Class MessagingChannelConfig<T>
- java.lang.Object
-
- io.hekate.messaging.MessagingConfigBase<MessagingChannelConfig<T>>
-
- io.hekate.messaging.MessagingChannelConfig<T>
-
- Type Parameters:
T
- Base class of messages that can be handled by the channel.
public class MessagingChannelConfig<T> extends MessagingConfigBase<MessagingChannelConfig<T>>
Configuration options for aMessagingChannel
.Instances of this class are strongly recommended to be constructed via the
MessagingChannelConfig(Class)
constructor in order to provide the type safety of messaging operations.Default
(no-arg) constructor of this class is provide for reflections-based instantiations by IoC frameworks only.For configuration options please see the documentation of setter-methods defined in this class.
For generic information about messaging and channels please see the documentation of
MessagingService
.
-
-
Constructor Summary
Constructors Constructor Description MessagingChannelConfig()
Deprecated.Not really deprecated, but set so in order to produce warnings when this constructor is used instead of therecommended
one.MessagingChannelConfig(Class<T> baseType)
Type safe constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getBackupNodes()
Returns the amount of backup nodes that should be assigned to each partition by the the channel'spartition mapper
(seesetBackupNodes(int)
).Class<T>
getBaseType()
Returns the base type of messages that can be transferred over this channel (seeMessagingChannelConfig(Class)
).ClusterNodeFilter
getClusterFilter()
Returns the cluster node filter for this channel (seesetClusterFilter(ClusterNodeFilter)
).List<MessageInterceptor>
getInterceptors()
Returns a list of message interceptors that should be used by the channel (seesetInterceptors(List)
).LoadBalancer<T>
getLoadBalancer()
Returns the unicast load balancer that should be used by the channel (seesetLoadBalancer(LoadBalancer)
).String
getLogCategory()
Returns the logging category that should be used by the channel (seesetLogCategory(String)
).CodecFactory<T>
getMessageCodec()
Returns the codec factory (seesetMessageCodec(CodecFactory)
).long
getMessagingTimeout()
Returns the timeout in milliseconds that should be applied to all messaging operations within this channel (seesetMessagingTimeout(long)
).String
getName()
Returns the channel name (seesetName(String)
).int
getPartitions()
Returns the total amount of partitions that should be managed by the channel'spartition mapper
(seesetPartitions(int)
).MessageReceiver<T>
getReceiver()
Returns the message receiver that should be used to handle incoming messages (seesetReceiver(MessageReceiver)
).GenericRetryConfigurer
getRetryPolicy()
Returns the generic retry policy to be applied to all messaging operations of this channel.int
getWarnOnRetry()
Returns the amount of retry attempts to skip before logging a warn message (seesetWarnOnRetry(int)
).int
getWorkerThreads()
Returns the worker thread pool size (seesetWorkerThreads(int)
).boolean
hasReceiver()
Returnstrue
ifreceiver
is specified.static <T> MessagingChannelConfig<T>
of(Class<T> baseType)
Shortcut method forMessagingChannelConfig(Class)
constructor.void
setBackupNodes(int backupNodes)
Sets the amount of backup nodes that should be assigned to each partition by the the channel'spartition mapper
.void
setClusterFilter(ClusterNodeFilter clusterFilter)
Sets the cluster node filter that should be used to filter nodes during the the message sending.void
setInterceptors(List<MessageInterceptor> interceptors)
Sets the list of message interceptors that should be used by the channel.void
setLoadBalancer(LoadBalancer<T> loadBalancer)
Sets the load balancer that should be used by theMessagingChannel
.void
setLogCategory(String logCategory)
Sets the logging category that should be used by the channel.void
setMessageCodec(CodecFactory<T> messageCodec)
Sets the codec factory to be used for messages serialization/deserialization by this channel.void
setMessagingTimeout(long messagingTimeout)
Sets the timeout in milliseconds that should be applied to all messaging operations of this channel.void
setName(String name)
Sets the channel name.void
setPartitions(int partitions)
Sets the total amount of partitions that should be managed by the channel'spartition mapper
.void
setReceiver(MessageReceiver<T> receiver)
Sets the message receiver that should be used to handle incoming messages.void
setRetryPolicy(GenericRetryConfigurer retryPolicy)
Sets the generic retry policy to be applied to all messaging operations of this channel.void
setWarnOnRetry(int warnOnRetry)
Sets the amount of retry attempts to skip before logging a warn message.void
setWorkerThreads(int workerThreads)
Sets the worker thread pool size.String
toString()
static MessagingChannelConfig<Object>
unchecked()
Shortcut method forMessagingChannelConfig(Class)
constructor to produce polyglot channels withObject
base type.MessagingChannelConfig<T>
withBackupNodes(int backupNodes)
Fluent-style version ofsetBackupNodes(int)
.MessagingChannelConfig<T>
withClusterFilter(ClusterNodeFilter clusterFilter)
Fluent-style version ofsetClusterFilter(ClusterNodeFilter)
.MessagingChannelConfig<T>
withInterceptor(MessageInterceptor interceptor)
Fluent-style version ofsetInterceptors(List)
.MessagingChannelConfig<T>
withLoadBalancer(LoadBalancer<T> loadBalancer)
Fluent-style version ofsetLoadBalancer(LoadBalancer)
.MessagingChannelConfig<T>
withLogCategory(String logCategory)
Fluent-style version ofsetLogCategory(String)
.MessagingChannelConfig<T>
withMessageCodec(CodecFactory<T> codecFactory)
Fluent-style version ofsetMessageCodec(CodecFactory)
.MessagingChannelConfig<T>
withMessagingTimeout(long messagingTimeout)
Fluent-style version ofsetMessagingTimeout(long)
.MessagingChannelConfig<T>
withName(String name)
Fluent-style version ofsetName(String)
.MessagingChannelConfig<T>
withPartitions(int partitions)
Fluent-style version ofsetPartitions(int)
.MessagingChannelConfig<T>
withReceiver(MessageReceiver<T> messageReceiver)
Fluent style version ofsetReceiver(MessageReceiver)
.MessagingChannelConfig<T>
withRetryPolicy(GenericRetryConfigurer retryPolicy)
Fluent-style version ofsetRetryPolicy(GenericRetryConfigurer)
.MessagingChannelConfig<T>
withWarnOnRetry(int warnOnRetry)
Fluent-style version ofsetWarnOnRetry(int)
.MessagingChannelConfig<T>
withWorkerThreads(int workerThreads)
Fluent-style version ofsetWorkerThreads(int)
.-
Methods inherited from class io.hekate.messaging.MessagingConfigBase
getBackPressure, getIdleSocketTimeout, getNioThreads, setBackPressure, setIdleSocketTimeout, setNioThreads, withBackPressure, withBackPressure, withIdleSocketTimeout, withNioThreads
-
-
-
-
Constructor Detail
-
MessagingChannelConfig
@Deprecated public MessagingChannelConfig()
Deprecated.Not really deprecated, but set so in order to produce warnings when this constructor is used instead of therecommended
one.Unsafe default constructor that should be used only for reflections-based instantiation by IoC frameworks. For programmatic construction theMessagingChannelConfig(Class)
constructor must be used instead of this one.Instances that are constructed via this constructor will have their
base type
set toObject
.- See Also:
MessagingChannelConfig(Class)
-
MessagingChannelConfig
public MessagingChannelConfig(Class<T> baseType)
Type safe constructor.This constructor sets the base type for messages that can be transferred over this channel. If an attempt is made to transfer a message who's type is not compatible with the specified one then an error will
Important: the specified base type must be compatible with the
base type
of themessage codec
of this channel and must be the same across all cluster nodes.- Parameters:
baseType
- Base type of messages that can be transferred over this channel.
-
-
Method Detail
-
of
public static <T> MessagingChannelConfig<T> of(Class<T> baseType)
Shortcut method forMessagingChannelConfig(Class)
constructor.- Type Parameters:
T
- Base type of messages that can be transferred over this channel.- Parameters:
baseType
- Base type of messages that can be transferred over this channel.- Returns:
- New instance.
-
unchecked
public static MessagingChannelConfig<Object> unchecked()
Shortcut method forMessagingChannelConfig(Class)
constructor to produce polyglot channels withObject
base type.- Returns:
- New instance.
- See Also:
MessagingChannelConfig(Class)
-
getBaseType
public Class<T> getBaseType()
Returns the base type of messages that can be transferred over this channel (seeMessagingChannelConfig(Class)
).- Returns:
- Base type of messages that can be transferred over this channel.
-
getName
public String getName()
Returns the channel name (seesetName(String)
).- Returns:
- Channel name.
-
setName
public void setName(String name)
Sets the channel name. Can contain only alpha-numeric characters and non-repeatable dots/hyphens.Each channel must have a unique name within the
MessagingService
instance. Messages that were sent by the particular channel can be handled only by a channel with the same name on the remote node.This name can be used to obtain channel by its name via
MessagingService.channel(String)
.This parameter is mandatory and doesn't have a default value.
- Parameters:
name
- Unique channel name (can contain only alpha-numeric characters and non-repeatable dots/hyphens).
-
withName
public MessagingChannelConfig<T> withName(String name)
Fluent-style version ofsetName(String)
.- Parameters:
name
- Unique channel name.- Returns:
- This instance.
-
getPartitions
public int getPartitions()
Returns the total amount of partitions that should be managed by the channel'spartition mapper
(seesetPartitions(int)
).- Returns:
- Total amount of partitions.
-
setPartitions
public void setPartitions(int partitions)
Sets the total amount of partitions that should be managed by the channel'spartition mapper
.Value of this parameter must be above zero and must be a power of two. Default value is specified by
RendezvousHashMapper.DEFAULT_PARTITIONS
.- Parameters:
partitions
- Total amount of partitions that should be managed by the channel's partition mapper (value must be a power of two).
-
withPartitions
public MessagingChannelConfig<T> withPartitions(int partitions)
Fluent-style version ofsetPartitions(int)
.- Parameters:
partitions
- Total amount of partitions that should be managed by the channel's partition mapper (value must be a power of two).- Returns:
- This instance.
-
getBackupNodes
public int getBackupNodes()
Returns the amount of backup nodes that should be assigned to each partition by the the channel'spartition mapper
(seesetBackupNodes(int)
).- Returns:
- Amount of backup nodes.
-
setBackupNodes
public void setBackupNodes(int backupNodes)
Sets the amount of backup nodes that should be assigned to each partition by the the channel'spartition mapper
.If value of this parameter is zero then the channel's mapper will not manage
backup nodes
. If value of this parameter is negative then all available cluster nodes will be used asbackup nodes
.Default value of this parameter is 0 (i.e. backup nodes management is disabled).
- Parameters:
backupNodes
- Amount of backup nodes that should be assigned to each partition of the channel'spartition mapper
.
-
withBackupNodes
public MessagingChannelConfig<T> withBackupNodes(int backupNodes)
Fluent-style version ofsetBackupNodes(int)
.- Parameters:
backupNodes
- Amount of backup nodes that should be assigned to each partition of the channel'spartition mapper
.- Returns:
- This instance.
-
getMessageCodec
public CodecFactory<T> getMessageCodec()
Returns the codec factory (seesetMessageCodec(CodecFactory)
).- Returns:
- Codec factory.
-
setMessageCodec
public void setMessageCodec(CodecFactory<T> messageCodec)
Sets the codec factory to be used for messages serialization/deserialization by this channel.If not specified then the default general-purpose codec will be used (see
HekateBootstrap.setDefaultCodec(CodecFactory)
).- Parameters:
messageCodec
- Codec factory.
-
withMessageCodec
public MessagingChannelConfig<T> withMessageCodec(CodecFactory<T> codecFactory)
Fluent-style version ofsetMessageCodec(CodecFactory)
.- Parameters:
codecFactory
- Codec factory.- Returns:
- This instance.
-
getWorkerThreads
public int getWorkerThreads()
Returns the worker thread pool size (seesetWorkerThreads(int)
).- Returns:
- Worker thread pool size.
-
setWorkerThreads
public void setWorkerThreads(int workerThreads)
Sets the worker thread pool size.Setting this parameter to a positive value instructs the channel to create a dedicated thread pool for messages handling and callbacks notification. If this parameter is negative or zero (default value) then messages handling and callbacks notification will be performed on the NIO thread. It is recommended to use the dedicated thread pool in case of long and heavy message processing operations.
- Parameters:
workerThreads
- Worker thread pool size.
-
withWorkerThreads
public MessagingChannelConfig<T> withWorkerThreads(int workerThreads)
Fluent-style version ofsetWorkerThreads(int)
.- Parameters:
workerThreads
- Worker thread pool size.- Returns:
- This instance.
-
getReceiver
public MessageReceiver<T> getReceiver()
Returns the message receiver that should be used to handle incoming messages (seesetReceiver(MessageReceiver)
).- Returns:
- Message receiver.
-
setReceiver
public void setReceiver(MessageReceiver<T> receiver)
Sets the message receiver that should be used to handle incoming messages.This parameter is optional and if not configured then channel will act in a client-only mode (i.e. it will be able to issue requests to remote nodes but will not be able to process request from remote nodes).
For more details about channels and messages handling please see the documentation of
MessagingService
interface.- Parameters:
receiver
- Message receiver.
-
hasReceiver
public boolean hasReceiver()
Returnstrue
ifreceiver
is specified.- Returns:
true
ifreceiver
is specified.
-
withReceiver
public MessagingChannelConfig<T> withReceiver(MessageReceiver<T> messageReceiver)
Fluent style version ofsetReceiver(MessageReceiver)
.- Parameters:
messageReceiver
- Message receiver.- Returns:
- This instance.
-
getClusterFilter
public ClusterNodeFilter getClusterFilter()
Returns the cluster node filter for this channel (seesetClusterFilter(ClusterNodeFilter)
).- Returns:
- Cluster node filter.
-
setClusterFilter
public void setClusterFilter(ClusterNodeFilter clusterFilter)
Sets the cluster node filter that should be used to filter nodes during the the message sending.Filtering can be used to limit communications between nodes based on some custom criteria (f.e. enable communications only between those nodes that have some specific
property
orrole
). Only those nodes that match the specified filter will be included into the messaging channel's cluster topology.This parameter is optional.
- Parameters:
clusterFilter
- Cluster node filter.
-
withClusterFilter
public MessagingChannelConfig<T> withClusterFilter(ClusterNodeFilter clusterFilter)
Fluent-style version ofsetClusterFilter(ClusterNodeFilter)
.- Parameters:
clusterFilter
- Cluster node filter.- Returns:
- This instance.
-
getRetryPolicy
public GenericRetryConfigurer getRetryPolicy()
Returns the generic retry policy to be applied to all messaging operations of this channel.- Returns:
- Generic retry policy to be applied to all messaging operations of this channel.
-
setRetryPolicy
public void setRetryPolicy(GenericRetryConfigurer retryPolicy)
Sets the generic retry policy to be applied to all messaging operations of this channel.This policy can be overridden for each individual operation via the following methods:
- Parameters:
retryPolicy
- Retry policy.
-
withRetryPolicy
public MessagingChannelConfig<T> withRetryPolicy(GenericRetryConfigurer retryPolicy)
Fluent-style version ofsetRetryPolicy(GenericRetryConfigurer)
.- Parameters:
retryPolicy
- Retry policy.- Returns:
- This instance.
-
getLoadBalancer
public LoadBalancer<T> getLoadBalancer()
Returns the unicast load balancer that should be used by the channel (seesetLoadBalancer(LoadBalancer)
).- Returns:
- Unicast load balancer.
-
setLoadBalancer
public void setLoadBalancer(LoadBalancer<T> loadBalancer)
Sets the load balancer that should be used by theMessagingChannel
.Note: it is also possible to set load balancer dynamically via
MessagingChannel.withLoadBalancer(LoadBalancer)
.- Parameters:
loadBalancer
- Unicast load balancer.
-
withLoadBalancer
public MessagingChannelConfig<T> withLoadBalancer(LoadBalancer<T> loadBalancer)
Fluent-style version ofsetLoadBalancer(LoadBalancer)
.- Parameters:
loadBalancer
- Unicast load balancer.- Returns:
- This instance.
-
getInterceptors
public List<MessageInterceptor> getInterceptors()
Returns a list of message interceptors that should be used by the channel (seesetInterceptors(List)
).- Returns:
- Message interceptors.
-
setInterceptors
public void setInterceptors(List<MessageInterceptor> interceptors)
Sets the list of message interceptors that should be used by the channel.Interceptors can be registered to the messaging channel in order to track message flow or to apply transformations to messages.
- Parameters:
interceptors
- Message interceptors.
-
withInterceptor
public MessagingChannelConfig<T> withInterceptor(MessageInterceptor interceptor)
Fluent-style version ofsetInterceptors(List)
.- Parameters:
interceptor
- Message interceptor.- Returns:
- This instance.
-
getMessagingTimeout
public long getMessagingTimeout()
Returns the timeout in milliseconds that should be applied to all messaging operations within this channel (seesetMessagingTimeout(long)
).- Returns:
- Timeout in milliseconds.
-
setMessagingTimeout
public void setMessagingTimeout(long messagingTimeout)
Sets the timeout in milliseconds that should be applied to all messaging operations of this channel.If particular messaging operation can't be completed within the specified timeout then such operation will fail with
MessageTimeoutException
.If value of this parameter is less than or equals to zero then timeouts will not be applied to messaging operations. Default value of this parameter is 0.
- Parameters:
messagingTimeout
- Timeout in milliseconds.
-
withMessagingTimeout
public MessagingChannelConfig<T> withMessagingTimeout(long messagingTimeout)
Fluent-style version ofsetMessagingTimeout(long)
.- Parameters:
messagingTimeout
- Timeout in milliseconds.- Returns:
- This instance.
-
getLogCategory
public String getLogCategory()
Returns the logging category that should be used by the channel (seesetLogCategory(String)
).- Returns:
- Logging category.
-
setLogCategory
public void setLogCategory(String logCategory)
Sets the logging category that should be used by the channel.- Parameters:
logCategory
- Logging category.
-
withLogCategory
public MessagingChannelConfig<T> withLogCategory(String logCategory)
Fluent-style version ofsetLogCategory(String)
.- Parameters:
logCategory
- Logging category.- Returns:
- This instance.
-
getWarnOnRetry
public int getWarnOnRetry()
Returns the amount of retry attempts to skip before logging a warn message (seesetWarnOnRetry(int)
).- Returns:
- Amount of retry attempts to skip before logging a warn message.
-
setWarnOnRetry
public void setWarnOnRetry(int warnOnRetry)
Sets the amount of retry attempts to skip before logging a warn message.- 0 - log every attempt
- positive N - log every N'th attempt
- negative - do not log warning on retries
By default this property is set to a negative value (i.e. retry warnings are disabled).
- Parameters:
warnOnRetry
- How many attempts to skip before logging a warn message.
-
withWarnOnRetry
public MessagingChannelConfig<T> withWarnOnRetry(int warnOnRetry)
Fluent-style version ofsetWarnOnRetry(int)
.- Parameters:
warnOnRetry
- How many attempts to skip before logging a warn message.- Returns:
- This instance.
-
-