Interface EventProducer

All Known Implementing Classes:
EventProducingCollection, EventProducingIterator, EventProducingList, EventProducingListIterator, EventProducingMap, EventProducingSet, LocalEventProducer, RmiEventProducer

public interface EventProducer
EventProducer is the interface that exposes a few of the methods of the implementation of an EventProducer to the outside world: the ability to add and remove listeners.

Copyright (c) 2022-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.

Author:
Alexander Verbraeck
  • Field Details

    • FIRST_POSITION

      static final int FIRST_POSITION
      The FIRST_POSITION in the queue.
      See Also:
    • LAST_POSITION

      static final int LAST_POSITION
      The LAST_POSITION in the queue.
      See Also:
  • Method Details

    • addListener

      default boolean addListener(EventListener listener, EventType eventType, int position, ReferenceType referenceType)
      Add a listener to the specified position of a queue of listeners.
      Parameters:
      listener - which is interested at certain events
      eventType - the events of interest
      position - the position of the listener in the queue
      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
    • addListener

      default boolean addListener(EventListener listener, EventType eventType)
      Add a listener as strong reference to the BEGINNING of a queue of listeners.
      Parameters:
      listener - the listener which is interested at events of eventType
      eventType - the events of interest
      Returns:
      the success of adding the listener. If a listener was already added false is returned
    • addListener

      default boolean addListener(EventListener listener, EventType eventType, ReferenceType referenceType)
      Add a listener to the BEGINNING of a queue of listeners.
      Parameters:
      listener - the listener which is interested at events of eventType
      eventType - the events of interest
      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:
    • addListener

      default boolean addListener(EventListener listener, EventType eventType, int position)
      Add a listener as strong reference to the specified position of a queue of listeners.
      Parameters:
      listener - the listener which is interested at events of eventType
      eventType - the events of interest
      position - 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
    • getEventListenerMap

      EventListenerMap getEventListenerMap()
      Return the map with the EventListener entries and the reference types.
      Returns:
      the map with the EventListener entries and the reference types
    • removeAllListeners

      default int removeAllListeners()
      Remove all the listeners from this event producer.
      Returns:
      the number of removed event types for which listeners existed
    • removeAllListeners

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

      default boolean removeListener(EventListener listener, EventType eventType)
      Remove the subscription of a listener for a specific event.
      Parameters:
      listener - which is no longer interested
      eventType - 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

      default boolean hasListeners()
      Return whether the EventProducer has listeners.
      Returns:
      whether the EventProducer has listeners or not
    • numberOfListeners

      default int numberOfListeners(EventType eventType)
      Return the number of listeners for the provided EventType.
      Parameters:
      eventType - the event type to return the number of listeners for
      Returns:
      whether the EventProducer has listeners or not
    • getListenerReferences

      default List<Reference<EventListener>> getListenerReferences(EventType 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 - the event type to look up the listeners for
      Returns:
      the list of references to the listeners for this event type, or an empty list when the event type is not registered
    • getEventTypesWithListeners

      default Set<EventType> getEventTypesWithListeners()
      Return the EventTypes for which the EventProducer has listeners.
      Returns:
      the EventTypes for which the EventProducer has registered listeners
    • fireEvent

      default void fireEvent(Event event)
      Transmit an event to all subscribed listeners.
      Parameters:
      event - the event
    • fireTimedEvent

      default <C extends Comparable<C>> void fireTimedEvent(TimedEvent<C> event)
      Transmit a time-stamped event to all interested listeners.
      Type Parameters:
      C - the comparable type to indicate the time when the event is fired
      Parameters:
      event - the event
    • fireEvent

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

      default <C extends Comparable<C>> void fireTimedEvent(EventType eventType, C time)
      Transmit a time-stamped event with a no payload object to all interested listeners.
      Type Parameters:
      C - the comparable type to indicate the time when the event is fired
      Parameters:
      eventType - the eventType of the event.
      time - a time stamp for the event
    • fireEvent

      default void fireEvent(EventType eventType, Object value)
      Transmit an event with an object as payload to all interested listeners.
      Parameters:
      eventType - the eventType of the event
      value - the object sent with the event
    • fireTimedEvent

      default <C extends Comparable<C>> void fireTimedEvent(EventType eventType, Object value, C time)
      Transmit a time-stamped event with an object (payload) to all interested listeners.
      Type Parameters:
      C - the comparable type to indicate the time when the event is fired
      Parameters:
      eventType - the eventType of the event.
      value - the payload sent with the event
      time - a time stamp for the event
    • fireUnverifiedEvent

      default void fireUnverifiedEvent(EventType eventType)
      Transmit an event with no payload object to all interested listeners.
      Parameters:
      eventType - the eventType of the event
    • fireUnverifiedTimedEvent

      default <C extends Comparable<C>> void fireUnverifiedTimedEvent(EventType eventType, C time)
      Transmit a time-stamped event without a payload object to all interested listeners.
      Type Parameters:
      C - the comparable type to indicate the time when the event is fired
      Parameters:
      eventType - the eventType of the event.
      time - a time stamp for the event
    • fireUnverifiedEvent

      default void fireUnverifiedEvent(EventType eventType, Object value)
      Transmit an event with an object as payload to all interested listeners.
      Parameters:
      eventType - the eventType of the event
      value - the object sent with the event
    • fireUnverifiedTimedEvent

      default <C extends Comparable<C>> void fireUnverifiedTimedEvent(EventType eventType, Object value, C time)
      Transmit a time-stamped event with an object (payload) to all interested listeners.
      Type Parameters:
      C - the comparable type to indicate the time when the event is fired
      Parameters:
      eventType - the eventType of the event.
      value - the payload sent with the event
      time - a time stamp for the event