java.lang.Object
it.tidalwave.messagebus.MessageBusHelper
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAn adapter betweenMessageBusHelperand a specific message bus.static interfaceThe binding of a listener method to a message bus, which can subscribe and unsubscribe it. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> voidPublishes a message with an explicit topic.voidPublishes a message.voidSubscribes all the listener methods of the owner object: the methods with a single parameter annotated withListensTo, declared in the classes of the hierarchy of the owner that are annotated withSimpleMessageSubscriber.voidUnsubscribes all the listener methods subscribed bysubscribeAll().
-
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 withListensTo, declared in the classes of the hierarchy of the owner that are annotated withSimpleMessageSubscriber. Methods declared in classes that are not annotated are ignored. -
unsubscribeAll
public void unsubscribeAll()Unsubscribes all the listener methods subscribed bysubscribeAll(). -
publish
Publishes a message. The topic is the class of the message.- Parameters:
message- the message to deliver
-
publish
Publishes a message with an explicit topic.- Type Parameters:
T- the static type of the topic- Parameters:
topicType- the topictopic- the message to deliver
-