Package org.apache.cayenne.event
Class DefaultEventManager
java.lang.Object
org.apache.cayenne.event.DefaultEventManager
- All Implemented Interfaces:
- EventManager
public class DefaultEventManager extends Object implements EventManager
A default implementation of 
EventManager.- Since:
- 3.1
- 
Field SummaryFields Modifier and Type Field Description protected List<org.apache.cayenne.event.DefaultEventManager.Dispatch>eventQueueprotected booleansingleThreadprotected booleanstoppedprotected Map<EventSubject,org.apache.cayenne.event.DispatchQueue>subjects
- 
Constructor SummaryConstructors Constructor Description DefaultEventManager()Creates a multithreaded EventManager using default thread count.DefaultEventManager(int dispatchThreadCount)Creates an EventManager starting the specified number of threads for multithreaded dispatching.
- 
Method SummaryModifier and Type Method Description voidaddListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject)Register anEventListenerfor events sent by any sender.voidaddListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject, Object sender)Register anEventListenerfor events sent by a specific sender.protected voidaddListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject, Object sender, boolean blocking)voidaddNonBlockingListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject)voidaddNonBlockingListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject, Object sender)booleanisSingleThreaded()Returns true if this EventManager is single-threaded.booleanisStopped()Returns true if the EventManager was stopped viashutdown()method.voidpostEvent(EventObject event, EventSubject subject)Sends an event to all registered objects about a particular subject.voidpostNonBlockingEvent(EventObject event, EventSubject subject)Sends an event to all registered objects about a particular subject.booleanremoveAllListeners(EventSubject subject)Removes all listeners for a given subject.booleanremoveListener(Object listener)Unregister the specified listener from all event subjects handled by this manager instance.booleanremoveListener(Object listener, EventSubject subject)Unregister the specified listener for the events about the given subject.booleanremoveListener(Object listener, EventSubject subject, Object sender)Unregister the specified listener for the events about the given subject and the given sender.voidshutdown()Stops event threads.
- 
Field Details- 
subjects
- 
eventQueue
- 
singleThreadprotected boolean singleThread
- 
stoppedprotected volatile boolean stopped
 
- 
- 
Constructor Details- 
DefaultEventManagerpublic DefaultEventManager()Creates a multithreaded EventManager using default thread count.
- 
DefaultEventManagerpublic DefaultEventManager(int dispatchThreadCount)Creates an EventManager starting the specified number of threads for multithreaded dispatching. To create a single-threaded EventManager, use thread count of zero or less.
 
- 
- 
Method Details- 
isStoppedpublic boolean isStopped()Returns true if the EventManager was stopped viashutdown()method.- Since:
- 3.1
 
- 
isSingleThreadedpublic boolean isSingleThreaded()Returns true if this EventManager is single-threaded. If so it will throw an exception on any attempt to register an unblocking listener or dispatch a non-blocking event.- Specified by:
- isSingleThreadedin interface- EventManager
- Since:
- 1.2
 
- 
shutdownStops event threads. After the EventManager is stopped, it can not be restarted and should be discarded.- Since:
- 3.0
 
- 
addListenerpublic void addListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject)Register anEventListenerfor events sent by any sender.- Specified by:
- addListenerin interface- EventManager
- Throws:
- RuntimeException- if- methodNameis not found
- See Also:
- addListener(Object, String, Class, EventSubject, Object)
 
- 
addNonBlockingListenerpublic void addNonBlockingListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject)- Specified by:
- addNonBlockingListenerin interface- EventManager
 
- 
addListenerpublic void addListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject, Object sender)Register anEventListenerfor events sent by a specific sender.- Specified by:
- addListenerin interface- EventManager
- Parameters:
- listener- the object to be notified about events
- methodName- the name of the listener method to be invoked
- eventParameterClass- the class of the single event argument passed to- methodName
- subject- the event subject that the listener is interested in
- sender- the object whose events the listener is interested in;- nullmeans 'any sender'.
- Throws:
- RuntimeException- if- methodNameis not found
 
- 
addNonBlockingListenerpublic void addNonBlockingListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject, Object sender)- Specified by:
- addNonBlockingListenerin interface- EventManager
 
- 
addListenerprotected void addListener(Object listener, String methodName, Class<?> eventParameterClass, EventSubject subject, Object sender, boolean blocking)
- 
removeListenerUnregister the specified listener from all event subjects handled by this manager instance.- Specified by:
- removeListenerin interface- EventManager
- Parameters:
- listener- the object to be unregistered
- Returns:
- trueif- listenercould be removed for any existing subjects, else returns- false.
 
- 
removeAllListenersRemoves all listeners for a given subject.- Specified by:
- removeAllListenersin interface- EventManager
 
- 
removeListenerUnregister the specified listener for the events about the given subject.- Specified by:
- removeListenerin interface- EventManager
- Parameters:
- listener- the object to be unregistered
- subject- the subject from which the listener is to be unregistered
- Returns:
- trueif- listenercould be removed for the given subject, else returns- false.
 
- 
removeListenerUnregister the specified listener for the events about the given subject and the given sender.- Specified by:
- removeListenerin interface- EventManager
- Parameters:
- listener- the object to be unregistered
- subject- the subject from which the listener is to be unregistered
- sender- the object whose events the listener was interested in;- nullmeans 'any sender'.
- Returns:
- trueif- listenercould be removed for the given subject, else returns- false.
 
- 
postEventSends an event to all registered objects about a particular subject. Event is sent synchronously, so the sender thread is blocked until all the listeners finish processing the event.- Specified by:
- postEventin interface- EventManager
- Parameters:
- event- the event to be posted to the observers
- subject- the subject about which observers will be notified
- Throws:
- IllegalArgumentException- if event or subject are null
 
- 
postNonBlockingEventSends an event to all registered objects about a particular subject. Event is queued by EventManager, releasing the sender thread, and is later dispatched in a separate thread.- Specified by:
- postNonBlockingEventin interface- EventManager
- Parameters:
- event- the event to be posted to the observers
- subject- the subject about which observers will be notified
- Throws:
- IllegalArgumentException- if event or subject are null
- Since:
- 1.1
 
 
-