Class MessageBusHelper

java.lang.Object
it.tidalwave.messagebus.MessageBusHelper

public class MessageBusHelper extends Object
A helper for objects that receive messages by means of listener methods: methods with a single parameter annotated with ListensTo. It finds such methods in the classes of the hierarchy of the owner object that are annotated with SimpleMessageSubscriber, and subscribes or unsubscribes all of them at once. MessageBusHelper doesn't depend on a specific message bus: the actual subscription is performed by means of an MessageBusHelper.Adapter.
Author:
Fabrizio Giudici
  • Constructor Details

    • MessageBusHelper

      public MessageBusHelper()
  • Method Details

    • subscribeAll

      public void subscribeAll()
      Subscribes all the listener methods of the owner object: the methods with a single parameter annotated with ListensTo, declared in the classes of the hierarchy of the owner that are annotated with SimpleMessageSubscriber. Methods declared in classes that are not annotated are ignored.
    • unsubscribeAll

      public void unsubscribeAll()
      Unsubscribes all the listener methods subscribed by subscribeAll().
    • publish

      public void publish(@Nonnull Object message)
      Publishes a message. The topic is the class of the message.
      Parameters:
      message - the message to deliver
    • publish

      public <T> void publish(@Nonnull Class<T> topicType, @Nonnull T topic)
      Publishes a message with an explicit topic.
      Type Parameters:
      T - the static type of the topic
      Parameters:
      topicType - the topic
      topic - the message to deliver