org.sonatype.sisu.goodies.eventbus.internal.guava
Class AsyncEventBus

java.lang.Object
  extended by org.sonatype.sisu.goodies.eventbus.internal.guava.EventBus
      extended by org.sonatype.sisu.goodies.eventbus.internal.guava.AsyncEventBus

@Beta
public class AsyncEventBus
extends EventBus

An EventBus that takes the Executor of your choice and uses it to dispatch events, allowing dispatch to occur asynchronously.

Since:
10.0
Author:
Cliff Biffle

Nested Class Summary
 
Nested classes/interfaces inherited from class org.sonatype.sisu.goodies.eventbus.internal.guava.EventBus
EventBus.EventWithHandler
 
Constructor Summary
AsyncEventBus(Executor executor)
          Creates a new AsyncEventBus that will use executor to dispatch events.
AsyncEventBus(String identifier, Executor executor)
          Creates a new AsyncEventBus that will use executor to dispatch events.
 
Method Summary
protected  void dispatch(Object event, EventHandler handler)
          Calls the executor to dispatch event to handler.
protected  void dispatchQueuedEvents()
          Dispatch events in the order they were posted, regardless of the posting thread.
protected  void enqueueEvent(Object event, EventHandler handler)
          Queue the event for dispatch during EventBus.dispatchQueuedEvents().
 
Methods inherited from class org.sonatype.sisu.goodies.eventbus.internal.guava.EventBus
newHandlerSet, post, register, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncEventBus

public AsyncEventBus(String identifier,
                     Executor executor)
Creates a new AsyncEventBus that will use executor to dispatch events. Assigns identifier as the bus's name for logging purposes.

Parameters:
identifier - short name for the bus, for logging purposes.
executor - Executor to use to dispatch events. It is the caller's responsibility to shut down the executor after the last event has been posted to this event bus.

AsyncEventBus

public AsyncEventBus(Executor executor)
Creates a new AsyncEventBus that will use executor to dispatch events.

Parameters:
executor - Executor to use to dispatch events. It is the caller's responsibility to shut down the executor after the last event has been posted to this event bus.
Method Detail

enqueueEvent

protected void enqueueEvent(Object event,
                            EventHandler handler)
Description copied from class: EventBus
Queue the event for dispatch during EventBus.dispatchQueuedEvents(). Events are queued in-order of occurrence so they can be dispatched in the same order.

Overrides:
enqueueEvent in class EventBus

dispatchQueuedEvents

protected void dispatchQueuedEvents()
Dispatch events in the order they were posted, regardless of the posting thread.

Overrides:
dispatchQueuedEvents in class EventBus

dispatch

protected void dispatch(Object event,
                        EventHandler handler)
Calls the executor to dispatch event to handler.

Overrides:
dispatch in class EventBus
Parameters:
event - event to dispatch.
handler - wrapper that will call the handler.


Copyright © 2008-2012 Sonatype, Inc.. All Rights Reserved.