Class: VertxServiceDiscovery::ServiceDiscovery

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb

Overview

Service Discovery main entry point.

The service discovery is an infrastructure that let you publish and find `services`. A `service` is a discoverable functionality. It can be qualified by its type, metadata, and location. So a `service` can be a database, a service proxy, a HTTP endpoint. It does not have to be a vert.x entity, but can be anything. Each service is described by a Hash.

The service discovery implements the interactions defined in the service-oriented computing. And to some extend, also provides the dynamic service-oriented computing interaction. So, application can react to arrival and departure of services.

A service provider can:

* publish a service record * un-publish a published record * update the status of a published service (down, out of service...)

A service consumer can:

* lookup for services * bind to a selected service (it gets a ServiceReference) and use it * release the service once the consumer is done with it * listen for arrival, departure and modification of services.

Consumer would 1) lookup for service record matching their need, 2) retrieve the ServiceReference that give access to the service, 3) get a service object to access the service, 4) release the service object once done.

A state above, the central piece of information shared by the providers and consumers are Hashrecords.

Providers and consumers must create their own ServiceDiscovery instance. These instances are collaborating in background (distributed structure) to keep the set of services in sync.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (::VertxServiceDiscovery::ServiceDiscovery) create(vertx = nil, options = nil)

Creates an instance of VertxServiceDiscovery::ServiceDiscovery.

Parameters:

  • vertx (::Vertx::Vertx) (defaults to: nil)
    the vert.x instance
  • options (Hash) (defaults to: nil)
    the discovery options

Returns:

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 54

def self.create(vertx=nil,options=nil)
  if vertx.class.method_defined?(:j_del) && !block_given? && options == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxServicediscovery::ServiceDiscovery.java_method(:create, [Java::IoVertxCore::Vertx.java_class]).call(vertx.j_del),::VertxServiceDiscovery::ServiceDiscovery)
  elsif vertx.class.method_defined?(:j_del) && options.class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxServicediscovery::ServiceDiscovery.java_method(:create, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxServicediscovery::ServiceDiscoveryOptions.java_class]).call(vertx.j_del,Java::IoVertxServicediscovery::ServiceDiscoveryOptions.new(::Vertx::Util::Utils.to_json_object(options))),::VertxServiceDiscovery::ServiceDiscovery)
  end
  raise ArgumentError, "Invalid arguments when calling create(vertx,options)"
end

+ (void) release_service_object(discovery = nil, svcObject = nil)

This method returns an undefined value.

Release the service object retrieved using get methods from the service type interface. It searches for the reference associated with the given object and release it.

Parameters:

Raises:

  • (ArgumentError)


220
221
222
223
224
225
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 220

def self.release_service_object(discovery=nil,svcObject=nil)
  if discovery.class.method_defined?(:j_del) && (svcObject.class == String  || svcObject.class == Hash || svcObject.class == Array || svcObject.class == NilClass || svcObject.class == TrueClass || svcObject.class == FalseClass || svcObject.class == Fixnum || svcObject.class == Float) && !block_given?
    return Java::IoVertxServicediscovery::ServiceDiscovery.java_method(:releaseServiceObject, [Java::IoVertxServicediscovery::ServiceDiscovery.java_class,Java::java.lang.Object.java_class]).call(discovery.j_del,::Vertx::Util::Utils.to_object(svcObject))
  end
  raise ArgumentError, "Invalid arguments when calling release_service_object(discovery,svcObject)"
end

Instance Method Details

- (Set<::VertxServiceDiscovery::ServiceReference>) bindings

@return the set of service references retrieved by this service discovery.

Returns:

Raises:

  • (ArgumentError)


209
210
211
212
213
214
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 209

def bindings
  if !block_given?
    return ::Vertx::Util::Utils.to_set(@j_del.java_method(:bindings, []).call()).map! { |elt| ::Vertx::Util::Utils.safe_create(elt,::VertxServiceDiscovery::ServiceReference) }
  end
  raise ArgumentError, "Invalid arguments when calling bindings()"
end

- (void) close

This method returns an undefined value.

Closes the service discovery

Raises:

  • (ArgumentError)


114
115
116
117
118
119
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 114

def close
  if !block_given?
    return @j_del.java_method(:close, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling close()"
end

- (void) getRecord(filter, resultHandler) { ... } - (void) getRecord(filter, resultHandler) { ... } - (void) getRecord(filter, includeOutOfService, resultHandler) { ... }

This method returns an undefined value.

Lookups for a single record.

The filter is a taking a Hash as argument and returning a boolean. You should see it as an accept method of a filter. This method return a record passing the filter.

Unlike #get_record, this method may accept records with a OUT OF SERVICE status, if the includeOutOfService parameter is set to true.

Overloads:

  • - (void) getRecord(filter, resultHandler) { ... }

    Parameters:

    • filter (Hash{String => Object})
      the filter.

    Yields:

    • handler called when the lookup has been completed. When there are no matching record, the operation succeed, but the async result has no result.
  • - (void) getRecord(filter, resultHandler) { ... }

    Parameters:

    • filter (Proc)
      the filter, must not be null. To return all records, use a function accepting all records

    Yields:

    • the result handler called when the lookup has been completed. When there are no matching record, the operation succeed, but the async result has no result.
  • - (void) getRecord(filter, includeOutOfService, resultHandler) { ... }

    Parameters:

    • filter (Proc)
      the filter, must not be null. To return all records, use a function accepting all records
    • includeOutOfService (true, false)
      whether or not the filter accepts OUT OF SERVICE records

    Yields:

    • the result handler called when the lookup has been completed. When there are no matching record, the operation succeed, but the async result has no result.

Raises:

  • (ArgumentError)


158
159
160
161
162
163
164
165
166
167
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 158

def get_record(param_1=nil,param_2=nil)
  if param_1.class == Hash && block_given? && param_2 == nil
    return @j_del.java_method(:getRecord, [Java::IoVertxCoreJson::JsonObject.java_class,Java::IoVertxCore::Handler.java_class]).call(::Vertx::Util::Utils.to_json_object(param_1),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
  elsif param_1.class == Proc && block_given? && param_2 == nil
    return @j_del.java_method(:getRecord, [Java::JavaUtilFunction::Function.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| param_1.call(event != nil ? JSON.parse(event.toJson.encode) : nil) }),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
  elsif param_1.class == Proc && (param_2.class == TrueClass || param_2.class == FalseClass) && block_given?
    return @j_del.java_method(:getRecord, [Java::JavaUtilFunction::Function.java_class,Java::boolean.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| param_1.call(event != nil ? JSON.parse(event.toJson.encode) : nil) }),param_2,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling get_record(param_1,param_2)"
end

- (void) getRecords(filter, resultHandler) { ... } - (void) getRecords(filter, resultHandler) { ... } - (void) getRecords(filter, includeOutOfService, resultHandler) { ... }

This method returns an undefined value.

Lookups for a set of records. Unlike #get_record, this method returns all matching records.

The filter is a taking a Hash as argument and returning a boolean. You should see it as an accept method of a filter. This method return a record passing the filter.

Unlike #get_records, this method may accept records with a OUT OF SERVICE status, if the includeOutOfService parameter is set to true.

Overloads:

  • - (void) getRecords(filter, resultHandler) { ... }

    Parameters:

    • filter (Hash{String => Object})
      the filter - see #get_record

    Yields:

    • handler called when the lookup has been completed. When there are no matching record, the operation succeed, but the async result has an empty list as result.
  • - (void) getRecords(filter, resultHandler) { ... }

    Parameters:

    • filter (Proc)
      the filter, must not be null. To return all records, use a function accepting all records

    Yields:

    • handler called when the lookup has been completed. When there are no matching record, the operation succeed, but the async result has an empty list as result.
  • - (void) getRecords(filter, includeOutOfService, resultHandler) { ... }

    Parameters:

    • filter (Proc)
      the filter, must not be null. To return all records, use a function accepting all records
    • includeOutOfService (true, false)
      whether or not the filter accepts OUT OF SERVICE records

    Yields:

    • handler called when the lookup has been completed. When there are no matching record, the operation succeed, but the async result has an empty list as result.

Raises:

  • (ArgumentError)


187
188
189
190
191
192
193
194
195
196
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 187

def get_records(param_1=nil,param_2=nil)
  if param_1.class == Hash && block_given? && param_2 == nil
    return @j_del.java_method(:getRecords, [Java::IoVertxCoreJson::JsonObject.java_class,Java::IoVertxCore::Handler.java_class]).call(::Vertx::Util::Utils.to_json_object(param_1),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result.to_a.map { |elt| elt != nil ? JSON.parse(elt.toJson.encode) : nil } : nil) }))
  elsif param_1.class == Proc && block_given? && param_2 == nil
    return @j_del.java_method(:getRecords, [Java::JavaUtilFunction::Function.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| param_1.call(event != nil ? JSON.parse(event.toJson.encode) : nil) }),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result.to_a.map { |elt| elt != nil ? JSON.parse(elt.toJson.encode) : nil } : nil) }))
  elsif param_1.class == Proc && (param_2.class == TrueClass || param_2.class == FalseClass) && block_given?
    return @j_del.java_method(:getRecords, [Java::JavaUtilFunction::Function.java_class,Java::boolean.java_class,Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| param_1.call(event != nil ? JSON.parse(event.toJson.encode) : nil) }),param_2,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result.to_a.map { |elt| elt != nil ? JSON.parse(elt.toJson.encode) : nil } : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling get_records(param_1,param_2)"
end

- (::VertxServiceDiscovery::ServiceReference) get_reference(record = nil)

Gets a service reference from the given record.

Parameters:

  • record (Hash) (defaults to: nil)
    the chosen record

Returns:

Raises:

  • (ArgumentError)


65
66
67
68
69
70
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 65

def get_reference(record=nil)
  if record.class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:getReference, [Java::IoVertxServicediscovery::Record.java_class]).call(Java::IoVertxServicediscovery::Record.new(::Vertx::Util::Utils.to_json_object(record))),::VertxServiceDiscovery::ServiceReference)
  end
  raise ArgumentError, "Invalid arguments when calling get_reference(record)"
end

- (::VertxServiceDiscovery::ServiceReference) get_reference_with_configuration(record = nil, configuration = nil)

Gets a service reference from the given record, the reference is configured with the given json object.

Parameters:

  • record (Hash) (defaults to: nil)
    the chosen record
  • configuration (Hash{String => Object}) (defaults to: nil)
    the configuration

Returns:

Raises:

  • (ArgumentError)


75
76
77
78
79
80
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 75

def get_reference_with_configuration(record=nil,configuration=nil)
  if record.class == Hash && configuration.class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:getReferenceWithConfiguration, [Java::IoVertxServicediscovery::Record.java_class,Java::IoVertxCoreJson::JsonObject.java_class]).call(Java::IoVertxServicediscovery::Record.new(::Vertx::Util::Utils.to_json_object(record)),::Vertx::Util::Utils.to_json_object(configuration)),::VertxServiceDiscovery::ServiceReference)
  end
  raise ArgumentError, "Invalid arguments when calling get_reference_with_configuration(record,configuration)"
end

- (void) publish(record = nil) { ... }

This method returns an undefined value.

Publishes a record.

Parameters:

  • record (Hash) (defaults to: nil)
    the record

Yields:

  • handler called when the operation has completed (successfully or not). In case of success, the passed record has a registration id required to modify and un-register the service.

Raises:

  • (ArgumentError)


124
125
126
127
128
129
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 124

def publish(record=nil)
  if record.class == Hash && block_given?
    return @j_del.java_method(:publish, [Java::IoVertxServicediscovery::Record.java_class,Java::IoVertxCore::Handler.java_class]).call(Java::IoVertxServicediscovery::Record.new(::Vertx::Util::Utils.to_json_object(record)),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling publish(record)"
end

- (::VertxServiceDiscovery::ServiceDiscovery) register_service_exporter(exporter = nil, configuration = nil)

Registers a discovery bridge. Exporters let you integrate other discovery technologies in this service discovery.

Parameters:

Returns:

Raises:

  • (ArgumentError)


106
107
108
109
110
111
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 106

def register_service_exporter(exporter=nil,configuration=nil)
  if exporter.class.method_defined?(:j_del) && configuration.class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:registerServiceExporter, [Java::IoVertxServicediscoverySpi::ServiceExporter.java_class,Java::IoVertxCoreJson::JsonObject.java_class]).call(exporter.j_del,::Vertx::Util::Utils.to_json_object(configuration)),::VertxServiceDiscovery::ServiceDiscovery)
  end
  raise ArgumentError, "Invalid arguments when calling register_service_exporter(exporter,configuration)"
end

- (::VertxServiceDiscovery::ServiceDiscovery) register_service_importer(importer = nil, configuration = nil)

Registers a discovery service importer. Importers let you integrate other discovery technologies in this service discovery.

Parameters:

Returns:

Raises:

  • (ArgumentError)


95
96
97
98
99
100
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 95

def register_service_importer(importer=nil,configuration=nil)
  if importer.class.method_defined?(:j_del) && configuration.class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:registerServiceImporter, [Java::IoVertxServicediscoverySpi::ServiceImporter.java_class,Java::IoVertxCoreJson::JsonObject.java_class]).call(importer.j_del,::Vertx::Util::Utils.to_json_object(configuration)),::VertxServiceDiscovery::ServiceDiscovery)
  end
  raise ArgumentError, "Invalid arguments when calling register_service_importer(importer,configuration)"
end

- (true, false) release?(reference = nil)

Releases the service reference.

Parameters:

Returns:

  • (true, false)
    whether or not the reference has been released.

Raises:

  • (ArgumentError)


84
85
86
87
88
89
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 84

def release?(reference=nil)
  if reference.class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:release, [Java::IoVertxServicediscovery::ServiceReference.java_class]).call(reference.j_del)
  end
  raise ArgumentError, "Invalid arguments when calling release?(reference)"
end

- (void) unpublish(id = nil) { ... }

This method returns an undefined value.

Un-publishes a record.

Parameters:

  • id (String) (defaults to: nil)
    the registration id

Yields:

  • handler called when the operation has completed (successfully or not).

Raises:

  • (ArgumentError)


134
135
136
137
138
139
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 134

def unpublish(id=nil)
  if id.class == String && block_given?
    return @j_del.java_method(:unpublish, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(id,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling unpublish(id)"
end

- (void) update(record = nil) { ... }

This method returns an undefined value.

Updates the given record. The record must has been published, and has it's registration id set.

Parameters:

  • record (Hash) (defaults to: nil)
    the updated record

Yields:

  • handler called when the lookup has been completed.

Raises:

  • (ArgumentError)


201
202
203
204
205
206
# File '/Users/julien/java/vertx-stack/stack-docs/target/rb/vertx-service-discovery/service_discovery.rb', line 201

def update(record=nil)
  if record.class == Hash && block_given?
    return @j_del.java_method(:update, [Java::IoVertxServicediscovery::Record.java_class,Java::IoVertxCore::Handler.java_class]).call(Java::IoVertxServicediscovery::Record.new(::Vertx::Util::Utils.to_json_object(record)),(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result != nil ? JSON.parse(ar.result.toJson.encode) : nil : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling update(record)"
end