com.stuffthathappens.classbus
Class BasicEventService

java.lang.Object
  extended by com.stuffthathappens.classbus.BasicEventService
All Implemented Interfaces:
EventService

public class BasicEventService
extends java.lang.Object
implements EventService

The default implementation of EventService. This provides weak references to subscribers and thread-safe subscription/notification.

Author:
Eric M. Burke

Constructor Summary
BasicEventService(DeliveryStrategy deliveryStrategy)
          Construct a new instance.
 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicEventService

public BasicEventService(DeliveryStrategy deliveryStrategy)
Construct a new instance.

Parameters:
deliveryStrategy - defines how threads are used during event delivery.
Method Detail

subscribe

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

Specified by:
subscribe in interface EventService
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

public <T> void unsubscribe(Matcher<java.lang.String> channelMatcher,
                            Matcher<java.lang.Object> eventMatcher,
                            EventSubscriber<T> subscriber)
Description copied from interface: EventService
Remove a subscriber provided we find a matching channelMatcher and eventMatcher.

Specified by:
unsubscribe in interface EventService
Parameters:
channelMatcher - the channel matcher to locate.
eventMatcher - the event matcher to locate.
subscriber - the subscriber to remove.

unsubscribe

public <T> void unsubscribe(EventSubscriber<T> subscriber)
Description copied from interface: EventService
Completely remove the given subscriber from all channel and event matchers.

Specified by:
unsubscribe in interface EventService
Parameters:
subscriber - the subscriber to remove.

publish

public <T> void publish(T event)
Description copied from interface: EventService
Publish an event to the null channel.

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

publish

public <T> void publish(java.lang.String channel,
                        T event)
Description copied from interface: EventService
Publish an event to a particular channel.

Specified by:
publish in interface EventService
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), EventService.publish(Object)

publish

public <T> void publish(T event,
                        DeliveryCompleteCallback<T> callback)
Description copied from interface: EventService
Publish an event to the null channel, notifying a callback after delivery completes.

Specified by:
publish in interface EventService
Parameters:
event - the object to send to matching subscribers.
callback - the object to notify after delivery.
See Also:
EventSubscriber.onEvent(Object)

publish

public <T> void publish(java.lang.String channel,
                        T event,
                        DeliveryCompleteCallback<T> callback)
Description copied from interface: EventService
Publish an event to a particular channel, notifying a callback after delivery completes.

Specified by:
publish in interface EventService
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)