Class EventProducer

    • Field Detail

      • eventProducerImpl

        protected final EventProducerImpl eventProducerImpl
        The EventProducer helper class with the actual implementation to avoid code duplication.
    • Constructor Detail

      • EventProducer

        public EventProducer()
        Constructs a new EventProducer and checks for duplicate values in event types.
    • Method Detail

      • getSourceId

        public abstract Serializable getSourceId()
        Provide the sourceId that will be transmitted with the fired Event.
        Specified by:
        getSourceId in interface EventProducerInterface
        Returns:
        Serializable; the sourceId that will be transmitted with the fired Event
      • addListener

        public final boolean addListener​(EventListenerInterface listener,
                                         EventTypeInterface eventType)
        Add a listener as strong reference to the BEGINNING of a queue of listeners.
        Specified by:
        addListener in interface EventProducerInterface
        Parameters:
        listener - EventListenerInterface; the listener which is interested at events of eventType
        eventType - EventTypeInterface; the events of interest
        Returns:
        the success of adding the listener. If a listener was already added false is returned
      • addListener

        public final boolean addListener​(EventListenerInterface listener,
                                         EventTypeInterface eventType,
                                         ReferenceType referenceType)
        Add a listener to the BEGINNING of a queue of listeners.
        Specified by:
        addListener in interface EventProducerInterface
        Parameters:
        listener - EventListenerInterface; the listener which is interested at events of eventType
        eventType - EventTypeInterface; the events of interest
        referenceType - ReferenceType; whether the listener is added as a strong or as a weak reference
        Returns:
        the success of adding the listener. If a listener was already added false is returned
        See Also:
        WeakReference
      • addListener

        public final boolean addListener​(EventListenerInterface listener,
                                         EventTypeInterface eventType,
                                         int position)
        Add a listener as strong reference to the specified position of a queue of listeners.
        Specified by:
        addListener in interface EventProducerInterface
        Parameters:
        listener - EventListenerInterface; the listener which is interested at events of eventType
        eventType - EventTypeInterface; the events of interest
        position - int; the position of the listener in the queue
        Returns:
        the success of adding the listener. If a listener was already added, or an illegal position is provided false is returned
      • addListener

        public final boolean addListener​(EventListenerInterface listener,
                                         EventTypeInterface eventType,
                                         int position,
                                         ReferenceType referenceType)
        Add a listener to the specified position of a queue of listeners.
        Specified by:
        addListener in interface EventProducerInterface
        Parameters:
        listener - EventListenerInterface; which is interested at certain events
        eventType - EventTypeInterface; the events of interest
        position - int; the position of the listener in the queue
        referenceType - ReferenceType; whether the listener is added as a strong or as a weak reference
        Returns:
        the success of adding the listener. If a listener was already added or an illegal position is provided false is returned
        See Also:
        WeakReference
      • removeAllListeners

        protected int removeAllListeners()
        Remove all the listeners from this event producer.
        Returns:
        int; the number of removed event types
      • removeAllListeners

        protected int removeAllListeners​(Class<?> ofClass)
        Removes all the listeners of a class from this event producer.
        Parameters:
        ofClass - Class<?>; the class or superclass
        Returns:
        int; the number of removed listeners
      • removeListener

        public final boolean removeListener​(EventListenerInterface listener,
                                            EventTypeInterface eventType)
        Remove the subscription of a listener for a specific event.
        Specified by:
        removeListener in interface EventProducerInterface
        Parameters:
        listener - EventListenerInterface; which is no longer interested
        eventType - EventTypeInterface; the event which is of no interest any more
        Returns:
        the success of removing the listener. If a listener was not subscribed false is returned
      • hasListeners

        public boolean hasListeners()
        Return whether the EventProducer has listeners.
        Specified by:
        hasListeners in interface EventProducerInterface
        Returns:
        boolean; whether the EventProducer has listeners or not
      • numberOfListeners

        public int numberOfListeners​(EventTypeInterface eventType)
        Return the number of listeners for the provided EventTypeInterface.
        Specified by:
        numberOfListeners in interface EventProducerInterface
        Parameters:
        eventType - EventTypeInterface; the event type to return the number of listeners for
        Returns:
        boolean; whether the EventProducer has listeners or not
      • getEventTypesWithListeners

        public Set<EventTypeInterface> getEventTypesWithListeners()
        Return the EventTypeInterfaces for which the EventProducer has listeners.
        Specified by:
        getEventTypesWithListeners in interface EventProducerInterface
        Returns:
        Set<EventTypeInterface>; the EventTypeInterfaces for which the EventProducer has registered listeners
      • getListenerReferences

        protected List<Reference<EventListenerInterface>> getListenerReferences​(EventTypeInterface eventType)
        Return a safe copy of the list of (strong or weak) references to the registered listeners for the provided event type, or an empty list when nothing is registered for this event type. The method never returns a null pointer, so it is safe to use the result directly in an iterator. The references to the listeners are the original references, so not safe copies.
        Parameters:
        eventType - EventTypeInterface; the event type to look up the listeners for
        Returns:
        List<Reference<EventListenerInterface>>; the list of references to the listeners for this event type, or an empty list when the event type is not registered
      • fireEvent

        protected void fireEvent​(EventInterface event)
        Transmit an event to all interested listeners.
        Parameters:
        event - EventInterface; the event
      • fireTimedEvent

        protected <C extends Comparable<C> & Serializable> void fireTimedEvent​(TimedEventInterface<C> event)
        Transmit a timed event to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        event - TimedEventInterface<C>; the timed event
      • fireEvent

        protected Serializable fireEvent​(EventTypeInterface eventType,
                                         Serializable value)
        Transmit an event with a serializable object as payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - Serializable; the object sent with the event
        Returns:
        Serializable; the payload
      • fireEvent

        protected void fireEvent​(EventTypeInterface eventType)
        Transmit an event with no payload object to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
      • fireTimedEvent

        protected <C extends Comparable<C> & SerializableSerializable fireTimedEvent​(TimedEventTypeInterface eventType,
                                                                                       Serializable value,
                                                                                       C time)
        Transmit a time-stamped event with a Serializable object (payload) to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event.
        value - Serializable; the payload sent with the event
        time - C; a time stamp for the event
        Returns:
        Serializable; the payload
      • fireEvent

        protected byte fireEvent​(EventTypeInterface eventType,
                                 byte value)
        Transmit an event with a one byte payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - byte; the payload
        Returns:
        byte; the payload
      • fireTimedEvent

        protected <C extends Comparable<C> & Serializable> byte fireTimedEvent​(TimedEventTypeInterface eventType,
                                                                               byte value,
                                                                               C time)
        Transmit a time-stamped event with a one byte payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - byte; the payload
        time - C; a time stamp for the event
        Returns:
        byte; the payload
      • fireEvent

        protected char fireEvent​(EventTypeInterface eventType,
                                 char value)
        Transmit an event with a one char payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - char; the payload
        Returns:
        char; the payload
      • fireTimedEvent

        protected <C extends Comparable<C> & Serializable> char fireTimedEvent​(TimedEventTypeInterface eventType,
                                                                               char value,
                                                                               C time)
        Transmit a time-stamped event with a one char payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - char; the payload
        time - C; a time stamp for the event
        Returns:
        char; the payload
      • fireEvent

        protected boolean fireEvent​(EventTypeInterface eventType,
                                    boolean value)
        Transmit an event with a boolean payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - boolean; the payload
        Returns:
        boolean; the payload
      • fireTimedEvent

        protected <C extends Comparable<C> & Serializable> boolean fireTimedEvent​(TimedEventTypeInterface eventType,
                                                                                  boolean value,
                                                                                  C time)
        Transmit a time-stamped event with a boolean payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - boolean; the payload
        time - C; a time stamp for the event
        Returns:
        boolean; the payload
      • fireEvent

        protected double fireEvent​(EventTypeInterface eventType,
                                   double value)
        Transmit an event with a double value payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - double; the payload
        Returns:
        double; the payload
      • fireTimedEvent

        protected <C extends Comparable<C> & Serializable> double fireTimedEvent​(TimedEventTypeInterface eventType,
                                                                                 double value,
                                                                                 C time)
        Transmit a time-stamped event with a double value payload to interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - double; the payload
        time - C; a time stamp for the event
        Returns:
        double; the payload
      • fireEvent

        protected int fireEvent​(EventTypeInterface eventType,
                                int value)
        Transmit an event with an integer payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - int; the payload
        Returns:
        int; the payload
      • fireTimedEvent

        protected <C extends Comparable<C> & Serializable> int fireTimedEvent​(TimedEventTypeInterface eventType,
                                                                              int value,
                                                                              C time)
        Transmit a time-stamped event with an integer payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - int; the payload
        time - C; a time stamp for the event
        Returns:
        int; the payload
      • fireEvent

        protected long fireEvent​(EventTypeInterface eventType,
                                 long value)
        Transmit an event with a long payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - long; the payload
        Returns:
        long; the payload
      • fireTimedEvent

        protected <C extends Comparable<C> & Serializable> long fireTimedEvent​(TimedEventTypeInterface eventType,
                                                                               long value,
                                                                               C time)
        Transmit a time-stamped event with a long payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - long; the payload
        time - C; a time stamp for the event
        Returns:
        long; the payload
      • fireEvent

        protected short fireEvent​(EventTypeInterface eventType,
                                  short value)
        Transmit an event with a short payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - short; the payload
        Returns:
        short; the payload
      • fireTimedEvent

        protected <C extends Comparable<C> & Serializable> short fireTimedEvent​(TimedEventTypeInterface eventType,
                                                                                short value,
                                                                                C time)
        Transmit a time-stamped event with a short payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - short; the payload
        time - C; a time stamp for the event
        Returns:
        short; the payload
      • fireEvent

        protected float fireEvent​(EventTypeInterface eventType,
                                  float value)
        Transmit an event with a float payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - float; the payload
        Returns:
        float; the payload
      • fireTimedEvent

        protected <C extends Comparable<C> & Serializable> float fireTimedEvent​(TimedEventTypeInterface eventType,
                                                                                float value,
                                                                                C time)
        Transmit a time-stamped event with a float payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - float; the payload
        time - C; a time stamp for the event
        Returns:
        float; the payload
      • fireUnverifiedEvent

        protected void fireUnverifiedEvent​(EventInterface event)
        Transmit an event to all interested listeners.
        Parameters:
        event - EventInterface; the event
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> void fireUnverifiedTimedEvent​(TimedEventInterface<C> event)
        Transmit a timed event to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        event - TimedEventInterface<C>; the timed event
      • fireUnverifiedEvent

        protected Serializable fireUnverifiedEvent​(EventTypeInterface eventType,
                                                   Serializable value)
        Transmit an event that is not verified with a serializable object as payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - Serializable; the object sent with the event
        Returns:
        Serializable; the payload
      • fireUnverifiedEvent

        protected void fireUnverifiedEvent​(EventTypeInterface eventType)
        Transmit an event that is not verified with no payload object to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> void fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                         C time)
        Transmit a timed event that is not verified with no payload object to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        time - C; a time stamp for the event
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & SerializableSerializable fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                                 Serializable value,
                                                                                                 C time)
        Transmit a time-stamped event that is not verified with a Serializable object (payload) to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event.
        value - Serializable; the payload sent with the event
        time - C; a time stamp for the event
        Returns:
        Serializable; the payload
      • fireUnverifiedEvent

        protected byte fireUnverifiedEvent​(EventTypeInterface eventType,
                                           byte value)
        Transmit an event that is not verified with a one byte payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - byte; the payload
        Returns:
        byte; the payload
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> byte fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                         byte value,
                                                                                         C time)
        Transmit a time-stamped event that is not verified with a one byte payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - byte; the payload
        time - C; a time stamp for the event
        Returns:
        byte; the payload
      • fireUnverifiedEvent

        protected char fireUnverifiedEvent​(EventTypeInterface eventType,
                                           char value)
        Transmit an event that is not verified with a one char payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - char; the payload
        Returns:
        char; the payload
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> char fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                         char value,
                                                                                         C time)
        Transmit a time-stamped event that is not verified with a one char payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - char; the payload
        time - C; a time stamp for the event
        Returns:
        char; the payload
      • fireUnverifiedEvent

        protected boolean fireUnverifiedEvent​(EventTypeInterface eventType,
                                              boolean value)
        Transmit an event that is not verified with a boolean payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - boolean; the payload
        Returns:
        boolean; the payload
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> boolean fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                            boolean value,
                                                                                            C time)
        Transmit a time-stamped event that is not verified with a boolean payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - boolean; the payload
        time - C; a time stamp for the event
        Returns:
        boolean; the payload
      • fireUnverifiedEvent

        protected double fireUnverifiedEvent​(EventTypeInterface eventType,
                                             double value)
        Transmit an event that is not verified with a double value payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - double; the payload
        Returns:
        double; the payload
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> double fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                           double value,
                                                                                           C time)
        Transmit a time-stamped event that is not verified with a double value payload to interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - double; the payload
        time - C; a time stamp for the event
        Returns:
        double; the payload
      • fireUnverifiedEvent

        protected int fireUnverifiedEvent​(EventTypeInterface eventType,
                                          int value)
        Transmit an event that is not verified with an integer payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - int; the payload
        Returns:
        int; the payload
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> int fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                        int value,
                                                                                        C time)
        Transmit a time-stamped event that is not verified with an integer payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - int; the payload
        time - C; a time stamp for the event
        Returns:
        int; the payload
      • fireUnverifiedEvent

        protected long fireUnverifiedEvent​(EventTypeInterface eventType,
                                           long value)
        Transmit an event that is not verified with a long payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - long; the payload
        Returns:
        long; the payload
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> long fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                         long value,
                                                                                         C time)
        Transmit a time-stamped event that is not verified with a long payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - long; the payload
        time - C; a time stamp for the event
        Returns:
        long; the payload
      • fireUnverifiedEvent

        protected short fireUnverifiedEvent​(EventTypeInterface eventType,
                                            short value)
        Transmit an event that is not verified with a short payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - short; the payload
        Returns:
        short; the payload
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> short fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                          short value,
                                                                                          C time)
        Transmit a time-stamped event that is not verified with a short payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - short; the payload
        time - C; a time stamp for the event
        Returns:
        short; the payload
      • fireUnverifiedEvent

        protected float fireUnverifiedEvent​(EventTypeInterface eventType,
                                            float value)
        Transmit an event that is not verified with a float payload to all interested listeners.
        Parameters:
        eventType - EventTypeInterface; the eventType of the event
        value - float; the payload
        Returns:
        float; the payload
      • fireUnverifiedTimedEvent

        protected <C extends Comparable<C> & Serializable> float fireUnverifiedTimedEvent​(TimedEventTypeInterface eventType,
                                                                                          float value,
                                                                                          C time)
        Transmit a time-stamped event that is not verified with a float payload to all interested listeners.
        Type Parameters:
        C - the comparable type to indicate the time when the event is fired
        Parameters:
        eventType - TimedEventTypeInterface; the eventType of the event
        value - float; the payload
        time - C; a time stamp for the event
        Returns:
        float; the payload