Interface MessagingChannel<T>
-
- Type Parameters:
T
- Base type fo messages that can be handled by channels.
- All Superinterfaces:
ClusterFilterSupport<MessagingChannel<T>>
public interface MessagingChannel<T> extends ClusterFilterSupport<MessagingChannel<T>>
Messaging channel.This interface represents a channel for exchanging messages with remote nodes.
Instances of this interface can be obtained via the
MessagingService.channel(String, Class)
method.For more details about messaging and channels please see the documentation of
MessagingService
interface.- See Also:
MessagingService.channel(String, Class)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default AggregateResult<T>
aggregate(Object affinityKey, T msg)
Synchronously submits the specified aggregation request.default AggregateResult<T>
aggregate(T msg)
Synchronously submits the specified aggregation request.default AggregateFuture<T>
aggregateAsync(Object affinityKey, T msg)
Asynchronously submits the specified aggregation request.default AggregateFuture<T>
aggregateAsync(T msg)
Asynchronously submits the specified aggregation request.Class<T>
baseType()
Returns the base type of messages that can be transferred through this channel.default BroadcastResult<T>
broadcast(Object affinityKey, T msg)
Synchronously broadcasts the specified message with a mandatory acknowledgement.default BroadcastResult<T>
broadcast(Object affinityKey, T msg, AckMode ackMode)
Synchronously broadcasts the specified message with the specified acknowledgement mode.default BroadcastResult<T>
broadcast(T msg)
Synchronously broadcasts the specified message with a mandatory acknowledgement.default BroadcastResult<T>
broadcast(T msg, AckMode ackMode)
Synchronously broadcasts the specified message with the specified acknowledgement mode.default BroadcastFuture<T>
broadcastAsync(Object affinityKey, T msg)
Asynchronously broadcasts the specified message with a mandatory acknowledgement.default BroadcastFuture<T>
broadcastAsync(Object affinityKey, T msg, AckMode ackMode)
Asynchronously broadcasts the specified message with the specified acknowledgement mode.default BroadcastFuture<T>
broadcastAsync(T msg)
Asynchronously broadcasts the specified message with a mandatory acknowledgement.default BroadcastFuture<T>
broadcastAsync(T msg, AckMode ackMode)
Asynchronously broadcasts the specified message with the specified acknowledgement mode.ClusterView
cluster()
Returns the cluster view of this channel.Executor
executor()
Returns the executor of this channel.MessagingChannelId
id()
Returns the universally unique identifier of this channel.String
name()
Returns the channel name.Aggregate<T>
newAggregate(T request)
Creates a newAggregate
operation.Broadcast<T>
newBroadcast(T request)
Creates a newBroadcast
operation.Request<T>
newRequest(T request)
Creates a newRequest
operation.Send<T>
newSend(T message)
Creates a newSend
operation.Subscribe<T>
newSubscribe(T request)
Creates a newSubscribe
operation.int
nioThreads()
Returns the size of a thread pool for handling NIO-based socket connections (seeMessagingConfigBase.setNioThreads(int)
).PartitionMapper
partitions()
Returns the partition mapper of this channel.default T
request(Object affinityKey, T msg)
Synchronously sends the specified request and awaits for a response.default T
request(T msg)
Synchronously sends the specified request and awaits for a response.default RequestFuture<T>
requestAsync(Object affinityKey, T msg)
Asynchronously sends the specified request.default RequestFuture<T>
requestAsync(T msg)
Asynchronously sends the specified request.default void
send(Object affinityKey, T msg)
Synchronously sends the specified message and awaits for an acknowledgement.default void
send(Object affinityKey, T msg, AckMode ackMode)
Synchronously sends the specified message with the specified acknowledgement mode.default void
send(T msg)
Synchronously sends the specified message and awaits for an acknowledgement.default void
send(T msg, AckMode ackMode)
Synchronously sends the specified message with the specified acknowledgement mode.default SendFuture
sendAsync(Object affinityKey, T msg)
Asynchronously sends the specified message with a mandatory acknowledgement.default SendFuture
sendAsync(Object affinityKey, T msg, AckMode ackMode)
Asynchronously sends the specified message with the specified acknowledgement mode.default SendFuture
sendAsync(T msg)
Asynchronously sends the specified message with a mandatory acknowledgement.default SendFuture
sendAsync(T msg, AckMode ackMode)
Asynchronously sends the specified message with the specified acknowledgement mode.default List<T>
subscribe(Object affinityKey, T msg)
Synchronously sends the specified subscription request and accumulates all responses.default List<T>
subscribe(T msg)
Synchronously sends the specified subscription request and accumulates all responses.default SubscribeFuture<T>
subscribeAsync(Object affinityKey, T msg, SubscribeCallback<T> callback)
Asynchronously sends the specified subscription request.default SubscribeFuture<T>
subscribeAsync(T msg, SubscribeCallback<T> callback)
Asynchronously sends the specified subscription request.MessagingChannel<T>
withCluster(ClusterView cluster)
Returns a copy of this channel that will use the specified cluster view and will inherit all other options from this instance.MessagingChannel<T>
withLoadBalancer(LoadBalancer<T> balancer)
Returns a copy of this channel that will use the specified load balancer and will inherit all other options from this instance.MessagingChannel<T>
withPartitions(int partitions, int backupNodes)
Returns a copy of this channel that will use aRendezvousHashMapper
with the specified options.MessagingChannel<T>
withPartitions(PartitionMapper mapper)
Returns a copy of this channel that will use the specifiedPartitionMapper
.int
workerThreads()
Returns the worker thread pool size (seeMessagingChannelConfig.setWorkerThreads(int)
).-
Methods inherited from interface io.hekate.cluster.ClusterFilterSupport
filter, filterAll, forNode, forNode, forOldest, forProperty, forProperty, forRemotes, forRole, forService, forYoungest
-
-
-
-
Method Detail
-
newSend
Send<T> newSend(T message)
Creates a newSend
operation.Send operation doesn't assume any response to be received from the destination node. If request-response type of communication is required then consider using the
newRequest(Object)
method.By default, this operation will not wait for the message to be processed on the receiver side. It is possible to change this behavior via
Send.withAckMode(AckMode)
method.- Parameters:
message
- Message to be sent.- Returns:
- New operation.
- See Also:
Send.submit()
-
newRequest
Request<T> newRequest(T request)
Creates a newRequest
operation.- Parameters:
request
- Request.- Returns:
- New operation.
- See Also:
Request.submit()
-
newSubscribe
Subscribe<T> newSubscribe(T request)
Creates a newSubscribe
operation.- Parameters:
request
- Subscription request.- Returns:
- New operation.
- See Also:
Subscribe.submit(SubscribeCallback)
-
newBroadcast
Broadcast<T> newBroadcast(T request)
Creates a newBroadcast
operation.By default, this operation will not wait for the message to be processed on the receiver side. It is possible to change this behavior via
Broadcast.withAckMode(AckMode)
method.- Parameters:
request
- Message to broadcast.- Returns:
- New operation.
- See Also:
Broadcast.submit()
-
newAggregate
Aggregate<T> newAggregate(T request)
Creates a newAggregate
operation.- Parameters:
request
- Aggregation request.- Returns:
- New operation.
- See Also:
Aggregate.submit()
-
id
MessagingChannelId id()
Returns the universally unique identifier of this channel.- Returns:
- Universally unique identifier of this channel.
-
name
String name()
Returns the channel name.- Returns:
- Channel name.
- See Also:
MessagingChannelConfig.setName(String)
-
baseType
Class<T> baseType()
Returns the base type of messages that can be transferred through this channel.- Returns:
- Base type of messages that can be transferred through this channel.
- See Also:
MessagingChannelConfig(Class)
-
nioThreads
int nioThreads()
Returns the size of a thread pool for handling NIO-based socket connections (seeMessagingConfigBase.setNioThreads(int)
).- Returns:
- Size of a thread pool for handling NIO-based socket connections.
-
workerThreads
int workerThreads()
Returns the worker thread pool size (seeMessagingChannelConfig.setWorkerThreads(int)
).- Returns:
- Worker thread pool size.
-
partitions
PartitionMapper partitions()
Returns the partition mapper of this channel.- Returns:
- Mapper.
- See Also:
MessagingChannelConfig.setPartitions(int)
,MessagingChannelConfig.setBackupNodes(int)
,withPartitions(int, int)
-
withPartitions
MessagingChannel<T> withPartitions(int partitions, int backupNodes)
Returns a copy of this channel that will use aRendezvousHashMapper
with the specified options.- Parameters:
partitions
- SeeRendezvousHashMapper.Builder.withPartitions(int)
.backupNodes
- SeeRendezvousHashMapper.Builder.withBackupNodes(int)
.- Returns:
- Channel wrapper.
- See Also:
partitions()
-
withPartitions
MessagingChannel<T> withPartitions(PartitionMapper mapper)
Returns a copy of this channel that will use the specifiedPartitionMapper
.- Parameters:
mapper
- Partition mapper.- Returns:
- Channel wrapper.
- See Also:
partitions()
-
withLoadBalancer
MessagingChannel<T> withLoadBalancer(LoadBalancer<T> balancer)
Returns a copy of this channel that will use the specified load balancer and will inherit all other options from this instance.If not specified or set to
null
thenDefaultLoadBalancer
will be used.- Parameters:
balancer
- Load balancer.- Returns:
- Channel wrapper.
- See Also:
MessagingChannelConfig.setLoadBalancer(LoadBalancer)
-
cluster
ClusterView cluster()
Returns the cluster view of this channel.The returned cluster view contains only those nodes that have a
receiver
and do match the channel'sfiltering
criteria.- Returns:
- Cluster view.
-
withCluster
MessagingChannel<T> withCluster(ClusterView cluster)
Returns a copy of this channel that will use the specified cluster view and will inherit all other options from this instance.- Parameters:
cluster
- Cluster view.- Returns:
- Channel wrapper.
-
executor
Executor executor()
Returns the executor of this channel.- Returns:
- Asynchronous task executor of this channel.
- See Also:
MessagingChannelConfig.setWorkerThreads(int)
-
sendAsync
default SendFuture sendAsync(T msg)
Asynchronously sends the specified message with a mandatory acknowledgement.- Parameters:
msg
- Message.- Returns:
- Future object to be completed after receiving an acknowledgement.
-
sendAsync
default SendFuture sendAsync(T msg, AckMode ackMode)
Asynchronously sends the specified message with the specified acknowledgement mode.- Parameters:
msg
- Message.ackMode
- Acknowledgement mode.- Returns:
- Operation future.
-
sendAsync
default SendFuture sendAsync(Object affinityKey, T msg)
Asynchronously sends the specified message with a mandatory acknowledgement.- Parameters:
affinityKey
- Affinity key (seeSend.withAffinity(Object)
).msg
- Message.- Returns:
- Future object to be completed after receiving an acknowledgement.
-
sendAsync
default SendFuture sendAsync(Object affinityKey, T msg, AckMode ackMode)
Asynchronously sends the specified message with the specified acknowledgement mode.- Parameters:
affinityKey
- Affinity key (seeSend.withAffinity(Object)
).msg
- Message.ackMode
- Acknowledgement mode.- Returns:
- Operation future.
-
send
default void send(T msg) throws HekateException
Synchronously sends the specified message and awaits for an acknowledgement.- Parameters:
msg
- Message.- Throws:
HekateException
- If operation failed.
-
send
default void send(T msg, AckMode ackMode) throws HekateException
Synchronously sends the specified message with the specified acknowledgement mode.- Parameters:
msg
- Message.ackMode
- Acknowledgement mode.- Throws:
HekateException
- If operation failed.
-
send
default void send(Object affinityKey, T msg) throws HekateException
Synchronously sends the specified message and awaits for an acknowledgement.- Parameters:
affinityKey
- Affinity key (seeSend.withAffinity(Object)
).msg
- Message.- Throws:
HekateException
- If operation failed.
-
send
default void send(Object affinityKey, T msg, AckMode ackMode) throws HekateException
Synchronously sends the specified message with the specified acknowledgement mode.- Parameters:
affinityKey
- Affinity key (seeSend.withAffinity(Object)
).msg
- Message.ackMode
- Acknowledgement mode.- Throws:
HekateException
- If operation failed.
-
requestAsync
default RequestFuture<T> requestAsync(T msg)
Asynchronously sends the specified request.- Parameters:
msg
- Request message.- Returns:
- Future object to be completed after receiving a response.
-
requestAsync
default RequestFuture<T> requestAsync(Object affinityKey, T msg)
Asynchronously sends the specified request.- Parameters:
affinityKey
- Affinity key (seeRequest.withAffinity(Object)
).msg
- Request message.- Returns:
- Future object to be completed after receiving a response.
-
request
default T request(T msg) throws HekateException
Synchronously sends the specified request and awaits for a response.- Parameters:
msg
- Request message.- Returns:
- Response.
- Throws:
HekateException
- If operation failed.
-
request
default T request(Object affinityKey, T msg) throws HekateException
Synchronously sends the specified request and awaits for a response.- Parameters:
affinityKey
- Affinity key (seeRequest.withAffinity(Object)
).msg
- Request message.- Returns:
- Response.
- Throws:
HekateException
- If operation failed.
-
subscribeAsync
default SubscribeFuture<T> subscribeAsync(T msg, SubscribeCallback<T> callback)
Asynchronously sends the specified subscription request.- Parameters:
msg
- Subscription request message.callback
- Subscription callback.- Returns:
- Future object to be completed after receiving the final response (see
ResponsePart.isLastPart()
).
-
subscribeAsync
default SubscribeFuture<T> subscribeAsync(Object affinityKey, T msg, SubscribeCallback<T> callback)
Asynchronously sends the specified subscription request.- Parameters:
affinityKey
- Affinity key (seeSubscribe.withAffinity(Object)
).msg
- Subscription request message.callback
- Subscription callback.- Returns:
- Future object to be completed after receiving the final response (see
ResponsePart.isLastPart()
).
-
subscribe
default List<T> subscribe(T msg) throws HekateException
Synchronously sends the specified subscription request and accumulates all responses.Notice: This method blocks until the final response is received (see
ResponsePart.isLastPart()
) and accumulates all intermediate parts in memory.- Parameters:
msg
- Subscription request message.- Returns:
- All response parts that were received.
- Throws:
HekateException
- If operation failed.
-
subscribe
default List<T> subscribe(Object affinityKey, T msg) throws HekateException
Synchronously sends the specified subscription request and accumulates all responses.Notice: This method blocks until the final response is received (see
ResponsePart.isLastPart()
) and accumulates all intermediate parts in memory.- Parameters:
affinityKey
- Affinity key (seeSubscribe.withAffinity(Object)
).msg
- Subscription request message.- Returns:
- All response parts that were received.
- Throws:
HekateException
- If operation failed.
-
broadcastAsync
default BroadcastFuture<T> broadcastAsync(T msg)
Asynchronously broadcasts the specified message with a mandatory acknowledgement.- Parameters:
msg
- Message.- Returns:
- Future object to be completed after receiving acknowledgements from all nodes.
-
broadcastAsync
default BroadcastFuture<T> broadcastAsync(T msg, AckMode ackMode)
Asynchronously broadcasts the specified message with the specified acknowledgement mode.- Parameters:
msg
- Message.ackMode
- Acknowledgement mode.- Returns:
- Operation future.
-
broadcastAsync
default BroadcastFuture<T> broadcastAsync(Object affinityKey, T msg)
Asynchronously broadcasts the specified message with a mandatory acknowledgement.- Parameters:
affinityKey
- Affinity key (seeBroadcast.withAffinity(Object)
).msg
- Message.- Returns:
- Future object to be completed after receiving acknowledgements from all nodes.
-
broadcastAsync
default BroadcastFuture<T> broadcastAsync(Object affinityKey, T msg, AckMode ackMode)
Asynchronously broadcasts the specified message with the specified acknowledgement mode.- Parameters:
affinityKey
- Affinity key (seeBroadcast.withAffinity(Object)
).msg
- Message.ackMode
- Acknowledgement mode.- Returns:
- Operation future.
-
broadcast
default BroadcastResult<T> broadcast(T msg) throws HekateException
Synchronously broadcasts the specified message with a mandatory acknowledgement.- Parameters:
msg
- Message.- Returns:
- Broadcast result.
- Throws:
HekateException
- If operation failed.
-
broadcast
default BroadcastResult<T> broadcast(T msg, AckMode ackMode) throws HekateException
Synchronously broadcasts the specified message with the specified acknowledgement mode.- Parameters:
msg
- Message.ackMode
- Acknowledgement mode.- Returns:
- Broadcast result.
- Throws:
HekateException
- If operation failed.
-
broadcast
default BroadcastResult<T> broadcast(Object affinityKey, T msg) throws HekateException
Synchronously broadcasts the specified message with a mandatory acknowledgement.- Parameters:
affinityKey
- Affinity key (seeBroadcast.withAffinity(Object)
).msg
- Message.- Returns:
- Broadcast result.
- Throws:
HekateException
- If operation failed.
-
broadcast
default BroadcastResult<T> broadcast(Object affinityKey, T msg, AckMode ackMode) throws HekateException
Synchronously broadcasts the specified message with the specified acknowledgement mode.- Parameters:
affinityKey
- Affinity key (seeBroadcast.withAffinity(Object)
).msg
- Message.ackMode
- Acknowledgement mode.- Returns:
- Broadcast result.
- Throws:
HekateException
- If operation failed.
-
aggregateAsync
default AggregateFuture<T> aggregateAsync(T msg)
Asynchronously submits the specified aggregation request.- Parameters:
msg
- Aggregation request message.- Returns:
- Future object to be completed after receiving responses from all nodes.
-
aggregateAsync
default AggregateFuture<T> aggregateAsync(Object affinityKey, T msg)
Asynchronously submits the specified aggregation request.- Parameters:
affinityKey
- Affinity key (seeAggregate.withAffinity(Object)
).msg
- Aggregation request message.- Returns:
- Future object to be completed after receiving responses from all nodes.
-
aggregate
default AggregateResult<T> aggregate(T msg) throws HekateException
Synchronously submits the specified aggregation request.- Parameters:
msg
- Aggregation request message.- Returns:
- Aggregation result.
- Throws:
HekateException
- If operation failed.
-
aggregate
default AggregateResult<T> aggregate(Object affinityKey, T msg) throws HekateException
Synchronously submits the specified aggregation request.- Parameters:
affinityKey
- Affinity key (seeAggregate.withAffinity(Object)
).msg
- Aggregation request message.- Returns:
- Aggregation result.
- Throws:
HekateException
- If operation failed.
-
-