public class ServiceDiscovery extends Object
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 Record
.
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 Record
.
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.
original
non RX-ified interface using Vert.x codegen.Modifier and Type | Field and Description |
---|---|
static io.vertx.lang.rx.TypeArg<ServiceDiscovery> |
__TYPE_ARG |
static String |
EVENT_ID
Constant for id field of usage events.
|
static String |
EVENT_RECORD
Constant for record field of usage events.
|
static String |
EVENT_TYPE
Constant for type field of usage events.
|
static String |
EVENT_TYPE_BIND
Constant for event type `Bind`.
|
static String |
EVENT_TYPE_RELEASE
Constant for event type `Release`.
|
Constructor and Description |
---|
ServiceDiscovery(Object delegate) |
ServiceDiscovery(ServiceDiscovery delegate) |
Modifier and Type | Method and Description |
---|---|
Set<ServiceReference> |
bindings() |
void |
close()
Closes the service discovery
|
static ServiceDiscovery |
create(Vertx vertx)
Creates a new instance of
ServiceDiscovery using the default configuration. |
static ServiceDiscovery |
create(Vertx vertx,
ServiceDiscoveryOptions options)
Creates an instance of
ServiceDiscovery . |
boolean |
equals(Object o) |
ServiceDiscovery |
getDelegate() |
void |
getRecord(java.util.function.Function<Record,Boolean> filter)
Lookups for a single record.
|
void |
getRecord(java.util.function.Function<Record,Boolean> filter,
boolean includeOutOfService)
Lookups for a single record.
|
void |
getRecord(java.util.function.Function<Record,Boolean> filter,
boolean includeOutOfService,
Handler<AsyncResult<Record>> resultHandler)
Lookups for a single record.
|
void |
getRecord(java.util.function.Function<Record,Boolean> filter,
Handler<AsyncResult<Record>> resultHandler)
Lookups for a single record.
|
void |
getRecord(JsonObject filter)
Lookups for a single record.
|
void |
getRecord(JsonObject filter,
Handler<AsyncResult<Record>> resultHandler)
Lookups for a single record.
|
void |
getRecord(String id)
Looks up for a single record by its registration
id . |
void |
getRecord(String id,
Handler<AsyncResult<Record>> resultHandler)
Looks up for a single record by its registration
id . |
void |
getRecords(java.util.function.Function<Record,Boolean> filter)
Lookups for a set of records.
|
void |
getRecords(java.util.function.Function<Record,Boolean> filter,
boolean includeOutOfService)
Lookups for a set of records.
|
void |
getRecords(java.util.function.Function<Record,Boolean> filter,
boolean includeOutOfService,
Handler<AsyncResult<List<Record>>> resultHandler)
Lookups for a set of records.
|
void |
getRecords(java.util.function.Function<Record,Boolean> filter,
Handler<AsyncResult<List<Record>>> resultHandler)
Lookups for a set of records.
|
void |
getRecords(JsonObject filter)
Lookups for a set of records.
|
void |
getRecords(JsonObject filter,
Handler<AsyncResult<List<Record>>> resultHandler)
Lookups for a set of records.
|
ServiceReference |
getReference(Record record)
Gets a service reference from the given record.
|
ServiceReference |
getReferenceWithConfiguration(Record record,
JsonObject configuration)
Gets a service reference from the given record, the reference is configured with the given json object.
|
int |
hashCode() |
static ServiceDiscovery |
newInstance(ServiceDiscovery arg) |
ServiceDiscoveryOptions |
options() |
void |
publish(Record record)
Publishes a record.
|
void |
publish(Record record,
Handler<AsyncResult<Record>> resultHandler)
Publishes a record.
|
ServiceDiscovery |
registerServiceExporter(ServiceExporter exporter,
JsonObject configuration)
Registers a discovery bridge.
|
ServiceDiscovery |
registerServiceExporter(ServiceExporter exporter,
JsonObject configuration,
Handler<AsyncResult<Void>> completionHandler)
Registers a discovery bridge.
|
ServiceDiscovery |
registerServiceImporter(ServiceImporter importer,
JsonObject configuration)
Registers a discovery service importer.
|
ServiceDiscovery |
registerServiceImporter(ServiceImporter importer,
JsonObject configuration,
Handler<AsyncResult<Void>> completionHandler)
Registers a discovery service importer.
|
boolean |
release(ServiceReference reference)
Releases the service reference.
|
static void |
releaseServiceObject(ServiceDiscovery discovery,
Object svcObject)
Release the service object retrieved using
get methods from the service type interface. |
Single<Record> |
rxGetRecord(java.util.function.Function<Record,Boolean> filter)
Lookups for a single record.
|
Single<Record> |
rxGetRecord(java.util.function.Function<Record,Boolean> filter,
boolean includeOutOfService)
Lookups for a single record.
|
Single<Record> |
rxGetRecord(JsonObject filter)
Lookups for a single record.
|
Single<Record> |
rxGetRecord(String id)
Looks up for a single record by its registration
id . |
Single<List<Record>> |
rxGetRecords(java.util.function.Function<Record,Boolean> filter)
Lookups for a set of records.
|
Single<List<Record>> |
rxGetRecords(java.util.function.Function<Record,Boolean> filter,
boolean includeOutOfService)
Lookups for a set of records.
|
Single<List<Record>> |
rxGetRecords(JsonObject filter)
Lookups for a set of records.
|
Single<Record> |
rxPublish(Record record)
Publishes a record.
|
Single<Void> |
rxRegisterServiceExporter(ServiceExporter exporter,
JsonObject configuration)
Registers a discovery bridge.
|
Single<Void> |
rxRegisterServiceImporter(ServiceImporter importer,
JsonObject configuration)
Registers a discovery service importer.
|
Single<Void> |
rxUnpublish(String id)
Un-publishes a record.
|
Single<Record> |
rxUpdate(Record record)
Updates the given record.
|
String |
toString() |
void |
unpublish(String id)
Un-publishes a record.
|
void |
unpublish(String id,
Handler<AsyncResult<Void>> resultHandler)
Un-publishes a record.
|
void |
update(Record record)
Updates the given record.
|
void |
update(Record record,
Handler<AsyncResult<Record>> resultHandler)
Updates the given record.
|
public static final io.vertx.lang.rx.TypeArg<ServiceDiscovery> __TYPE_ARG
public static final String EVENT_TYPE
public static final String EVENT_TYPE_BIND
public static final String EVENT_TYPE_RELEASE
public static final String EVENT_RECORD
public static final String EVENT_ID
public ServiceDiscovery(ServiceDiscovery delegate)
public ServiceDiscovery(Object delegate)
public ServiceDiscovery getDelegate()
public static ServiceDiscovery create(Vertx vertx, ServiceDiscoveryOptions options)
ServiceDiscovery
.vertx
- the vert.x instanceoptions
- the discovery optionspublic static ServiceDiscovery create(Vertx vertx)
ServiceDiscovery
using the default configuration.vertx
- the vert.x instancepublic ServiceReference getReference(Record record)
record
- the chosen recordpublic ServiceReference getReferenceWithConfiguration(Record record, JsonObject configuration)
record
- the chosen recordconfiguration
- the configurationpublic boolean release(ServiceReference reference)
reference
- the reference to release, must not be null
public ServiceDiscovery registerServiceImporter(ServiceImporter importer, JsonObject configuration, Handler<AsyncResult<Void>> completionHandler)
importer
- the service importerconfiguration
- the optional configurationcompletionHandler
- handler call when the importer has finished its initialization and initial importsServiceDiscovery
public ServiceDiscovery registerServiceImporter(ServiceImporter importer, JsonObject configuration)
importer
- the service importerconfiguration
- the optional configurationServiceDiscovery
public Single<Void> rxRegisterServiceImporter(ServiceImporter importer, JsonObject configuration)
importer
- the service importerconfiguration
- the optional configurationServiceDiscovery
public ServiceDiscovery registerServiceExporter(ServiceExporter exporter, JsonObject configuration, Handler<AsyncResult<Void>> completionHandler)
exporter
- the service exporterconfiguration
- the optional configurationcompletionHandler
- handler notified when the exporter has been correctly initialized.ServiceDiscovery
public ServiceDiscovery registerServiceExporter(ServiceExporter exporter, JsonObject configuration)
exporter
- the service exporterconfiguration
- the optional configurationServiceDiscovery
public Single<Void> rxRegisterServiceExporter(ServiceExporter exporter, JsonObject configuration)
exporter
- the service exporterconfiguration
- the optional configurationServiceDiscovery
public void close()
public void publish(Record record, Handler<AsyncResult<Record>> resultHandler)
record
- the recordresultHandler
- 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.public void publish(Record record)
record
- the recordpublic Single<Record> rxPublish(Record record)
record
- the recordpublic void unpublish(String id, Handler<AsyncResult<Void>> resultHandler)
id
- the registration idresultHandler
- handler called when the operation has completed (successfully or not).public void unpublish(String id)
id
- the registration idpublic Single<Void> rxUnpublish(String id)
id
- the registration idpublic void getRecord(JsonObject filter, Handler<AsyncResult<Record>> resultHandler)
Filters are expressed using a Json object. Each entry of the given filter will be checked against the record. All entry must match exactly the record. The entry can use the special "*" value to denotes a requirement on the key, but not on the value.
Let's take some example:
{ "name" = "a" } => matches records with name set fo "a" { "color" = "*" } => matches records with "color" set { "color" = "red" } => only matches records with "color" set to "red" { "color" = "red", "name" = "a"} => only matches records with name set to "a", and color set to "red"
If the filter is not set (null
or empty), it accepts all records.
This method returns the first matching record.
filter
- the filter.resultHandler
- handler called when the lookup has been completed. When there are no matching record, the operation succeeds, but the async result has no result (null
).public void getRecord(JsonObject filter)
Filters are expressed using a Json object. Each entry of the given filter will be checked against the record. All entry must match exactly the record. The entry can use the special "*" value to denotes a requirement on the key, but not on the value.
Let's take some example:
{ "name" = "a" } => matches records with name set fo "a" { "color" = "*" } => matches records with "color" set { "color" = "red" } => only matches records with "color" set to "red" { "color" = "red", "name" = "a"} => only matches records with name set to "a", and color set to "red"
If the filter is not set (null
or empty), it accepts all records.
This method returns the first matching record.
filter
- the filter.public Single<Record> rxGetRecord(JsonObject filter)
Filters are expressed using a Json object. Each entry of the given filter will be checked against the record. All entry must match exactly the record. The entry can use the special "*" value to denotes a requirement on the key, but not on the value.
Let's take some example:
{ "name" = "a" } => matches records with name set fo "a" { "color" = "*" } => matches records with "color" set { "color" = "red" } => only matches records with "color" set to "red" { "color" = "red", "name" = "a"} => only matches records with name set to "a", and color set to "red"
If the filter is not set (null
or empty), it accepts all records.
This method returns the first matching record.
filter
- the filter.public void getRecord(String id, Handler<AsyncResult<Record>> resultHandler)
id
.
When there are no matching record, the operation succeeds, but the async result has no result (null
).
id
- the registration idresultHandler
- handler called when the lookup has been completedpublic void getRecord(String id)
id
.
When there are no matching record, the operation succeeds, but the async result has no result (null
).
id
- the registration idpublic Single<Record> rxGetRecord(String id)
id
.
When there are no matching record, the operation succeeds, but the async result has no result (null
).
id
- the registration idpublic void getRecord(java.util.function.Function<Record,Boolean> filter, Handler<AsyncResult<Record>> resultHandler)
The filter is a taking a Record
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.
This method only looks for records with a UP
status.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordsresultHandler
- 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.public void getRecord(java.util.function.Function<Record,Boolean> filter)
The filter is a taking a Record
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.
This method only looks for records with a UP
status.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordspublic Single<Record> rxGetRecord(java.util.function.Function<Record,Boolean> filter)
The filter is a taking a Record
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.
This method only looks for records with a UP
status.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordspublic void getRecord(java.util.function.Function<Record,Boolean> filter, boolean includeOutOfService, Handler<AsyncResult<Record>> resultHandler)
The filter is a taking a Record
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 getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method may accept records with a OUT OF SERVICE
status, if the includeOutOfService
parameter is set to true
.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordsincludeOutOfService
- whether or not the filter accepts OUT OF SERVICE
recordsresultHandler
- 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.public void getRecord(java.util.function.Function<Record,Boolean> filter, boolean includeOutOfService)
The filter is a taking a Record
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 getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method may accept records with a OUT OF SERVICE
status, if the includeOutOfService
parameter is set to true
.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordsincludeOutOfService
- whether or not the filter accepts OUT OF SERVICE
recordspublic Single<Record> rxGetRecord(java.util.function.Function<Record,Boolean> filter, boolean includeOutOfService)
The filter is a taking a Record
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 getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method may accept records with a OUT OF SERVICE
status, if the includeOutOfService
parameter is set to true
.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordsincludeOutOfService
- whether or not the filter accepts OUT OF SERVICE
recordspublic void getRecords(JsonObject filter, Handler<AsyncResult<List<Record>>> resultHandler)
getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method returns all matching
records.filter
- the filter - see getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
resultHandler
- 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.public void getRecords(JsonObject filter)
getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method returns all matching
records.filter
- the filter - see getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
public Single<List<Record>> rxGetRecords(JsonObject filter)
getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method returns all matching
records.filter
- the filter - see getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
public void getRecords(java.util.function.Function<Record,Boolean> filter, Handler<AsyncResult<List<Record>>> resultHandler)
getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method returns all matching
records.
The filter is a taking a Record
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.
This method only looks for records with a UP
status.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordsresultHandler
- 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.public void getRecords(java.util.function.Function<Record,Boolean> filter)
getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method returns all matching
records.
The filter is a taking a Record
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.
This method only looks for records with a UP
status.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordspublic Single<List<Record>> rxGetRecords(java.util.function.Function<Record,Boolean> filter)
getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method returns all matching
records.
The filter is a taking a Record
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.
This method only looks for records with a UP
status.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordspublic void getRecords(java.util.function.Function<Record,Boolean> filter, boolean includeOutOfService, Handler<AsyncResult<List<Record>>> resultHandler)
getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method returns all matching
records.
The filter is a taking a Record
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 getRecords(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<io.vertx.servicediscovery.Record>>>)
, this method may accept records with a OUT OF SERVICE
status, if the includeOutOfService
parameter is set to true
.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordsincludeOutOfService
- whether or not the filter accepts OUT OF SERVICE
recordsresultHandler
- 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.public void getRecords(java.util.function.Function<Record,Boolean> filter, boolean includeOutOfService)
getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method returns all matching
records.
The filter is a taking a Record
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 getRecords(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<io.vertx.servicediscovery.Record>>>)
, this method may accept records with a OUT OF SERVICE
status, if the includeOutOfService
parameter is set to true
.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordsincludeOutOfService
- whether or not the filter accepts OUT OF SERVICE
recordspublic Single<List<Record>> rxGetRecords(java.util.function.Function<Record,Boolean> filter, boolean includeOutOfService)
getRecord(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.servicediscovery.Record>>)
, this method returns all matching
records.
The filter is a taking a Record
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 getRecords(io.vertx.core.json.JsonObject, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<io.vertx.servicediscovery.Record>>>)
, this method may accept records with a OUT OF SERVICE
status, if the includeOutOfService
parameter is set to true
.
filter
- the filter, must not be null
. To return all records, use a function accepting all recordsincludeOutOfService
- whether or not the filter accepts OUT OF SERVICE
recordspublic void update(Record record, Handler<AsyncResult<Record>> resultHandler)
record
- the updated recordresultHandler
- handler called when the lookup has been completed.public void update(Record record)
record
- the updated recordpublic Single<Record> rxUpdate(Record record)
record
- the updated recordpublic Set<ServiceReference> bindings()
public ServiceDiscoveryOptions options()
public static void releaseServiceObject(ServiceDiscovery discovery, Object svcObject)
get
methods from the service type interface.
It searches for the reference associated with the given object and release it.discovery
- the service discoverysvcObject
- the service objectpublic static ServiceDiscovery newInstance(ServiceDiscovery arg)
Copyright © 2024 Eclipse. All rights reserved.