Class AbstractConcurrentEventManager
- java.lang.Object
-
- org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager
-
- All Implemented Interfaces:
java.io.Serializable,EventManager
- Direct Known Subclasses:
AbstractDataCache,AbstractQueryCache,BrokerFactoryEventManager,JDBCEventConnectionDecorator,RemoteCommitEventManager,TransactionEventManager
public abstract class AbstractConcurrentEventManager extends java.lang.Object implements EventManager, java.io.Serializable
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
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Collection_listeners
-
Constructor Summary
Constructors Constructor Description AbstractConcurrentEventManager()Default constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddListener(java.lang.Object listener)Register an event listener.java.lang.Exception[]fireEvent(java.lang.Object event)Fire the given event to all listeners.protected abstract voidfireEvent(java.lang.Object event, java.lang.Object listener)Implement this method to fire the given event to the given listener.java.util.CollectiongetListeners()Return a read-only list of listeners.booleanhasListener(java.lang.Object listener)Return whether the given instance is in the list of listeners.booleanhasListeners()Return true if there are any registered listeners.booleanisFailFast()Whether to fail after the first exception thrown by any listener.protected java.util.CollectionnewListenerCollection()Return a new concurrent container for listeners.booleanremoveListener(java.lang.Object listener)Remove an event listener.voidsetFailFast(boolean failFast)Whether to fail after the first exception thrown by any listener.
-
-
-
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(java.lang.Object listener)
Register an event listener.- Specified by:
addListenerin interfaceEventManager
-
removeListener
public boolean removeListener(java.lang.Object listener)
Remove an event listener.- Specified by:
removeListenerin interfaceEventManager
-
hasListener
public boolean hasListener(java.lang.Object listener)
Return whether the given instance is in the list of listeners.- Specified by:
hasListenerin interfaceEventManager
-
hasListeners
public boolean hasListeners()
Return true if there are any registered listeners.- Specified by:
hasListenersin interfaceEventManager
-
getListeners
public java.util.Collection getListeners()
Return a read-only list of listeners.- Specified by:
getListenersin interfaceEventManager
-
fireEvent
public java.lang.Exception[] fireEvent(java.lang.Object event)
Fire the given event to all listeners.- Specified by:
fireEventin interfaceEventManager
-
fireEvent
protected abstract void fireEvent(java.lang.Object event, java.lang.Object listener) throws java.lang.ExceptionImplement this method to fire the given event to the given listener.- Throws:
java.lang.Exception
-
newListenerCollection
protected java.util.Collection newListenerCollection()
Return a new concurrent container for listeners. Uses aCopyOnWriteArrayListby default.
-
-