Package io.atomix.cluster.messaging.impl
Class DefaultClusterCommunicationService
java.lang.Object
io.atomix.cluster.messaging.impl.DefaultClusterCommunicationService
- All Implemented Interfaces:
ClusterCommunicationService,ManagedClusterCommunicationService,Managed<ClusterCommunicationService>
public class DefaultClusterCommunicationService
extends Object
implements ManagedClusterCommunicationService
Cluster communication service implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ClusterMembershipServiceprotected final MessagingServiceprotected final UnicastService -
Constructor Summary
ConstructorsConstructorDescriptionDefaultClusterCommunicationService(ClusterMembershipService membershipService, MessagingService messagingService, UnicastService unicastService) -
Method Summary
Modifier and TypeMethodDescription<M> voidBroadcasts a message to all members.boolean<M> voidmulticast(String subject, M message, Function<M, byte[]> encoder, Set<MemberId> nodes, boolean reliable) Multicasts a message to a set of members.<M,R> CompletableFuture<R> send(String subject, M message, Function<M, byte[]> encoder, Function<byte[], R> decoder, MemberId toMemberId, Duration timeout) Sends a message and expects a reply.start()stop()<M> voidsubscribe(String subject, Function<byte[], M> decoder, BiConsumer<MemberId, M> handler, Executor executor) Adds a new subscriber for the specified message subject.<M> voidAdds a new subscriber for the specified message subject.<M,R> void subscribe(String subject, Function<byte[], M> decoder, Function<M, CompletableFuture<R>> handler, Function<R, byte[]> encoder) Adds a new subscriber for the specified message subject.<M,R> void subscribe(String subject, Function<byte[], M> decoder, Function<M, R> handler, Function<R, byte[]> encoder, Executor executor) Adds a new subscriber for the specified message subject.<M> voidSends a message to a member.voidunsubscribe(String subject) Removes a subscriber for the specified message subject.
-
Field Details
-
membershipService
-
messagingService
-
unicastService
-
-
Constructor Details
-
DefaultClusterCommunicationService
public DefaultClusterCommunicationService(ClusterMembershipService membershipService, MessagingService messagingService, UnicastService unicastService)
-
-
Method Details
-
broadcast
Description copied from interface:ClusterCommunicationServiceBroadcasts a message to all members.- Specified by:
broadcastin interfaceClusterCommunicationService- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]reliable- whether to perform a reliable (TCP) unicast
-
multicast
public <M> void multicast(String subject, M message, Function<M, byte[]> encoder, Set<MemberId> nodes, boolean reliable) Description copied from interface:ClusterCommunicationServiceMulticasts a message to a set of members.- Specified by:
multicastin interfaceClusterCommunicationService- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]nodes- recipient node identifiersreliable- whether to perform a reliable (TCP) unicast
-
unicast
public <M> void unicast(String subject, M message, Function<M, byte[]> encoder, MemberId memberId, boolean reliable) Description copied from interface:ClusterCommunicationServiceSends a message to a member.- Specified by:
unicastin interfaceClusterCommunicationService- Type Parameters:
M- message type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding message to byte[]memberId- recipient node identifierreliable- whether to perform a reliable (TCP) unicast
-
send
public <M,R> CompletableFuture<R> send(String subject, M message, Function<M, byte[]> encoder, Function<byte[], R> decoder, MemberId toMemberId, Duration timeout) Description copied from interface:ClusterCommunicationServiceSends a message and expects a reply.- Specified by:
sendin interfaceClusterCommunicationService- Type Parameters:
M- request typeR- reply type- Parameters:
subject- message subjectmessage- message to sendencoder- function for encoding request to byte[]decoder- function for decoding response from byte[]toMemberId- recipient node identifiertimeout- response timeout- Returns:
- reply future
-
subscribe
public <M,R> void subscribe(String subject, Function<byte[], M> decoder, Function<M, R> handler, Function<R, byte[]> encoder, Executor executor) Description copied from interface:ClusterCommunicationServiceAdds a new subscriber for the specified message subject.- Specified by:
subscribein interfaceClusterCommunicationService- Type Parameters:
M- incoming message typeR- reply message type- Parameters:
subject- message subjectdecoder- 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 on
-
subscribe
public <M,R> void subscribe(String subject, Function<byte[], M> decoder, Function<M, CompletableFuture<R>> handler, Function<R, byte[]> encoder) Description copied from interface:ClusterCommunicationServiceAdds a new subscriber for the specified message subject.- Specified by:
subscribein interfaceClusterCommunicationService- Type Parameters:
M- incoming message typeR- reply message type- Parameters:
subject- message subjectdecoder- decoder for resurrecting incoming messagehandler- handler function that processes the incoming message and produces a replyencoder- encoder for serializing reply
-
subscribe
public <M> void subscribe(String subject, Function<byte[], M> decoder, Consumer<M> handler, Executor executor) Description copied from interface:ClusterCommunicationServiceAdds a new subscriber for the specified message subject.- Specified by:
subscribein interfaceClusterCommunicationService- Type Parameters:
M- incoming message type- Parameters:
subject- message subjectdecoder- decoder to resurrecting incoming messagehandler- handler for handling messageexecutor- executor to run this handler on
-
subscribe
public <M> void subscribe(String subject, Function<byte[], M> decoder, BiConsumer<MemberId, M> handler, Executor executor) Description copied from interface:ClusterCommunicationServiceAdds a new subscriber for the specified message subject.- Specified by:
subscribein interfaceClusterCommunicationService- Type Parameters:
M- incoming message type- Parameters:
subject- message subjectdecoder- decoder to resurrecting incoming messagehandler- handler for handling messageexecutor- executor to run this handler on
-
unsubscribe
Description copied from interface:ClusterCommunicationServiceRemoves a subscriber for the specified message subject.- Specified by:
unsubscribein interfaceClusterCommunicationService- Parameters:
subject- message subject
-
start
- Specified by:
startin interfaceManaged<ClusterCommunicationService>
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceManaged<ClusterCommunicationService>
-
stop
- Specified by:
stopin interfaceManaged<ClusterCommunicationService>
-