com.stuffthathappens.classbus
Interface EventService

All Known Implementing Classes:
BasicEventService

public interface EventService

A publish/subscribe mechanism where multiple publishers can broadcast events to multiple subscribers without any direct connections between publishers and subscribers.

Author:
Eric M. Burke

Method Summary
<T> void
publish(java.lang.String channel, T event)
          Publish an event to a particular channel.
<T> void
publish(java.lang.String channel, T event, DeliveryCompleteCallback<T> callback)
          Publish an event to a particular channel, notifying a callback after delivery completes.
<T> void
publish(T event)
          Publish an event to the null channel.
<T> void
publish(T event, DeliveryCompleteCallback<T> callback)
          Publish an event to the null channel, notifying a callback after delivery completes.
<T> EventSubscriber<T>
subscribe(Matcher<java.lang.String> channelMatcher, Matcher<java.lang.Object> eventMatcher, EventSubscriber<T> subscriber)
          Register a subscriber that will be notified if the sent event matches both the channelMatcher and the eventMatcher.
<T> void
unsubscribe(EventSubscriber<T> subscriber)
          Completely remove the given subscriber from all channel and event matchers.
<T> void
unsubscribe(Matcher<java.lang.String> channelMatcher, Matcher<java.lang.Object> eventMatcher, EventSubscriber<T> subscriber)
          Remove a subscriber provided we find a matching channelMatcher and eventMatcher.
 

Method Detail

subscribe

<T> EventSubscriber<T> subscribe(Matcher<java.lang.String> channelMatcher,
                                 Matcher<java.lang.Object> eventMatcher,
                                 EventSubscriber<T> subscriber)
Register a subscriber that will be notified if the sent event matches both the channelMatcher and the eventMatcher.

Parameters:
channelMatcher - filters based on the event channel.
eventMatcher - filters based on the event object.
subscriber - will be notified of all events passing both channelMatcher and eventMatcher.
Returns:
a reference to the subscriber, useful if you pass an anonymous class and wish to hold a reference, thus preventing garbage collection since implementations generally use weak references.

unsubscribe

<T> void unsubscribe(Matcher<java.lang.String> channelMatcher,
                     Matcher<java.lang.Object> eventMatcher,
                     EventSubscriber<T> subscriber)
Remove a subscriber provided we find a matching channelMatcher and eventMatcher.

Parameters:
channelMatcher - the channel matcher to locate.
eventMatcher - the event matcher to locate.
subscriber - the subscriber to remove.

unsubscribe

<T> void unsubscribe(EventSubscriber<T> subscriber)
Completely remove the given subscriber from all channel and event matchers.

Parameters:
subscriber - the subscriber to remove.

publish

<T> void publish(T event)
Publish an event to the null channel.

Parameters:
event - the object to send to matching subscribers.
See Also:
EventSubscriber.onEvent(Object), publish(String, Object)

publish

<T> void publish(java.lang.String channel,
                 T event)
Publish an event to a particular channel.

Parameters:
channel - a String channel name (can be anything), or even null.
event - the object to send to matching subscribers.
See Also:
EventSubscriber.onEvent(Object), publish(Object)

publish

<T> void publish(T event,
                 DeliveryCompleteCallback<T> callback)
Publish an event to the null channel, notifying a callback after delivery completes.

Parameters:
event - the object to send to matching subscribers.
callback - the object to notify after delivery.
See Also:
EventSubscriber.onEvent(Object)

publish

<T> void publish(java.lang.String channel,
                 T event,
                 DeliveryCompleteCallback<T> callback)
Publish an event to a particular channel, notifying a callback after delivery completes.

Parameters:
channel - a String channel name (can be anything), or even null.
event - the object to send to matching subscribers.
callback - the object to notify after delivery.
See Also:
EventSubscriber.onEvent(Object)