Class AbstractEventSupport<E extends java.util.EventListener>

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable
    Direct Known Subclasses:
    AgendaEventSupport, RuleEventListenerSupport, RuleRuntimeEventSupport

    public abstract class AbstractEventSupport<E extends java.util.EventListener>
    extends java.lang.Object
    implements java.io.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 Detail

      • AbstractEventSupport

        public AbstractEventSupport()
    • Method Detail

      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
      • notifyAllListeners

        public <O> void notifyAllListeners​(O event,
                                           java.util.function.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​(java.lang.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 java.util.List<E> getEventListeners()
      • clear

        public void clear()