org.apache.openjpa.lib.util.concurrent
Class AbstractConcurrentEventManager

java.lang.Object
  extended by org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
All Implemented Interfaces:
EventManager
Direct Known Subclasses:
AbstractDataCache, AbstractQueryCache, BrokerFactoryEventManager, JDBCEventConnectionDecorator, RemoteCommitEventManager, TransactionEventManager

public abstract class AbstractConcurrentEventManager
extends Object
implements EventManager

Base event manager that handles adding/removing listeners and firing events. Meant for high concurrency. This class is reentrant-safe; listeners can be added and removed by other listeners when they receive events. The changes will not be visible until the event fire that initiated the recursive sequence of calls completes, however.

Author:
Abe White

Field Summary
protected  Collection _listeners
           
 
Constructor Summary
AbstractConcurrentEventManager()
          Default constructor.
 
Method Summary
 void addListener(Object listener)
          Register an event listener.
 Exception[] fireEvent(Object event)
          Fire the given event to all listeners.
protected abstract  void fireEvent(Object event, Object listener)
          Implement this method to fire the given event to the given listener.
 Collection getListeners()
          Return a read-only list of listeners.
 boolean hasListener(Object listener)
          Return whether the given instance is in the list of listeners.
 boolean hasListeners()
          Return true if there are any registered listeners.
 boolean isFailFast()
          Whether to fail after the first exception thrown by any listener.
protected  Collection newListenerCollection()
          Return a new concurrent container for listeners.
 boolean removeListener(Object listener)
          Remove an event listener.
 void setFailFast(boolean failFast)
          Whether to fail after the first exception thrown by any listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_listeners

protected final Collection _listeners
Constructor Detail

AbstractConcurrentEventManager

public AbstractConcurrentEventManager()
Default constructor.

Method Detail

isFailFast

public boolean isFailFast()
Whether to fail after the first exception thrown by any listener.


setFailFast

public void setFailFast(boolean failFast)
Whether to fail after the first exception thrown by any listener.


addListener

public void addListener(Object listener)
Register an event listener.

Specified by:
addListener in interface EventManager

removeListener

public boolean removeListener(Object listener)
Remove an event listener.

Specified by:
removeListener in interface EventManager

hasListener

public boolean hasListener(Object listener)
Return whether the given instance is in the list of listeners.

Specified by:
hasListener in interface EventManager

hasListeners

public boolean hasListeners()
Return true if there are any registered listeners.

Specified by:
hasListeners in interface EventManager

getListeners

public Collection getListeners()
Return a read-only list of listeners.

Specified by:
getListeners in interface EventManager

fireEvent

public Exception[] fireEvent(Object event)
Fire the given event to all listeners.

Specified by:
fireEvent in interface EventManager

fireEvent

protected abstract void fireEvent(Object event,
                                  Object listener)
                           throws Exception
Implement this method to fire the given event to the given listener.

Throws:
Exception

newListenerCollection

protected Collection newListenerCollection()
Return a new concurrent container for listeners. Uses a CopyOnWriteArrayList by default.



Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.