Class ReliableTopicConfig
- java.lang.Object
-
- com.hazelcast.config.ReliableTopicConfig
-
- All Implemented Interfaces:
NamedConfig
,DataSerializable
,IdentifiedDataSerializable
public class ReliableTopicConfig extends java.lang.Object implements IdentifiedDataSerializable, NamedConfig
Configuration for a reliableITopic
.The reliable topic makes use of a
Ringbuffer
to store the actual messages.To configure the ringbuffer for a reliable topic, define a ringbuffer in the config with exactly the same name. It is very unlikely that you want to run with the default settings.
When a ReliableTopic starts, it will always start from the
tail+1
item from the RingBuffer. It will not chew its way through all available events but it will wait for the next item being published.In the reliable topic, global order is always maintained, so all listeners will observe exactly the same order of sequence of messages.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_READ_BATCH_SIZE
The default read batch size.static boolean
DEFAULT_STATISTICS_ENABLED
Default value for statistics enabled.static TopicOverloadPolicy
DEFAULT_TOPIC_OVERLOAD_POLICY
The default slow consumer policy.
-
Constructor Summary
Constructors Constructor Description ReliableTopicConfig()
ReliableTopicConfig(ReliableTopicConfig config)
Creates a new ReliableTopicConfig by cloning an existing one.ReliableTopicConfig(java.lang.String name)
Creates a new ReliableTopicConfig with default settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ReliableTopicConfig
addMessageListenerConfig(ListenerConfig listenerConfig)
Adds a message listener (listens for when messages are added or removed) to this reliable topic.boolean
equals(java.lang.Object o)
int
getClassId()
Returns type identifier for this class.java.util.concurrent.Executor
getExecutor()
Gets the Executor that is going to process the events.int
getFactoryId()
Returns DataSerializableFactory factory ID for this class.java.util.List<ListenerConfig>
getMessageListenerConfigs()
Gets the list of message listeners (listens for when messages are added or removed) for this reliable topic.java.lang.String
getName()
Gets the name of the reliable topic.int
getReadBatchSize()
Gets the maximum number of items to read in a batch.TopicOverloadPolicy
getTopicOverloadPolicy()
Gets the TopicOverloadPolicy for this reliable topic.int
hashCode()
boolean
isStatisticsEnabled()
Checks if statistics are enabled for this reliable topic.void
readData(ObjectDataInput in)
Reads fields from the input streamReliableTopicConfig
setExecutor(java.util.concurrent.Executor executor)
Sets the executor that is going to process the event.ReliableTopicConfig
setMessageListenerConfigs(java.util.List<ListenerConfig> listenerConfigs)
Sets the list of message listeners (listens for when messages are added or removed) for this topic.ReliableTopicConfig
setName(java.lang.String name)
Sets the name of the reliable topic.ReliableTopicConfig
setReadBatchSize(int readBatchSize)
Sets the read batch size.ReliableTopicConfig
setStatisticsEnabled(boolean statisticsEnabled)
Enables or disables statistics for this reliable topic.ReliableTopicConfig
setTopicOverloadPolicy(TopicOverloadPolicy topicOverloadPolicy)
Sets the TopicOverloadPolicy for this reliable topic.java.lang.String
toString()
void
writeData(ObjectDataOutput out)
Writes object fields to output stream
-
-
-
Field Detail
-
DEFAULT_READ_BATCH_SIZE
public static final int DEFAULT_READ_BATCH_SIZE
The default read batch size.- See Also:
- Constant Field Values
-
DEFAULT_TOPIC_OVERLOAD_POLICY
public static final TopicOverloadPolicy DEFAULT_TOPIC_OVERLOAD_POLICY
The default slow consumer policy.
-
DEFAULT_STATISTICS_ENABLED
public static final boolean DEFAULT_STATISTICS_ENABLED
Default value for statistics enabled.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ReliableTopicConfig
public ReliableTopicConfig()
-
ReliableTopicConfig
public ReliableTopicConfig(java.lang.String name)
Creates a new ReliableTopicConfig with default settings.
-
ReliableTopicConfig
public ReliableTopicConfig(ReliableTopicConfig config)
Creates a new ReliableTopicConfig by cloning an existing one.- Parameters:
config
- the ReliableTopicConfig to clone
-
-
Method Detail
-
setName
public ReliableTopicConfig setName(java.lang.String name)
Sets the name of the reliable topic.- Specified by:
setName
in interfaceNamedConfig
- Parameters:
name
- the name of the reliable topic- Returns:
- the updated ReliableTopicConfig
- Throws:
java.lang.IllegalArgumentException
- if name isnull
-
getName
public java.lang.String getName()
Gets the name of the reliable topic.- Specified by:
getName
in interfaceNamedConfig
- Returns:
- the name of the reliable topic
-
getTopicOverloadPolicy
public TopicOverloadPolicy getTopicOverloadPolicy()
Gets the TopicOverloadPolicy for this reliable topic.- Returns:
- the TopicOverloadPolicy
-
setTopicOverloadPolicy
public ReliableTopicConfig setTopicOverloadPolicy(TopicOverloadPolicy topicOverloadPolicy)
Sets the TopicOverloadPolicy for this reliable topic. Check theTopicOverloadPolicy
for more details about this setting.- Parameters:
topicOverloadPolicy
- the new TopicOverloadPolicy- Returns:
- the updated reliable topic config
- Throws:
java.lang.IllegalArgumentException
- if topicOverloadPolicy isnull
-
getExecutor
public java.util.concurrent.Executor getExecutor()
Gets the Executor that is going to process the events.If no Executor is selected, then the
ExecutionService.ASYNC_EXECUTOR
is used.- Returns:
- the Executor used to process events
- See Also:
setExecutor(java.util.concurrent.Executor)
-
setExecutor
public ReliableTopicConfig setExecutor(java.util.concurrent.Executor executor)
Sets the executor that is going to process the event.In some cases it is desirable to set a specific executor. For example, you may want to isolate a certain topic from other topics because it contains long running messages or very high priority messages.
A single executor can be shared between multiple Reliable topics, although it could take more time to process a message. If a single executor is not shared with other reliable topics, then the executor only needs to have a single thread.
- Parameters:
executor
- the executor. if the executor is null, theExecutionService.ASYNC_EXECUTOR
will be used to process the event- Returns:
- the updated config
-
getReadBatchSize
public int getReadBatchSize()
Gets the maximum number of items to read in a batch. Returned value will always be equal or larger than 1.- Returns:
- the read batch size
-
setReadBatchSize
public ReliableTopicConfig setReadBatchSize(int readBatchSize)
Sets the read batch size.The ReliableTopic tries to read a batch of messages from the ringbuffer. It will get at least one, but if there are more available, then it will try to get more to increase throughput. The maximum read batch size can be influenced using the read batch size.
Apart from influencing the number of messages to retrieve, the
readBatchSize
also determines how many messages will be processed by the thread running theMessageListener
before it returns back to the pool to look for otherMessageListener
s that need to be processed. The problem with returning to the pool and looking for new work is that interacting with an executor is quite expensive due to contention on the work-queue. The more work that can be done without retuning to the pool, the smaller the overhead.If the
readBatchSize
is 10 and there are 50 messages available, 10 items are retrieved and processed consecutively before the thread goes back to the pool and helps out with the processing of other messages.If the
readBatchSize
is 10 and there are 2 items available, 2 items are retrieved and processed consecutively.If the
readBatchSize
is an issue because a thread will be busy too long with processing a singleMessageListener
and it can't help out otherMessageListener
s, increase the size of the threadpool so the otherMessageListener
s don't need to wait for a thread, but can be processed in parallel.- Parameters:
readBatchSize
- the maximum number of items to read in a batch- Returns:
- the updated reliable topic config
- Throws:
java.lang.IllegalArgumentException
- if thereadBatchSize
is smaller than 1
-
isStatisticsEnabled
public boolean isStatisticsEnabled()
Checks if statistics are enabled for this reliable topic.- Returns:
true
if enabled,false
otherwise
-
setStatisticsEnabled
public ReliableTopicConfig setStatisticsEnabled(boolean statisticsEnabled)
Enables or disables statistics for this reliable topic. Collects the creation time, total number of published and received messages for each member locally.- Parameters:
statisticsEnabled
-true
to enable statistics,false
to disable- Returns:
- the updated reliable topic config
-
setMessageListenerConfigs
public ReliableTopicConfig setMessageListenerConfigs(java.util.List<ListenerConfig> listenerConfigs)
Sets the list of message listeners (listens for when messages are added or removed) for this topic.- Parameters:
listenerConfigs
- the list of message listeners for this topic- Returns:
- this updated topic configuration
-
getMessageListenerConfigs
public java.util.List<ListenerConfig> getMessageListenerConfigs()
Gets the list of message listeners (listens for when messages are added or removed) for this reliable topic.- Returns:
- list of MessageListener configurations
-
addMessageListenerConfig
public ReliableTopicConfig addMessageListenerConfig(ListenerConfig listenerConfig)
Adds a message listener (listens for when messages are added or removed) to this reliable topic.- Parameters:
listenerConfig
- the ListenerConfig to add- Returns:
- the updated config
- Throws:
java.lang.NullPointerException
- if listenerConfig isnull
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getFactoryId
public int getFactoryId()
Description copied from interface:IdentifiedDataSerializable
Returns DataSerializableFactory factory ID for this class.- Specified by:
getFactoryId
in interfaceIdentifiedDataSerializable
- Returns:
- factory ID
-
getClassId
public int getClassId()
Description copied from interface:IdentifiedDataSerializable
Returns type identifier for this class. It should be unique per DataSerializableFactory.- Specified by:
getClassId
in interfaceIdentifiedDataSerializable
- Returns:
- type ID
-
writeData
public void writeData(ObjectDataOutput out) throws java.io.IOException
Description copied from interface:DataSerializable
Writes object fields to output stream- Specified by:
writeData
in interfaceDataSerializable
- Parameters:
out
- output- Throws:
java.io.IOException
- if an I/O error occurs. In particular, anIOException
may be thrown if the output stream has been closed.
-
readData
public void readData(ObjectDataInput in) throws java.io.IOException
Description copied from interface:DataSerializable
Reads fields from the input stream- Specified by:
readData
in interfaceDataSerializable
- Parameters:
in
- input- Throws:
java.io.IOException
- if an I/O error occurs. In particular, anIOException
may be thrown if the input stream has been closed.
-
equals
public final boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-