Class DefaultEventManager
java.lang.Object
org.apache.cayenne.event.DefaultEventManager
- All Implemented Interfaces:
EventManager
A default implementation of
EventManager.- Since:
- 3.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<org.apache.cayenne.event.DefaultEventManager.DispatchThread> protected final List<org.apache.cayenne.event.DefaultEventManager.Dispatch> protected final booleanprotected booleanprotected final Map<EventSubject, org.apache.cayenne.event.DispatchQueue> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a multithreaded EventManager using default thread count.DefaultEventManager(int dispatchThreadCount) Creates an EventManager starting the specified number of threads for multithreaded dispatching. -
Method Summary
Modifier and TypeMethodDescription<L, E extends EventObject>
voidaddListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject) Registers a listener for events sent by any sender.<L, E extends EventObject>
voidaddListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject, Object sender) Registers a listener for events sent by a specific sender.protected <L, E extends EventObject>
voidaddListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject, Object sender, boolean blocking) <L, E extends EventObject>
voidaddNonBlockingListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject) Registers a listener for events sent by any sender, to be notified on a dispatch thread instead of the thread that posted the event.<L, E extends EventObject>
voidaddNonBlockingListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject, Object sender) Registers a listener for events sent by a specific sender, to be notified on a dispatch thread instead of the thread that posted the event.booleanReturns true if this EventManager is single-threaded.booleanReturns 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
-
singleThread
protected final boolean singleThread -
dispatchThreads
-
stopped
protected volatile boolean stopped
-
-
Constructor Details
-
DefaultEventManager
public DefaultEventManager()Creates a multithreaded EventManager using default thread count. -
DefaultEventManager
public 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
-
isStopped
public boolean isStopped()Returns true if the EventManager was stopped viashutdown()method.- Since:
- 3.1
-
isSingleThreaded
public 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 interfaceEventManager- Since:
- 1.2
-
shutdown
@BeforeScopeEnd public void shutdown()Stops event threads. After the EventManager is stopped, it can not be restarted and should be discarded.- Since:
- 3.0
-
addListener
public <L, E extends EventObject> void addListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject) Description copied from interface:EventManagerRegisters a listener for events sent by any sender.- Specified by:
addListenerin interfaceEventManager- Parameters:
listener- the object to be notified about eventseventClass- the class of events the listener is interested in; events of other types are ignoredhandler- the callback invoked with the listener and the event, normally an unbound method referencesubject- the event subject that the listener is interested in
-
addNonBlockingListener
public <L, E extends EventObject> void addNonBlockingListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject) Description copied from interface:EventManagerRegisters a listener for events sent by any sender, to be notified on a dispatch thread instead of the thread that posted the event.- Specified by:
addNonBlockingListenerin interfaceEventManager- See Also:
-
addListener
public <L, E extends EventObject> void addListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject, Object sender) Description copied from interface:EventManagerRegisters a listener for events sent by a specific sender.- Specified by:
addListenerin interfaceEventManager- Parameters:
listener- the object to be notified about eventseventClass- the class of events the listener is interested in; events of other types are ignoredhandler- the callback invoked with the listener and the event, normally an unbound method referencesubject- the event subject that the listener is interested insender- the object whose events the listener is interested in; null means 'any sender'
-
addNonBlockingListener
public <L, E extends EventObject> void addNonBlockingListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject, Object sender) Description copied from interface:EventManagerRegisters a listener for events sent by a specific sender, to be notified on a dispatch thread instead of the thread that posted the event.- Specified by:
addNonBlockingListenerin interfaceEventManager
-
addListener
protected <L, E extends EventObject> void addListener(L listener, Class<E> eventClass, EventHandler<? super L, ? super E> handler, EventSubject subject, Object sender, boolean blocking) -
removeListener
Unregister the specified listener from all event subjects handled by this manager instance.- Specified by:
removeListenerin interfaceEventManager- Parameters:
listener- the object to be unregistered- Returns:
trueiflistenercould be removed for any existing subjects, else returnsfalse.
-
removeAllListeners
Removes all listeners for a given subject.- Specified by:
removeAllListenersin interfaceEventManager
-
removeListener
Unregister the specified listener for the events about the given subject.- Specified by:
removeListenerin interfaceEventManager- Parameters:
listener- the object to be unregisteredsubject- the subject from which the listener is to be unregistered- Returns:
trueiflistenercould be removed for the given subject, else returnsfalse.
-
removeListener
Unregister the specified listener for the events about the given subject and the given sender.- Specified by:
removeListenerin interfaceEventManager- Parameters:
listener- the object to be unregisteredsubject- the subject from which the listener is to be unregisteredsender- the object whose events the listener was interested in;nullmeans 'any sender'.- Returns:
trueiflistenercould be removed for the given subject, else returnsfalse.
-
postEvent
Sends 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 interfaceEventManager- Parameters:
event- the event to be posted to the observerssubject- the subject about which observers will be notified- Throws:
IllegalArgumentException- if event or subject are null
-
postNonBlockingEvent
Sends 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 interfaceEventManager- Parameters:
event- the event to be posted to the observerssubject- the subject about which observers will be notified- Throws:
IllegalArgumentException- if event or subject are null- Since:
- 1.1
-