Class EventProducerImpl

  • Direct Known Subclasses:
    DemandsModifier, DirectedGraphModifierImpl, GraphModifierImpl, PlanitComponentFactory, RoutedServicesLayerModifierImpl, ZoningModifierImpl

    public abstract class EventProducerImpl
    extends Object
    The EventProducer is the base class able to produce events. It provides protected methods to register listeners and remove listeners as well as ways to fire a generic event. Event producing classes should either extend this class to provide more user friendly public methods with the correct signatures that enforce the appropriate event and listener combinations suitable for that particular class while internally making use of this implementations functionality.
    Author:
    markr
    • Constructor Detail

      • EventProducerImpl

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

      • addListener

        protected final void addListener​(EventListener listener,
                                         EventListenerPriority priority)
        Add a listener for one or more event types (collected from listener's known supported types) that are presumably triggered by this producer
        Parameters:
        listener - to register
        priority - to apply for the combination of listener and event type(s)
      • addListener

        protected final void addListener​(EventListener listener,
                                         EventListenerPriority priority,
                                         EventType... eventTypes)
        Add a listener for one or more event types that are presumably triggered by this producer
        Parameters:
        listener - to register
        priority - to apply for the combination of listener and event type(s)
        eventTypes - to register the listener for
      • addListener

        protected final void addListener​(EventListener listener,
                                         EventType... eventTypes)
        Add a listener for one or more event types that are presumably triggered by this producer, with the default priority (low)
        Parameters:
        listener - to register
        eventTypes - to register the listener for
      • addListener

        protected final void addListener​(EventListener listener)
        add a listener for one or more event types that are presumably triggered by this producer absed on its known supported types. If no known types are not available the listener will not be added and a warning is issued
        Parameters:
        listener - to add
      • removeListener

        protected final boolean removeListener​(EventListener listener,
                                               EventType eventType)
        Remove a listener for a given event type
        Parameters:
        listener - to remove
        eventType - to remove it for
        Returns:
        true when succeeded, false otherwise
      • removeListener

        protected final boolean removeListener​(EventListener listener)
        Remove listener from all event types it is registered on
        Parameters:
        listener - to remove
        Returns:
        true when removed from one or more event types it was registered for, false otherwise
      • fireEvent

        protected abstract void fireEvent​(EventListener eventListener,
                                          Event event)
        Let derived class deal with the handling of the listener, where based on the derived event implementation the listener's concrete class can be determined which in turn allows for calling the right event callback method which is unknown at this base level since this event mechanism does not force a particular notification method signature on its listener interface
        Parameters:
        eventListener - to notify for the event
        event - to process for the listener
      • fireEvent

        protected void fireEvent​(Event event)
        Transmit an event to all interested listeners.
        Parameters:
        event - the event fired
      • removeAllListeners

        public void removeAllListeners()
        Remove all the listeners from this producer
      • hasListeners

        public boolean hasListeners()
        Verify if any listeners are available
        Returns:
        true when present, false otherwise
      • hasListener

        public boolean hasListener​(EventType eventType)
        Verify if one or more listeners are registered for given event type
        Parameters:
        eventType - to verify
        Returns:
        true when present, false otherwise
      • numberOfListeners

        public int numberOfListeners​(EventType eventType)
        Determine the number of listeners for a given event type
        Parameters:
        eventType - to check
        Returns:
        number of listeners
      • getEventTypesWithListeners

        public Set<EventType> getEventTypesWithListeners()
        Determine the event types have one or more listeners registered
        Returns:
        event types with listeners