public interface ClusterEventService
This service is an abstraction for publish-subscribe based cluster communication. Messages are published and received
based on arbitrary String topics. It supports several types of messaging:
broadcast(String, Object) broadcasts a message to all subscribers registered for the topicunicast(String, Object) sends a unicast message directly to one of the subscribers registered
for the topic; unicast messages are generally delivered in round-robin fashionsend(String, Object) sends a message directly to one of the subscribers registered for the topic
and awaits a reply; direct messages are generally delivered in round-robin fashionsubscribe(String, Consumer, Executor) methods:
Subscription subscription = atomix.getEventService().subscribe("test", message -> {
System.out.println("Received message");
}, executor).join();
To cancel the subscription for a topic, call Subscription.close() on the returned Subscription
object:
subscription.close().join();
This API relies on CompletableFuture for asynchronous completion of all method calls.| Modifier and Type | Method and Description |
|---|---|
default <M> void |
broadcast(java.lang.String topic,
M message)
Broadcasts a message to all subscribers registered for the given
topic. |
<M> void |
broadcast(java.lang.String topic,
M message,
java.util.function.Function<M,byte[]> encoder)
Broadcasts a message to all subscribers registered for the given
topic. |
java.util.List<Subscription> |
getSubscriptions(java.lang.String topic)
Returns a list of subscriptions for the given topic.
|
default <M,R> java.util.concurrent.CompletableFuture<R> |
send(java.lang.String topic,
M message)
Sends a direct message to the next registered subscriber for
topic and awaits a reply. |
default <M,R> java.util.concurrent.CompletableFuture<R> |
send(java.lang.String topic,
M message,
java.time.Duration timeout)
Sends a direct message to the next registered subscriber for
topic and awaits a reply. |
default <M,R> java.util.concurrent.CompletableFuture<R> |
send(java.lang.String topic,
M message,
java.util.function.Function<M,byte[]> encoder,
java.util.function.Function<byte[],R> decoder)
Sends a direct message to the next registered subscriber for
topic and awaits a reply. |
<M,R> java.util.concurrent.CompletableFuture<R> |
send(java.lang.String topic,
M message,
java.util.function.Function<M,byte[]> encoder,
java.util.function.Function<byte[],R> decoder,
java.time.Duration timeout)
Sends a direct message to the next registered subscriber for
topic and awaits a reply. |
default <M> java.util.concurrent.CompletableFuture<Subscription> |
subscribe(java.lang.String topic,
java.util.function.Consumer<M> handler,
java.util.concurrent.Executor executor)
Adds a new subscriber for the specified message topic.
|
<M> java.util.concurrent.CompletableFuture<Subscription> |
subscribe(java.lang.String topic,
java.util.function.Function<byte[],M> decoder,
java.util.function.Consumer<M> handler,
java.util.concurrent.Executor executor)
Adds a new subscriber for the specified message topic.
|
<M,R> java.util.concurrent.CompletableFuture<Subscription> |
subscribe(java.lang.String topic,
java.util.function.Function<byte[],M> decoder,
java.util.function.Function<M,java.util.concurrent.CompletableFuture<R>> handler,
java.util.function.Function<R,byte[]> encoder)
Adds a new subscriber for the specified message topic.
|
<M,R> java.util.concurrent.CompletableFuture<Subscription> |
subscribe(java.lang.String topic,
java.util.function.Function<byte[],M> decoder,
java.util.function.Function<M,R> handler,
java.util.function.Function<R,byte[]> encoder,
java.util.concurrent.Executor executor)
Adds a new subscriber for the specified message topic.
|
default <M,R> java.util.concurrent.CompletableFuture<Subscription> |
subscribe(java.lang.String topic,
java.util.function.Function<M,java.util.concurrent.CompletableFuture<R>> handler)
Adds a new subscriber for the specified message topic.
|
default <M,R> java.util.concurrent.CompletableFuture<Subscription> |
subscribe(java.lang.String topic,
java.util.function.Function<M,R> handler,
java.util.concurrent.Executor executor)
Adds a new subscriber for the specified message topic.
|
default <M> java.util.concurrent.CompletableFuture<java.lang.Void> |
unicast(java.lang.String topic,
M message)
Unicasts a message to the next registered subscriber for
topic. |
<M> java.util.concurrent.CompletableFuture<java.lang.Void> |
unicast(java.lang.String topic,
M message,
java.util.function.Function<M,byte[]> encoder)
Unicasts a message to the next registered subscriber for
topic. |
default <M> void broadcast(java.lang.String topic,
M message)
topic.M - message typetopic - message topicmessage - message to send<M> void broadcast(java.lang.String topic,
M message,
java.util.function.Function<M,byte[]> encoder)
topic.M - message typetopic - message topicmessage - message to sendencoder - function for encoding message to byte[]default <M> java.util.concurrent.CompletableFuture<java.lang.Void> unicast(java.lang.String topic,
M message)
topic.M - message typetopic - message topicmessage - message to send<M> java.util.concurrent.CompletableFuture<java.lang.Void> unicast(java.lang.String topic,
M message,
java.util.function.Function<M,byte[]> encoder)
topic.M - message typemessage - message to sendtopic - message topicencoder - function for encoding message to byte[]default <M,R> java.util.concurrent.CompletableFuture<R> send(java.lang.String topic,
M message)
topic and awaits a reply.M - request typeR - reply typetopic - message topicmessage - message to senddefault <M,R> java.util.concurrent.CompletableFuture<R> send(java.lang.String topic,
M message,
java.time.Duration timeout)
topic and awaits a reply.M - request typeR - reply typetopic - message topicmessage - message to sendtimeout - reply timeoutdefault <M,R> java.util.concurrent.CompletableFuture<R> send(java.lang.String topic,
M message,
java.util.function.Function<M,byte[]> encoder,
java.util.function.Function<byte[],R> decoder)
topic and awaits a reply.M - request typeR - reply typetopic - message topicmessage - message to sendencoder - function for encoding request to byte[]decoder - function for decoding response from byte[]<M,R> java.util.concurrent.CompletableFuture<R> send(java.lang.String topic,
M message,
java.util.function.Function<M,byte[]> encoder,
java.util.function.Function<byte[],R> decoder,
java.time.Duration timeout)
topic and awaits a reply.M - request typeR - reply typetopic - message topicmessage - message to sendencoder - function for encoding request to byte[]decoder - function for decoding response from byte[]timeout - reply timeoutdefault <M,R> java.util.concurrent.CompletableFuture<Subscription> subscribe(java.lang.String topic, java.util.function.Function<M,R> handler, java.util.concurrent.Executor executor)
M - incoming message typeR - reply message typetopic - message topichandler - handler function that processes the incoming message and produces a replyexecutor - executor to run this handler on<M,R> java.util.concurrent.CompletableFuture<Subscription> subscribe(java.lang.String topic, java.util.function.Function<byte[],M> decoder, java.util.function.Function<M,R> handler, java.util.function.Function<R,byte[]> encoder, java.util.concurrent.Executor executor)
M - incoming message typeR - reply message typetopic - message topicdecoder - decoder for resurrecting incoming messagehandler - handler function that processes the incoming message and produces a replyencoder - encoder for serializing replyexecutor - executor to run this handler ondefault <M,R> java.util.concurrent.CompletableFuture<Subscription> subscribe(java.lang.String topic, java.util.function.Function<M,java.util.concurrent.CompletableFuture<R>> handler)
M - incoming message typeR - reply message typetopic - message topichandler - handler function that processes the incoming message and produces a reply<M,R> java.util.concurrent.CompletableFuture<Subscription> subscribe(java.lang.String topic, java.util.function.Function<byte[],M> decoder, java.util.function.Function<M,java.util.concurrent.CompletableFuture<R>> handler, java.util.function.Function<R,byte[]> encoder)
M - incoming message typeR - reply message typetopic - message topicdecoder - decoder for resurrecting incoming messagehandler - handler function that processes the incoming message and produces a replyencoder - encoder for serializing replydefault <M> java.util.concurrent.CompletableFuture<Subscription> subscribe(java.lang.String topic, java.util.function.Consumer<M> handler, java.util.concurrent.Executor executor)
M - incoming message typetopic - message topichandler - handler for handling messageexecutor - executor to run this handler on<M> java.util.concurrent.CompletableFuture<Subscription> subscribe(java.lang.String topic, java.util.function.Function<byte[],M> decoder, java.util.function.Consumer<M> handler, java.util.concurrent.Executor executor)
M - incoming message typetopic - message topicdecoder - decoder to resurrecting incoming messagehandler - handler for handling messageexecutor - executor to run this handler onjava.util.List<Subscription> getSubscriptions(java.lang.String topic)
topic - the topic for which to return subscriptionsCopyright © 2013-2018. All Rights Reserved.