Package com.github.ambry.commons
Interface Notifier<T>
-
- Type Parameters:
T
- The type of message.
public interface Notifier<T>
ANotifier
is a hub that dispatches messages of various topics toTopicListener
s. After aTopicListener
has subscribed to a topic through theNotifier
, a message can be published for that topic, and will be received by theTopicListener
. A topic can be subscribed by multipleTopicListener
, and aTopicListener
can subscribe multiple topics.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
publish(java.lang.String topic, T message)
Publishes a message for the specified topic.void
subscribe(java.lang.String topic, TopicListener<T> listener)
Let aTopicListener
subscribe to a topic.void
unsubscribe(java.lang.String topic, TopicListener<T> listener)
Let aTopicListener
unsubscribe from a topic, so it will no longer receive the messages for the topic.
-
-
-
Method Detail
-
publish
boolean publish(java.lang.String topic, T message)
Publishes a message for the specified topic. TheTopicListener
s that have subscribed to the topic will receive the message.- Parameters:
topic
- The topic the message is sent for.message
- The message to send for the topic.- Returns:
true
if the message has been sent out successfully,false
otherwise.
-
subscribe
void subscribe(java.lang.String topic, TopicListener<T> listener)
Let aTopicListener
subscribe to a topic. After subscription, it will receive the messages published for the topic.- Parameters:
topic
- The topic to subscribe.listener
- TheTopicListener
who subscribes the topic.
-
unsubscribe
void unsubscribe(java.lang.String topic, TopicListener<T> listener)
Let aTopicListener
unsubscribe from a topic, so it will no longer receive the messages for the topic.- Parameters:
topic
- The topic to unsubscribe.listener
- TheTopicListener
who unsubscribes the topic.
-
-