com.stuffthathappens.classbus
Class EdtDeliveryStrategy

java.lang.Object
  extended by com.stuffthathappens.classbus.EdtDeliveryStrategy
All Implemented Interfaces:
DeliveryStrategy

public class EdtDeliveryStrategy
extends java.lang.Object
implements DeliveryStrategy

An event delivery strategy that ensures EventSubscribers are only notified on the Swing Event Dispatch Thread (EDT). If the sender is already on the EDT, events are simply passed through. Otherwise this implementation uses SwingUtilities.invokeLater(...) to deliver the events.

Author:
Eric M. Burke

Constructor Summary
EdtDeliveryStrategy()
           
 
Method Summary
<T> void
publishTo(java.lang.Iterable<EventSubscriber<T>> subscribers, T event, DeliveryCompleteCallback<T> callback)
          Iterate over the given collection of subscribers, calling EventSubscriber.onEvent(Object) on each subscriber.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EdtDeliveryStrategy

public EdtDeliveryStrategy()
Method Detail

publishTo

public <T> void publishTo(java.lang.Iterable<EventSubscriber<T>> subscribers,
                          T event,
                          DeliveryCompleteCallback<T> callback)
Description copied from interface: DeliveryStrategy
Iterate over the given collection of subscribers, calling EventSubscriber.onEvent(Object) on each subscriber. This may spawn a new thread, depending on the implementation.

The callback is optional. If null, it is ignored.

Specified by:
publishTo in interface DeliveryStrategy
Parameters:
subscribers - the subscribers to notify.
event - the object to send.
callback - an optional callback to notify upon completion.
See Also:
EventSubscriber.onEvent(Object)