org.drools.event
Class AbstractEventSupport<E extends EventListener>

java.lang.Object
  extended by org.drools.event.AbstractEventSupport<E>
All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
AgendaEventSupport, KnowledgeAgentEventSupport, ProcessEventSupport, RuleBaseEventSupport, WorkingMemoryEventSupport

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:
Serialized Form

Constructor Summary
AbstractEventSupport()
           
 
Method Summary
 void addEventListener(E listener)
          Adds the specified listener to the list of listeners.
 void clear()
           
 List<E> getEventListeners()
           
protected  Iterator<E> getEventListenersIterator()
           
 boolean isEmpty()
           
 void readExternal(ObjectInput in)
           
 void removeEventListener(Class cls)
          Removes all event listeners of the specified class.
 void removeEventListener(E listener)
           
 int size()
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractEventSupport

public AbstractEventSupport()
Method Detail

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

getEventListenersIterator

protected final Iterator<E> getEventListenersIterator()

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)

getEventListeners

public List<E> getEventListeners()

size

public final int size()

isEmpty

public boolean isEmpty()

clear

public void clear()


Copyright © 2001-2012 JBoss by Red Hat. All Rights Reserved.