Class 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 a MessagingChannel.

    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.

    See Also:
    MessagingServiceFactory.setChannels(List)
    • 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 the recommended one.
        Unsafe default constructor that should be used only for reflections-based instantiation by IoC frameworks. For programmatic construction the MessagingChannelConfig(Class) constructor must be used instead of this one.

        Instances that are constructed via this constructor will have their base type set to Object.

        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 the message 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 for MessagingChannelConfig(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.
      • getBaseType

        public Class<T> getBaseType()
        Returns the base type of messages that can be transferred over this channel (see MessagingChannelConfig(Class)).
        Returns:
        Base type of messages that can be transferred over this channel.
      • getName

        public String getName()
        Returns the channel name (see setName(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).
      • getPartitions

        public int getPartitions()
        Returns the total amount of partitions that should be managed by the channel's partition mapper (see setPartitions(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's partition 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 of setPartitions(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's partition mapper (see setBackupNodes(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's partition 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 as backup 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's partition mapper.
      • 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.
      • getWorkerThreads

        public int getWorkerThreads()
        Returns the worker thread pool size (see setWorkerThreads(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.
      • 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()
        Returns true if receiver is specified.
        Returns:
        true if receiver is specified.
      • 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 or role). 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.
      • 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.
      • 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.
      • getMessagingTimeout

        public long getMessagingTimeout()
        Returns the timeout in milliseconds that should be applied to all messaging operations within this channel (see setMessagingTimeout(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.
      • getLogCategory

        public String getLogCategory()
        Returns the logging category that should be used by the channel (see setLogCategory(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.
      • getWarnOnRetry

        public int getWarnOnRetry()
        Returns the amount of retry attempts to skip before logging a warn message (see setWarnOnRetry(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 of setWarnOnRetry(int).
        Parameters:
        warnOnRetry - How many attempts to skip before logging a warn message.
        Returns:
        This instance.