Interface MessagingService
-
public interface MessagingService
Interface for low level messaging primitives.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
registerHandler(String type, BiConsumer<Endpoint,byte[]> handler, Executor executor)
Registers a new message handler for message type.void
registerHandler(String type, BiFunction<Endpoint,byte[],byte[]> handler, Executor executor)
Registers a new message handler for message type.void
registerHandler(String type, BiFunction<Endpoint,byte[],CompletableFuture<byte[]>> handler)
Registers a new message handler for message type.default CompletableFuture<byte[]>
sendAndReceive(Endpoint ep, String type, byte[] payload)
Sends a message asynchronously and expects a response.default CompletableFuture<byte[]>
sendAndReceive(Endpoint ep, String type, byte[] payload, Duration timeout)
Sends a message asynchronously and expects a response.CompletableFuture<byte[]>
sendAndReceive(Endpoint ep, String type, byte[] payload, Duration timeout, Executor executor)
Sends a message synchronously and expects a response.default CompletableFuture<byte[]>
sendAndReceive(Endpoint ep, String type, byte[] payload, Executor executor)
Sends a message synchronously and expects a response.CompletableFuture<Void>
sendAsync(Endpoint ep, String type, byte[] payload)
Sends a message asynchronously to the specified communication end point.void
unregisterHandler(String type)
Unregister current handler, if one exists for message type.
-
-
-
Method Detail
-
sendAsync
CompletableFuture<Void> sendAsync(Endpoint ep, String type, byte[] payload)
Sends a message asynchronously to the specified communication end point. The message is specified using the type and payload.- Parameters:
ep
- end point to send the message to.type
- type of message.payload
- message payload bytes.- Returns:
- future that is completed when the message is sent
-
sendAndReceive
default CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload)
Sends a message asynchronously and expects a response.- Parameters:
ep
- end point to send the message to.type
- type of message.payload
- message payload.- Returns:
- a response future
-
sendAndReceive
default CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload, Executor executor)
Sends a message synchronously and expects a response.- Parameters:
ep
- end point 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
default CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload, Duration timeout)
Sends a message asynchronously and expects a response.- Parameters:
ep
- end point to send the message to.type
- type of message.payload
- message payload.timeout
- operation timeout- Returns:
- a response future
-
sendAndReceive
CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload, Duration timeout, Executor executor)
Sends a message synchronously and expects a response.- Parameters:
ep
- end point 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.timeout
- operation timeout- Returns:
- a response future
-
registerHandler
void registerHandler(String type, BiConsumer<Endpoint,byte[]> handler, Executor executor)
Registers a new message handler for message type.- Parameters:
type
- message type.handler
- message handlerexecutor
- executor to use for running message handler logic.
-
registerHandler
void registerHandler(String type, BiFunction<Endpoint,byte[],byte[]> handler, Executor executor)
Registers a new message handler for message type.- Parameters:
type
- message type.handler
- message handlerexecutor
- executor to use for running message handler logic.
-
registerHandler
void registerHandler(String type, BiFunction<Endpoint,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
-
-