Interface Notifier<T>

  • Type Parameters:
    T - The type of message.

    public interface Notifier<T>
    A Notifier is a hub that dispatches messages of various topics to TopicListeners. After a TopicListener has subscribed to a topic through the Notifier, a message can be published for that topic, and will be received by the TopicListener. A topic can be subscribed by multiple TopicListener, and a TopicListener can subscribe multiple topics.
    • Method Detail

      • publish

        boolean publish​(java.lang.String topic,
                        T message)
        Publishes a message for the specified topic. The TopicListeners 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 a TopicListener subscribe to a topic. After subscription, it will receive the messages published for the topic.
        Parameters:
        topic - The topic to subscribe.
        listener - The TopicListener who subscribes the topic.
      • unsubscribe

        void unsubscribe​(java.lang.String topic,
                         TopicListener<T> listener)
        Let a TopicListener unsubscribe from a topic, so it will no longer receive the messages for the topic.
        Parameters:
        topic - The topic to unsubscribe.
        listener - The TopicListener who unsubscribes the topic.