Class NettyMessagingService

java.lang.Object
io.atomix.cluster.messaging.impl.NettyMessagingService
All Implemented Interfaces:
ManagedMessagingService, MessagingService, Managed<MessagingService>, AutoCloseable

public final class NettyMessagingService extends Object implements ManagedMessagingService
Netty based MessagingService.
  • Constructor Details

  • Method Details

    • getChannelPool

      @VisibleForTesting public io.atomix.cluster.messaging.impl.ChannelPool getChannelPool()
    • address

      public Address address()
      Description copied from interface: MessagingService
      Returns the local messaging service address. This is the address used by other nodes to communicate to this service.
      Specified by:
      address in interface MessagingService
      Returns:
      the address remote nodes use to communicate to this node
    • bindingAddresses

      public Collection<Address> bindingAddresses()
      Description copied from interface: MessagingService
      Returns the interfaces to which the local messaging service is bind.
      Specified by:
      bindingAddresses in interface MessagingService
      Returns:
      the address the messaging service is bound to
    • sendAsync

      public CompletableFuture<Void> sendAsync(Address address, String type, byte[] payload, boolean keepAlive)
      Description copied from interface: MessagingService
      Sends a message asynchronously to the specified communication address. The message is specified using the type and payload.
      Specified by:
      sendAsync in interface MessagingService
      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

      public CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive)
      Description copied from interface: MessagingService
      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:

      Specified by:
      sendAndReceive in interface MessagingService
      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

      public CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Executor executor)
      Description copied from interface: MessagingService
      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:

      Specified by:
      sendAndReceive in interface MessagingService
      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

      public CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Duration timeout)
      Description copied from interface: MessagingService
      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:

      Specified by:
      sendAndReceive in interface MessagingService
      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

      public CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Duration timeout, Executor executor)
      Description copied from interface: MessagingService
      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:

      Specified by:
      sendAndReceive in interface MessagingService
      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

      public void registerHandler(String type, BiConsumer<Address,byte[]> handler, Executor executor)
      Description copied from interface: MessagingService
      Registers a new message handler for message type.
      Specified by:
      registerHandler in interface MessagingService
      Parameters:
      type - message type.
      handler - message handler
      executor - executor to use for running message handler logic.
    • registerHandler

      public void registerHandler(String type, BiFunction<Address,byte[],byte[]> handler, Executor executor)
      Description copied from interface: MessagingService
      Registers a new message handler for message type.
      Specified by:
      registerHandler in interface MessagingService
      Parameters:
      type - message type.
      handler - message handler
      executor - executor to use for running message handler logic.
    • registerHandler

      public void registerHandler(String type, BiFunction<Address,byte[],CompletableFuture<byte[]>> handler)
      Description copied from interface: MessagingService
      Registers a new message handler for message type.
      Specified by:
      registerHandler in interface MessagingService
      Parameters:
      type - message type.
      handler - message handler
    • unregisterHandler

      public void unregisterHandler(String type)
      Description copied from interface: MessagingService
      Unregister current handler, if one exists for message type.
      Specified by:
      unregisterHandler in interface MessagingService
      Parameters:
      type - message type
    • isRunning

      public boolean isRunning()
      Description copied from interface: MessagingService
      Returns a boolean value indicating whether the managed object is running.
      Specified by:
      isRunning in interface Managed<MessagingService>
      Specified by:
      isRunning in interface MessagingService
      Returns:
      Indicates whether the managed object is running.
    • start

      Specified by:
      start in interface Managed<MessagingService>
    • stop

      public CompletableFuture<Void> stop()
      Specified by:
      stop in interface Managed<MessagingService>