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
,KieBaseEventSupport
,ProcessEventSupport
,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 thegetEventListenersIterator 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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractEventSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEventListener(E listener)
Adds the specified listener to the list of listeners.void
clear()
List<E>
getEventListeners()
protected boolean
hasListeners()
<O> void
notifyAllListeners(O event, BiConsumer<E,O> consumer)
void
readExternal(ObjectInput in)
void
removeEventListener(E listener)
void
removeEventListener(Class cls)
Removes all event listeners of the specified class.void
writeExternal(ObjectOutput out)
-
-
-
Method Detail
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
notifyAllListeners
public <O> void notifyAllListeners(O event, BiConsumer<E,O> consumer)
-
hasListeners
protected boolean hasListeners()
-
addEventListener
public final void addEventListener(E listener)
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
public final void removeEventListener(Class cls)
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
public final void removeEventListener(E listener)
-
clear
public void clear()
-
-