Interface NamedTopic<V>
- Type Parameters:
V
- the type of the topic values
- All Superinterfaces:
AutoCloseable
,NamedCollection
,Releasable
A topic may have any number of publishers
or subscribers
.
Subscriber
s subscribe directly to the topic or subscribe to a logical subscriber group
of the topic.
Each published value to a topic is delivered to all direct topic Subscriber
s and
each subscriber group of the topic. Each value of a subscriber group is only consumed by one subscriber group member
.
Thus, each subscriber group in effect behaves like a queue over the topic data.
Once published
, a value will be retained by the topic until it has either
expired or has been received
by all subscriber group(s)
and direct topic Subscriber
(s) which were registered prior to it being published.
The ordering of values within the topic is dependent on the Publisher.OrderBy
option.
Subscriber Group Lifecycle
A subscriber group is created either at configuration time or dynamically.
A subscriber-group child element of a topic-mapping element in a cache configuration file statically
configures a subscriber group when the topic is created, ensuring all values published to the
topic are also delivered to the statically configured subscriber group.
A subscriber group is created dynamically when a createSubscriber call
specifies a
subscriber group name using the option Subscriber.Name.of(String)
and the subscriber group does not exist on the NamedTopic
.
One must actively manage a NamedTopic's logical subscriber groups
since their life span
is independent of their active Subscriber
membership.
destroySubscriberGroup(String)
releases storage and stops accumulating topic values for a subscriber group.
To release storage resources for unconsumed values for a direct topic Subscriber
, it is sufficient to ensure it is closed
.
Both topic Publisher
and Subscriber
can be defined with the try-with-resource pattern to ensure their resources are
closed when no longer in scope.
- Since:
- Coherence 14.1.1
- Author:
- jf/jk/mf 2015.06.03
- See Also:
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A unit calculator is an object that can calculate the cost of storing an element in a topic.Nested classes/interfaces inherited from interface com.tangosol.net.NamedCollection
NamedCollection.Option
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The topic should have the default number of channels.static final long
The default capacity of pages when using the default binary calculator (1MB).static final Seconds
The default reconnect retry.static final Seconds
The default reconnect timeout.static final Seconds
The default reconnect wait.static final Seconds
The default subscriber timeout. -
Method Summary
Modifier and TypeMethodDescriptionCreate aPublisher
that can publish values into thisNamedTopic
.createPublisher
(Publisher.Option<? super V>... options) Create aPublisher
that can publish values into thisNamedTopic
.default Subscriber
<V> Create a directSubscriber
to the topic that receives all values from thisNamedTopic
.<U> Subscriber
<U> createSubscriber
(Subscriber.Option<? super V, U>... options) Create aSubscriber
that can receive values from thisNamedTopic
.void
destroySubscriberGroup
(String sGroup) Destroy thenamed
subscriber group for the associated topic.default void
ensureSubscriberGroup
(String sName) Ensure that the specified subscriber group exists for this topic.void
ensureSubscriberGroup
(String sGroup, Filter<?> filter, ValueExtractor<?, ?> extractor) Ensure that the specified subscriber group exists for this topic.int
Returns the number of channels that this topic has.default int
getRemainingMessages
(String sSubscriberGroup) Returns the number of remaining messages to be read from the topic for the specific subscriber group.int
getRemainingMessages
(String sSubscriberGroup, int... anChannel) Returns the number of remaining messages to be read from the topic for the specific subscriber group, and optionally for one or more specific channels.Return the set ofnamed
subscriber group(s) and statically configured subscriber-group(s).default TopicService
Return theTopicService
managing thisNamedTopic
.default boolean
Specifies whether this NamedTopic has been destroyed.default boolean
Specifies whether this NamedTopic has been released.Methods inherited from interface com.tangosol.net.NamedCollection
destroy, getName, getService
Methods inherited from interface com.tangosol.net.Releasable
close, isActive, release
-
Field Details
-
DEFAULT_CHANNEL_COUNT
static final int DEFAULT_CHANNEL_COUNTThe topic should have the default number of channels.- See Also:
-
DEFAULT_PAGE_CAPACITY_BYTES
static final long DEFAULT_PAGE_CAPACITY_BYTESThe default capacity of pages when using the default binary calculator (1MB).- See Also:
-
DEFAULT_SUBSCRIBER_TIMEOUT_SECONDS
The default subscriber timeout. -
DEFAULT_RECONNECT_TIMEOUT_SECONDS
The default reconnect timeout. -
DEFAULT_RECONNECT_RETRY_SECONDS
The default reconnect retry. -
DEFAULT_RECONNECT_WAIT_SECONDS
The default reconnect wait.
-
-
Method Details
-
createPublisher
Create aPublisher
that can publish values into thisNamedTopic
.- Parameters:
options
- thePublisher.Option
s controlling thePublisher
- Returns:
- a
Publisher
that can publish values into thisNamedTopic
-
createPublisher
Create aPublisher
that can publish values into thisNamedTopic
.- Returns:
- a
Publisher
that can publish values into thisNamedTopic
-
createSubscriber
Create aSubscriber
that can receive values from thisNamedTopic
.- Parameters:
options
- theSubscriber.Option
s controlling theSubscriber
- Returns:
- a
Subscriber
that can receive values from thisNamedTopic
-
createSubscriber
Create a directSubscriber
to the topic that receives all values from thisNamedTopic
.- Returns:
- a
Subscriber
that can receive values from thisNamedTopic
-
ensureSubscriberGroup
Ensure that the specified subscriber group exists for this topic.- Parameters:
sName
- the name of the subscriber group- Throws:
IllegalStateException
- if the subscriber group already exists with a different filter or converter function
-
ensureSubscriberGroup
Ensure that the specified subscriber group exists for this topic.- Parameters:
sGroup
- the name of the subscriber groupfilter
- theFilter
used to filter messages to be received by subscribers in the groupextractor
- theValueExtractor
used to convert messages to be received by subscribers in the group- Throws:
IllegalStateException
- if the subscriber group already exists with a different filter or converter extractor
-
destroySubscriberGroup
-
getSubscriberGroups
Return the set ofnamed
subscriber group(s) and statically configured subscriber-group(s).- Returns:
- the set of named subscriber groups.
-
isDestroyed
default boolean isDestroyed()Specifies whether this NamedTopic has been destroyed. Implementations must override this method to provide the necessary information.- Specified by:
isDestroyed
in interfaceNamedCollection
- Returns:
- true if the NamedTopic has been destroyed; false otherwise
-
isReleased
default boolean isReleased()Specifies whether this NamedTopic has been released. Implementations must override this method to provide the necessary information.- Specified by:
isReleased
in interfaceReleasable
- Returns:
- true if the NamedTopic has been released; false otherwise
-
getChannelCount
int getChannelCount()Returns the number of channels that this topic has.- Returns:
- the number of channels that this topic has
-
getRemainingMessages
Returns the number of remaining messages to be read from the topic for the specific subscriber group.This method is a sum of the remaining messages for each channel from the last committed message (exclusive) to the current tail. This result returned by this method is somewhat transient in situations where there are active Subscribers with in-flight commit requests, so the count may change just after the method returns. Message expiry may also affect the returned value, if messages expire after the count is returned.
- Parameters:
sSubscriberGroup
- the name of the subscriber group- Returns:
- the number of remaining messages for the subscriber group
-
getRemainingMessages
Returns the number of remaining messages to be read from the topic for the specific subscriber group, and optionally for one or more specific channels.This method is a sum of the remaining messages for each channel from the last committed message (exclusive) to the current tail. This result returned by this method is somewhat transient in situations where there are active Subscribers with in-flight commit requests, so the count may change just after the method returns. Message expiry may also affect the returned value, if messages expire after the count is returned.
- Parameters:
sSubscriberGroup
- the name of the subscriber groupanChannel
- one or more optional channels- Returns:
- the number of remaining messages for the subscriber group
-
getTopicService
Return theTopicService
managing thisNamedTopic
.- Returns:
- the
TopicService
managing thisNamedTopic
-