Class NettyMessagingService
- All Implemented Interfaces:
ManagedMessagingService,MessagingService,Managed<MessagingService>,AutoCloseable
-
Constructor Summary
ConstructorsConstructorDescriptionNettyMessagingService(String cluster, Address advertisedAddress, MessagingConfig config, ProtocolVersion protocolVersion, io.micrometer.core.instrument.MeterRegistry registry) NettyMessagingService(String cluster, Address advertisedAddress, MessagingConfig config, io.micrometer.core.instrument.MeterRegistry registry) -
Method Summary
Modifier and TypeMethodDescriptionaddress()Returns the local messaging service address.Returns the interfaces to which the local messaging service is bind.io.atomix.cluster.messaging.impl.ChannelPoolbooleanReturns a boolean value indicating whether the managed object is running.voidregisterHandler(String type, BiConsumer<Address, byte[]> handler, Executor executor) Registers a new message handler for message type.voidregisterHandler(String type, BiFunction<Address, byte[], byte[]> handler, Executor executor) Registers a new message handler for message type.voidregisterHandler(String type, BiFunction<Address, byte[], CompletableFuture<byte[]>> handler) Registers a new message handler for message type.CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive) Sends a message asynchronously and expects a response.CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Duration timeout) Sends a message asynchronously and expects a response.CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Duration timeout, Executor executor) Sends a message synchronously and expects a response.CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Executor executor) Sends a message synchronously and expects a response.Sends a message asynchronously to the specified communication address.start()stop()voidunregisterHandler(String type) Unregister current handler, if one exists for message type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.atomix.cluster.messaging.MessagingService
sendAndReceive, sendAndReceive, sendAndReceive, sendAsync
-
Constructor Details
-
NettyMessagingService
public NettyMessagingService(String cluster, Address advertisedAddress, MessagingConfig config, io.micrometer.core.instrument.MeterRegistry registry) -
NettyMessagingService
public NettyMessagingService(String cluster, Address advertisedAddress, MessagingConfig config, ProtocolVersion protocolVersion, io.micrometer.core.instrument.MeterRegistry registry)
-
-
Method Details
-
getChannelPool
-
address
Description copied from interface:MessagingServiceReturns the local messaging service address. This is the address used by other nodes to communicate to this service.- Specified by:
addressin interfaceMessagingService- Returns:
- the address remote nodes use to communicate to this node
-
bindingAddresses
Description copied from interface:MessagingServiceReturns the interfaces to which the local messaging service is bind.- Specified by:
bindingAddressesin interfaceMessagingService- 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:MessagingServiceSends a message asynchronously to the specified communication address. The message is specified using the type and payload.- Specified by:
sendAsyncin interfaceMessagingService- 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:MessagingServiceSends a message asynchronously and expects a response.If
keepAliveis 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:
IllegalStateException- the underlying service cannot send the given request (e.g. the service is not running)ConnectException- indicates the recipient is unreachableTimeoutException- indicates no response came back after the default timeoutMessagingException.ProtocolException- indicates the recipient failed to parse the incoming messageMessagingException.NoRemoteHandler- indicates the recipient received the message, but was no expecting toMessagingException.RemoteHandlerFailure- indicates the recipient parsed and expected the message, but it failed unexpectedly to process it
- Specified by:
sendAndReceivein interfaceMessagingService- 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:MessagingServiceSends a message synchronously and expects a response.If
keepAliveis 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:
IllegalStateException- the underlying service cannot send the given request (e.g. the service is not running)ConnectException- indicates the recipient is unreachableTimeoutException- indicates no response came back after the default timeoutMessagingException.ProtocolException- indicates the recipient failed to parse the incoming messageMessagingException.NoRemoteHandler- indicates the recipient received the message, but was no expecting toMessagingException.RemoteHandlerFailure- indicates the recipient parsed and expected the message, but it failed unexpectedly to process it
- Specified by:
sendAndReceivein interfaceMessagingService- Parameters:
address- address to send the message to.type- type of message.payload- message payload.keepAlive- whether to keep the connection alive after usageexecutor- 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:MessagingServiceSends a message asynchronously and expects a response.If
keepAliveis 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:
IllegalStateException- the underlying service cannot send the given request (e.g. the service is not running)ConnectException- indicates the recipient is unreachableTimeoutException- indicates no response came back within the given timeoutMessagingException.ProtocolException- indicates the recipient failed to parse the incoming messageMessagingException.NoRemoteHandler- indicates the recipient received the message, but was no expecting toMessagingException.RemoteHandlerFailure- indicates the recipient parsed and expected the message, but it failed unexpectedly to process it
- Specified by:
sendAndReceivein interfaceMessagingService- Parameters:
address- address to send the message to.type- type of message.payload- message payload.keepAlive- whether to keep the connection alive after usagetimeout- 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:MessagingServiceSends a message synchronously and expects a response.If
keepAliveis 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:
IllegalStateException- the underlying service cannot send the given request (e.g. the service is not running)ConnectException- indicates the recipient is unreachableTimeoutException- indicates no response came back within the given timeoutMessagingException.ProtocolException- indicates the recipient failed to parse the incoming messageMessagingException.NoRemoteHandler- indicates the recipient received the message, but was no expecting toMessagingException.RemoteHandlerFailure- indicates the recipient parsed and expected the message, but it failed unexpectedly to process it
- Specified by:
sendAndReceivein interfaceMessagingService- Parameters:
address- address to send the message to.type- type of message.payload- message payload.keepAlive- whether to keep the connection alive after usagetimeout- response timeoutexecutor- executor over which any follow up actions after completion will be executed.- Returns:
- a response future
-
registerHandler
Description copied from interface:MessagingServiceRegisters a new message handler for message type.- Specified by:
registerHandlerin interfaceMessagingService- Parameters:
type- message type.handler- message handlerexecutor- 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:MessagingServiceRegisters a new message handler for message type.- Specified by:
registerHandlerin interfaceMessagingService- Parameters:
type- message type.handler- message handlerexecutor- executor to use for running message handler logic.
-
registerHandler
public void registerHandler(String type, BiFunction<Address, byte[], CompletableFuture<byte[]>> handler) Description copied from interface:MessagingServiceRegisters a new message handler for message type.- Specified by:
registerHandlerin interfaceMessagingService- Parameters:
type- message type.handler- message handler
-
unregisterHandler
Description copied from interface:MessagingServiceUnregister current handler, if one exists for message type.- Specified by:
unregisterHandlerin interfaceMessagingService- Parameters:
type- message type
-
isRunning
public boolean isRunning()Description copied from interface:MessagingServiceReturns a boolean value indicating whether the managed object is running.- Specified by:
isRunningin interfaceManaged<MessagingService>- Specified by:
isRunningin interfaceMessagingService- Returns:
- Indicates whether the managed object is running.
-
start
- Specified by:
startin interfaceManaged<MessagingService>
-
stop
- Specified by:
stopin interfaceManaged<MessagingService>
-