Package org.drools.core.event
Class AbstractEventSupport<E extends EventListener>
java.lang.Object
org.drools.core.event.AbstractEventSupport<E>
- All Implemented Interfaces:
Externalizable,Serializable
- Direct Known Subclasses:
AgendaEventSupport,RuleEventListenerSupport,RuleRuntimeEventSupport
public abstract class AbstractEventSupport<E extends EventListener>
extends Object
implements Externalizable
Base class for Thread-safe Event Support in Drools. Note that subclasses wishing to access
the listeners should do so via the getEventListenersIterator method. This
will provide an Iterator accessing the current snapshot of the underlying list, freeing the
subclasss of thread problems.
Please note that for lists of small sizes, and few modifications, the CopyOnWriteArrayList
provides best performance. If the list is modified more often, than a simple ArrayList
with synchonized operations, and copying of the array for iteration is faster.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddEventListener(E listener) Adds the specified listener to the list of listeners.voidclear()protected boolean<O> voidnotifyAllListeners(O event, BiConsumer<E, O> consumer) voidfinal voidremoveEventListener(E listener) final voidremoveEventListener(Class cls) Removes all event listeners of the specified class.void
-
Constructor Details
-
AbstractEventSupport
public AbstractEventSupport()
-
-
Method Details
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
notifyAllListeners
-
hasListeners
protected boolean hasListeners() -
addEventListener
Adds the specified listener to the list of listeners. Note that this method needs to be synchonized because it performs two independent operations on the underlying list- Parameters:
listener- to add
-
removeEventListener
Removes all event listeners of the specified class. Note that this method needs to be synchonized because it performs two independent operations on the underlying list- Parameters:
cls- class of listener to remove
-
removeEventListener
-
getEventListeners
-
clear
public void clear()
-