Class MessageBus


  • public final class MessageBus
    extends java.lang.Object
    Provides support for basic intra-application message passing.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> void sendMessage​(T message)
      Sends a message to subscribed topic listeners.
      static <T> void subscribe​(java.lang.Class<? super T> topic, MessageBusListener<T> messageListener)
      Subscribes a listener to a message topic.
      static <T> void unsubscribe​(java.lang.Class<? super T> topic, MessageBusListener<T> messageListener)
      Unsubscribe a listener from a message topic.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • subscribe

        public static <T> void subscribe​(java.lang.Class<? super T> topic,
                                         MessageBusListener<T> messageListener)
        Subscribes a listener to a message topic.
        Type Parameters:
        T - The type of the topic.
        Parameters:
        topic - The topic class to subscribe to.
        messageListener - The listener we want to attach.
      • unsubscribe

        public static <T> void unsubscribe​(java.lang.Class<? super T> topic,
                                           MessageBusListener<T> messageListener)
        Unsubscribe a listener from a message topic.
        Type Parameters:
        T - The type of the topic.
        Parameters:
        topic - The topic class to subscribe to.
        messageListener - The listener to unsubscribe.
        Throws:
        java.lang.IllegalArgumentException - if there are no listeners subscribed.
      • sendMessage

        public static <T> void sendMessage​(T message)
        Sends a message to subscribed topic listeners.
        Type Parameters:
        T - The type of the topic.
        Parameters:
        message - The message to send to all subscribed listeners.