Interface NamedTopic<V>
-
- Type Parameters:
V- the type of the topic values
- All Superinterfaces:
AutoCloseable,NamedCollection,Releasable
public interface NamedTopic<V> extends NamedCollection
NamedTopic represents a topic entity for publish/subscribe messaging.A topic may have any number of
publishersorsubscribers.Subscribers subscribe directly to the topic or subscribe to a logicalsubscriber groupof the topic. Each published value to a topic is delivered to all direct topicSubscribers and each subscriber group of the topic. Each value of a subscriber group is only consumed by onesubscriber 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 beenreceivedby allsubscriber group(s)and direct topicSubscriber(s) which were registered prior to it being published. The ordering of values within the topic is dependent on thePublisher.OrderByoption.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 acreateSubscriber callspecifies a subscriber group name using the optionSubscriber.Name.of(String)and the subscriber group does not exist on theNamedTopic.One must actively manage a
NamedTopic's logical subscriber groupssince their life span is independent of their activeSubscribermembership.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 isclosed. Both topicPublisherandSubscribercan 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:
Publisher,Subscriber
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceNamedTopic.ElementCalculatorA 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
Fields Modifier and Type Field Description static intDEFAULT_CHANNEL_COUNTThe topic should have the default number of channels.static longDEFAULT_PAGE_CAPACITY_BYTESThe default capacity of pages when using the default binary calculator (1MB).static SecondsDEFAULT_RECONNECT_RETRY_SECONDSThe default reconnect retry.static SecondsDEFAULT_RECONNECT_TIMEOUT_SECONDSThe default reconnect timeout.static SecondsDEFAULT_RECONNECT_WAIT_SECONDSThe default reconnect wait.static SecondsDEFAULT_SUBSCRIBER_TIMEOUT_SECONDSThe default subscriber timeout.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Publisher<V>createPublisher()Create aPublisherthat can publish values into thisNamedTopic.Publisher<V>createPublisher(Publisher.Option<? super V>... options)Create aPublisherthat can publish values into thisNamedTopic.default Subscriber<V>createSubscriber()Create a directSubscriberto the topic that receives all values from thisNamedTopic.<U> Subscriber<U>createSubscriber(Subscriber.Option<? super V,U>... options)Create aSubscriberthat can receive values from thisNamedTopic.voiddestroySubscriberGroup(String sGroup)Destroy thenamedsubscriber group for the associated topic.default voidensureSubscriberGroup(String sName)Ensure that the specified subscriber group exists for this topic.voidensureSubscriberGroup(String sGroup, Filter<?> filter, ValueExtractor<?,?> extractor)Ensure that the specified subscriber group exists for this topic.intgetChannelCount()Returns the number of channels that this topic has.default intgetRemainingMessages(String sSubscriberGroup)Returns the number of remaining messages to be read from the topic for the specific subscriber group.intgetRemainingMessages(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.Set<String>getSubscriberGroups()Return the set ofnamedsubscriber group(s) and statically configured subscriber-group(s).default TopicServicegetTopicService()Return theTopicServicemanaging thisNamedTopic.default booleanisDestroyed()Specifies whether this NamedTopic has been destroyed.default booleanisReleased()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 Detail
-
DEFAULT_CHANNEL_COUNT
static final int DEFAULT_CHANNEL_COUNT
The topic should have the default number of channels.- See Also:
- Constant Field Values
-
DEFAULT_PAGE_CAPACITY_BYTES
static final long DEFAULT_PAGE_CAPACITY_BYTES
The default capacity of pages when using the default binary calculator (1MB).- See Also:
- Constant Field Values
-
DEFAULT_SUBSCRIBER_TIMEOUT_SECONDS
static final Seconds DEFAULT_SUBSCRIBER_TIMEOUT_SECONDS
The default subscriber timeout.
-
DEFAULT_RECONNECT_TIMEOUT_SECONDS
static final Seconds DEFAULT_RECONNECT_TIMEOUT_SECONDS
The default reconnect timeout.
-
DEFAULT_RECONNECT_RETRY_SECONDS
static final Seconds DEFAULT_RECONNECT_RETRY_SECONDS
The default reconnect retry.
-
DEFAULT_RECONNECT_WAIT_SECONDS
static final Seconds DEFAULT_RECONNECT_WAIT_SECONDS
The default reconnect wait.
-
-
Method Detail
-
createPublisher
Publisher<V> createPublisher(Publisher.Option<? super V>... options)
Create aPublisherthat can publish values into thisNamedTopic.- Parameters:
options- thePublisher.Options controlling thePublisher- Returns:
- a
Publisherthat can publish values into thisNamedTopic
-
createPublisher
default Publisher<V> createPublisher()
Create aPublisherthat can publish values into thisNamedTopic.- Returns:
- a
Publisherthat can publish values into thisNamedTopic
-
createSubscriber
<U> Subscriber<U> createSubscriber(Subscriber.Option<? super V,U>... options)
Create aSubscriberthat can receive values from thisNamedTopic.- Parameters:
options- theSubscriber.Options controlling theSubscriber- Returns:
- a
Subscriberthat can receive values from thisNamedTopic
-
createSubscriber
default Subscriber<V> createSubscriber()
Create a directSubscriberto the topic that receives all values from thisNamedTopic.- Returns:
- a
Subscriberthat can receive values from thisNamedTopic
-
ensureSubscriberGroup
default void ensureSubscriberGroup(String sName)
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
void ensureSubscriberGroup(String sGroup, Filter<?> filter, ValueExtractor<?,?> extractor)
Ensure that the specified subscriber group exists for this topic.- Parameters:
sGroup- the name of the subscriber groupfilter- theFilterused to filter messages to be received by subscribers in the groupextractor- theValueExtractorused 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
void destroySubscriberGroup(String sGroup)
-
getSubscriberGroups
Set<String> getSubscriberGroups()
Return the set ofnamedsubscriber 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:
isDestroyedin 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:
isReleasedin 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
default int getRemainingMessages(String sSubscriberGroup)
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
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.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
default TopicService getTopicService()
Return theTopicServicemanaging thisNamedTopic.- Returns:
- the
TopicServicemanaging thisNamedTopic
-
-