Interface MessagingService
- All Known Subinterfaces:
ManagedMessagingService
- All Known Implementing Classes:
NettyMessagingService
-
Method Summary
Modifier and TypeMethodDescriptionaddress()Returns the local messaging service address.Returns the interfaces to which the local messaging service is bind.booleanReturns 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.default CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload) Sends a message asynchronously and expects a response on a pooled connection.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.default CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, Duration timeout) Sends a message asynchronously and expects a response on a pooled connection.default CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, Executor executor) Sends a message synchronously and expects a response on a pooled connection.default CompletableFuture<Void> Sends a message asynchronously to the specified communication address.Sends a message asynchronously to the specified communication address.voidunregisterHandler(String type) Unregister current handler, if one exists for message type.
-
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
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:
ConnectException- indicates the recipient is unreachableTimeoutException- indicates no response came back within the given timeout
- 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
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
Sends a message asynchronously and expects a response on a pooled connection.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
- 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
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
- 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:
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
- 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
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
- 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
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:
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
- 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
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
- 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
CompletableFuture<byte[]> sendAndReceive(Address address, String type, byte[] payload, boolean keepAlive, Duration timeout, Executor executor) Sends 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
- 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
Registers a new message handler for message type.- Parameters:
type- message type.handler- message handlerexecutor- executor to use for running message handler logic.
-
registerHandler
Registers a new message handler for message type.- Parameters:
type- message type.handler- message handlerexecutor- executor to use for running message handler logic.
-
registerHandler
Registers a new message handler for message type.- Parameters:
type- message type.handler- message handler
-
unregisterHandler
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.
-