Interface ClusterCommunicationService


  • public interface ClusterCommunicationService
    Service for assisting communications between controller cluster nodes.
    • Method Detail

      • addSubscriber

        @Deprecated
        void addSubscriber​(MessageSubject subject,
                           ClusterMessageHandler subscriber,
                           ExecutorService executor)
        Deprecated.
        in Cardinal Release
        Adds a new subscriber for the specified message subject.
        Parameters:
        subject - message subject
        subscriber - message subscriber
        executor - executor to use for running handler.
      • broadcast

        <M> void broadcast​(M message,
                           MessageSubject subject,
                           Function<M,​byte[]> encoder)
        Broadcasts a message to all controller nodes.
        Type Parameters:
        M - message type
        Parameters:
        message - message to send
        subject - message subject
        encoder - function for encoding message to byte[]
      • broadcastIncludeSelf

        <M> void broadcastIncludeSelf​(M message,
                                      MessageSubject subject,
                                      Function<M,​byte[]> encoder)
        Broadcasts a message to all controller nodes including self.
        Type Parameters:
        M - message type
        Parameters:
        message - message to send
        subject - message subject
        encoder - function for encoding message to byte[]
      • unicast

        <M> CompletableFuture<Void> unicast​(M message,
                                            MessageSubject subject,
                                            Function<M,​byte[]> encoder,
                                            NodeId toNodeId)
        Sends a message to the specified controller node.
        Type Parameters:
        M - message type
        Parameters:
        message - message to send
        subject - message subject
        encoder - function for encoding message to byte[]
        toNodeId - destination node identifier
        Returns:
        future that is completed when the message is sent
      • multicast

        <M> void multicast​(M message,
                           MessageSubject subject,
                           Function<M,​byte[]> encoder,
                           Set<NodeId> nodeIds)
        Multicasts a message to a set of controller nodes.
        Type Parameters:
        M - message type
        Parameters:
        message - message to send
        subject - message subject
        encoder - function for encoding message to byte[]
        nodeIds - recipient node identifiers
      • sendAndReceive

        default <M,​R> CompletableFuture<R> sendAndReceive​(M message,
                                                                MessageSubject subject,
                                                                Function<M,​byte[]> encoder,
                                                                Function<byte[],​R> decoder,
                                                                NodeId toNodeId)
        Sends a message and expects a reply.
        Type Parameters:
        M - request type
        R - reply type
        Parameters:
        message - message to send
        subject - message subject
        encoder - function for encoding request to byte[]
        decoder - function for decoding response from byte[]
        toNodeId - recipient node identifier
        Returns:
        reply future
      • sendAndReceive

        <M,​R> CompletableFuture<R> sendAndReceive​(M message,
                                                        MessageSubject subject,
                                                        Function<M,​byte[]> encoder,
                                                        Function<byte[],​R> decoder,
                                                        NodeId toNodeId,
                                                        Duration timeout)
        Sends a message and expects a reply.
        Type Parameters:
        M - request type
        R - reply type
        Parameters:
        message - message to send
        subject - message subject
        encoder - function for encoding request to byte[]
        decoder - function for decoding response from byte[]
        toNodeId - recipient node identifier
        timeout - the message timeout
        Returns:
        reply future
      • addSubscriber

        <M,​R> void addSubscriber​(MessageSubject subject,
                                       Function<byte[],​M> decoder,
                                       Function<M,​R> handler,
                                       Function<R,​byte[]> encoder,
                                       Executor executor)
        Adds a new subscriber for the specified message subject.
        Type Parameters:
        M - incoming message type
        R - reply message type
        Parameters:
        subject - message subject
        decoder - decoder for resurrecting incoming message
        handler - handler function that processes the incoming message and produces a reply
        encoder - encoder for serializing reply
        executor - executor to run this handler on
      • addSubscriber

        <M,​R> void addSubscriber​(MessageSubject subject,
                                       Function<byte[],​M> decoder,
                                       Function<M,​CompletableFuture<R>> handler,
                                       Function<R,​byte[]> encoder)
        Adds a new subscriber for the specified message subject.
        Type Parameters:
        M - incoming message type
        R - reply message type
        Parameters:
        subject - message subject
        decoder - decoder for resurrecting incoming message
        handler - handler function that processes the incoming message and produces a reply
        encoder - encoder for serializing reply
      • addSubscriber

        <M> void addSubscriber​(MessageSubject subject,
                               Function<byte[],​M> decoder,
                               Consumer<M> handler,
                               Executor executor)
        Adds a new subscriber for the specified message subject.
        Type Parameters:
        M - incoming message type
        Parameters:
        subject - message subject
        decoder - decoder to resurrecting incoming message
        handler - handler for handling message
        executor - executor to run this handler on
      • removeSubscriber

        void removeSubscriber​(MessageSubject subject)
        Removes a subscriber for the specified message subject.
        Parameters:
        subject - message subject