Interface MessagingService

All Known Subinterfaces:
ManagedMessagingService
All Known Implementing Classes:
NettyMessagingService

public interface MessagingService
Interface for low level messaging primitives.
  • Method Details

    • address

      Address address()
      Returns the local messaging service address. This is the address used by other nodes to communicate to this service.
      Returns:
      the address remote nodes use to communicate to this node
    • bindingAddresses

      Collection<Address> bindingAddresses()
      Returns the interfaces to which the local messaging service is bind.
      Returns:
      the address the messaging service is bound to
    • sendAsync

      default CompletableFuture<Void> sendAsync(Address address, String type, byte[] payload)
      Sends a message asynchronously to the specified communication address. The message is specified using the type and payload.

      The future may be completed exceptionally with one of the following:

      Parameters:
      address - address to send the message to.
      type - type of message.
      payload - message payload bytes.
      Returns:
      future that is completed when the message is sent
    • sendAsync

      CompletableFuture<Void> sendAsync(Address address, String type, byte[] payload, boolean keepAlive)
      Sends a message asynchronously to the specified communication address. The message is specified using the type and payload.
      Parameters:
      address - address to send the message to.
      type - type of message.
      payload - message payload bytes.
      keepAlive - whether to keep the connection alive after usage
      Returns:
      future that is completed when the message is sent
    • sendAndReceive

      default CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload)
      Sends a message asynchronously and expects a response on a pooled connection.

      The future may be completed exceptionally with one of:

      Parameters:
      address - address to send the message to.
      type - type of message.
      payload - message payload.
      Returns:
      a response future
    • sendAndReceive

      CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive)
      Sends a message asynchronously and expects a response.

      If keepAlive is false, a new, transient connection is set up and created. If true, it will reuse an existing connection (if any), or create a new one that will be kept in a pool for future reuse for this address and type pair.

      The future may be completed exceptionally with one of:

      Parameters:
      address - address to send the message to.
      type - type of message.
      payload - message payload.
      keepAlive - whether to keep the connection alive after usage
      Returns:
      a response future
    • sendAndReceive

      default CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, Executor executor)
      Sends a message synchronously and expects a response on a pooled connection.

      The future may be completed exceptionally with one of:

      Parameters:
      address - address to send the message to.
      type - type of message.
      payload - message payload.
      executor - executor over which any follow up actions after completion will be executed.
      Returns:
      a response future
    • sendAndReceive

      CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Executor executor)
      Sends a message synchronously and expects a response.

      If keepAlive is false, a new, transient connection is set up and created. If true, it will reuse an existing connection (if any), or create a new one that will be kept in a pool for future reuse for this address and type pair.

      The future may be completed exceptionally with one of:

      Parameters:
      address - address to send the message to.
      type - type of message.
      payload - message payload.
      keepAlive - whether to keep the connection alive after usage
      executor - executor over which any follow up actions after completion will be executed.
      Returns:
      a response future
    • sendAndReceive

      default CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, Duration timeout)
      Sends a message asynchronously and expects a response on a pooled connection.

      The future may be completed exceptionally with one of:

      Parameters:
      address - address to send the message to.
      type - type of message.
      payload - message payload.
      timeout - response timeout
      Returns:
      a response future
    • sendAndReceive

      CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Duration timeout)
      Sends a message asynchronously and expects a response.

      If keepAlive is false, a new, transient connection is set up and created. If true, it will reuse an existing connection (if any), or create a new one that will be kept in a pool for future reuse for this address and type pair.

      The future may be completed exceptionally with one of:

      Parameters:
      address - address to send the message to.
      type - type of message.
      payload - message payload.
      keepAlive - whether to keep the connection alive after usage
      timeout - response timeout
      Returns:
      a response future
    • sendAndReceive

      CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Duration timeout, Executor executor)
      Sends a message synchronously and expects a response.

      If keepAlive is false, a new, transient connection is set up and created. If true, it will reuse an existing connection (if any), or create a new one that will be kept in a pool for future reuse for this address and type pair.

      The future may be completed exceptionally with one of:

      Parameters:
      address - address to send the message to.
      type - type of message.
      payload - message payload.
      keepAlive - whether to keep the connection alive after usage
      timeout - response timeout
      executor - executor over which any follow up actions after completion will be executed.
      Returns:
      a response future
    • registerHandler

      void registerHandler(String type, BiConsumer<Address,byte[]> handler, Executor executor)
      Registers a new message handler for message type.
      Parameters:
      type - message type.
      handler - message handler
      executor - executor to use for running message handler logic.
    • registerHandler

      void registerHandler(String type, BiFunction<Address,byte[],byte[]> handler, Executor executor)
      Registers a new message handler for message type.
      Parameters:
      type - message type.
      handler - message handler
      executor - executor to use for running message handler logic.
    • registerHandler

      void registerHandler(String type, BiFunction<Address,byte[],CompletableFuture<byte[]>> handler)
      Registers a new message handler for message type.
      Parameters:
      type - message type.
      handler - message handler
    • unregisterHandler

      void unregisterHandler(String type)
      Unregister current handler, if one exists for message type.
      Parameters:
      type - message type
    • isRunning

      boolean isRunning()
      Returns a boolean value indicating whether the managed object is running.
      Returns:
      Indicates whether the managed object is running.