io.hekate.messaging.MessagingChannelConfig Maven / Gradle / Ivy
Show all versions of hekate-core Show documentation
/*
* Copyright 2020 The Hekate Project
*
* The Hekate Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.hekate.messaging;
import io.hekate.cluster.ClusterNode;
import io.hekate.cluster.ClusterNodeFilter;
import io.hekate.codec.Codec;
import io.hekate.codec.CodecFactory;
import io.hekate.core.HekateBootstrap;
import io.hekate.core.internal.util.ArgAssert;
import io.hekate.messaging.intercept.MessageInterceptor;
import io.hekate.messaging.loadbalance.LoadBalancer;
import io.hekate.messaging.operation.Aggregate;
import io.hekate.messaging.operation.AggregateRetryConfigurer;
import io.hekate.messaging.operation.Broadcast;
import io.hekate.messaging.operation.BroadcastRetryConfigurer;
import io.hekate.messaging.operation.Request;
import io.hekate.messaging.operation.RequestRetryConfigurer;
import io.hekate.messaging.operation.Send;
import io.hekate.messaging.operation.SendRetryConfigurer;
import io.hekate.messaging.retry.GenericRetryConfigurer;
import io.hekate.partition.Partition;
import io.hekate.partition.RendezvousHashMapper;
import io.hekate.util.format.ToString;
import java.util.ArrayList;
import java.util.List;
/**
* Configuration options for a {@link MessagingChannel}.
*
*
* Instances of this class are strongly recommended to be constructed via the {@link #MessagingChannelConfig(Class)} constructor in order
* to provide the type safety of messaging operations. {@link #MessagingChannelConfig() 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 {@link MessagingService}.
*
*
* @param Base class of messages that can be handled by the channel.
*
* @see MessagingServiceFactory#setChannels(List)
*/
public class MessagingChannelConfig extends MessagingConfigBase> {
/** See {@link #MessagingChannelConfig(Class)}. */
private final Class baseType;
/** See {@link #setName(String)}. */
private String name;
/** See {@link #setWorkerThreads(int)}. */
private int workerThreads;
/** See {@link #setPartitions(int)}. */
private int partitions = RendezvousHashMapper.DEFAULT_PARTITIONS;
/** See {@link #setBackupNodes(int)}. */
private int backupNodes;
/** See {@link #setMessageCodec(CodecFactory)}. */
private CodecFactory messageCodec;
/** See {@link #setClusterFilter(ClusterNodeFilter)}. */
private ClusterNodeFilter clusterFilter;
/** See {@link #setReceiver(MessageReceiver)}. */
private MessageReceiver receiver;
/** See {@link #setRetryPolicy(GenericRetryConfigurer)}. */
private GenericRetryConfigurer retryPolicy;
/** See {@link #setLoadBalancer(LoadBalancer)}. */
private LoadBalancer loadBalancer;
/** See {@link #setInterceptors(List)}. */
private List interceptors;
/** See {@link #setMessagingTimeout(long)}. */
private long messagingTimeout;
/** See {@link #setLogCategory(String)}. */
private String logCategory;
/** See {@link #setWarnOnRetry(int)}. */
private int warnOnRetry = -1;
/**
* Unsafe default constructor that should be used only for reflections-based instantiation by IoC frameworks. For programmatic
* construction the {@link #MessagingChannelConfig(Class)} constructor must be used instead of this one.
*
*
* Instances that are constructed via this constructor will have their {@link #getBaseType() base type} set to {@link Object}.
*
*
* @see #MessagingChannelConfig(Class)
* @deprecated Not really deprecated, but set so in order to produce warnings when this constructor is used instead of the {@link
* #MessagingChannelConfig(Class) recommended} one.
*/
@Deprecated
public MessagingChannelConfig() {
baseType = uncheckedObjectType();
}
/**
* 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 {@link Codec#baseType() base type} of the
* {@link #setMessageCodec(CodecFactory) message codec} of this channel and must be the same across all cluster nodes.
*
*
* @param baseType Base type of messages that can be transferred over this channel.
*/
public MessagingChannelConfig(Class baseType) {
ArgAssert.notNull(baseType, "base type");
this.baseType = baseType;
}
/**
* Shortcut method for {@link #MessagingChannelConfig(Class)} constructor.
*
* @param baseType Base type of messages that can be transferred over this channel.
* @param Base type of messages that can be transferred over this channel.
*
* @return New instance.
*/
public static MessagingChannelConfig of(Class baseType) {
return new MessagingChannelConfig<>(baseType);
}
/**
* Shortcut method for {@link #MessagingChannelConfig(Class)} constructor to produce polyglot channels with {@link Object} base type.
*
* @return New instance.
*
* @see #MessagingChannelConfig(Class)
*/
public static MessagingChannelConfig