com.hazelcast.core
Interface ITopic<E>

All Superinterfaces:
DistributedObject
All Known Implementing Classes:
ClientTopicProxy, TopicProxy, TotalOrderedTopicProxy

public interface ITopic<E>
extends DistributedObject

Hazelcast provides distribution mechanism for publishing messages that are delivered to multiple subscribers, which is also known as a publish/subscribe (pub/sub) messaging model. Publish and subscriptions are cluster-wide. When a member subscribes for a topic, it is actually registering for messages published by any member in the cluster, including the new members joined after you added the listener.

Messages are ordered, meaning that listeners(subscribers) will process the messages in the order they are actually published. If cluster member M publishes messages m1, m2, m3...mn to a topic T, then Hazelcast makes sure that all of the subscribers of topic T will receive and process m1, m2, m3...mn in order.


Method Summary
 String addMessageListener(MessageListener<E> listener)
          Subscribes to this topic.
 LocalTopicStats getLocalTopicStats()
          Returns statistics about this topic, like total number of publishes/receives
 String getName()
          Returns the name of this ITopic instance
 void publish(E message)
          Publishes the message to all subscribers of this topic
 boolean removeMessageListener(String registrationId)
          Stops receiving messages for the given message listener.
 
Methods inherited from interface com.hazelcast.core.DistributedObject
destroy, getId, getPartitionKey, getServiceName
 

Method Detail

getName

String getName()
Returns the name of this ITopic instance

Specified by:
getName in interface DistributedObject
Returns:
name of this ITopic instance

publish

void publish(E message)
Publishes the message to all subscribers of this topic

Parameters:
message - the message to publish to all subscribers of this topic

addMessageListener

String addMessageListener(MessageListener<E> listener)
Subscribes to this topic. When someone publishes a message on this topic. onMessage() function of the given MessageListener is called. More than one message listener can be added on one instance.

Parameters:
listener -
Returns:
returns the registration id.

removeMessageListener

boolean removeMessageListener(String registrationId)
Stops receiving messages for the given message listener. If the given listener already removed, this method does nothing.

Parameters:
registrationId - Id of listener registration.
Returns:
true if registration is removed, false otherwise

getLocalTopicStats

LocalTopicStats getLocalTopicStats()
Returns statistics about this topic, like total number of publishes/receives

Returns:
statistics about this topic


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.