Interface MessageBus

All Known Implementing Classes:
SimpleMessageBus

public interface MessageBus
A simple message bus for a local publish/subscribe facility. The topic of a message is a class: a MessageBus.Listener subscribed to a topic receives the messages of that class and of its subclasses (or implementations, if the topic is an interface).
Author:
Fabrizio Giudici
  • Method Details

    • publish

      <T> void publish(@Nonnull T message)
      Publishes the given event. The topic is the class of the event.
      Type Parameters:
      T - the static type of the topic
      Parameters:
      message - the event
    • publish

      <T> void publish(@Nonnull Class<T> topic, @Nonnull T message)
      Publishes the given message and topic. Passing an explicit topic can be useful when dealing with a hierarchy of events (so, perhaps a subclass is passed but the topic is the root of the hierarchy).
      Type Parameters:
      T - the static type of the topic
      Parameters:
      topic - the topic
      message - the message
    • subscribe

      <T> void subscribe(@Nonnull Class<T> topic, @Nonnull MessageBus.Listener<T> listener)
      Subscribes a MessageBus.Listener to a topic.
      Type Parameters:
      T - the static type of the topic
      Parameters:
      topic - the topic
      listener - the listener
    • unsubscribe

      void unsubscribe(@Nonnull MessageBus.Listener<?> listener)
      Unsubscribes a MessageBus.Listener from all the topics it was subscribed to.
      Parameters:
      listener - the listener