Interface EventProducerInterface

All Known Subinterfaces:
RemoteEventProducerInterface
All Known Implementing Classes:
EventProducer, EventProducerImpl, EventProducingCollection, EventProducingIterator, EventProducingList, EventProducingListIterator, EventProducingMap, EventProducingSet, RemoteEventProducer

public interface EventProducerInterface
The EventProducerInterface defines the registration operations of an event producer. This behavior includes adding and removing listeners for a specific event type. The EventListener and EventProducer together form a combination of the Publish-Subscribe design pattern and the Observer design pattern using the notify(event) method. See https://en.wikipedia.org/wiki/Publish-subscribe_pattern, https://en.wikipedia.org/wiki/Observer_pattern, and https://howtodoinjava.com/design-patterns/behavioral/observer-design-pattern/.

Copyright (c) 2002-2020 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. This class was originally part of the DSOL project, see https://simulation.tudelft.nl/dsol/manual.

Author:
Peter Jacobs , Alexander Verbraeck
  • Field Details

  • Method Details

    • getSourceId

      Serializable getSourceId() throws RemoteException
      Provide the sourceId that will be transmitted with the fired Event.
      Returns:
      Serializable; the sourceId that will be transmitted with the fired Event
      Throws:
      RemoteException - if a network failure occurs
    • addListener

      boolean addListener​(EventListenerInterface listener, EventType eventType) throws RemoteException
      Add a listener as strong reference to the BEGINNING of a queue of listeners.
      Parameters:
      listener - EventListenerInterface; the listener which is interested at events of eventType
      eventType - EventType; the events of interest
      Returns:
      the success of adding the listener. If a listener was already added false is returned
      Throws:
      RemoteException - If a network connection failure occurs.
    • addListener

      boolean addListener​(EventListenerInterface listener, EventType eventType, ReferenceType referenceType) throws RemoteException
      Add a listener to the BEGINNING of a queue of listeners.
      Parameters:
      listener - EventListenerInterface; the listener which is interested at events of eventType
      eventType - EventType; 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
      Throws:
      RemoteException - If a network connection failure occurs.
      See Also:
      WeakReference
    • addListener

      boolean addListener​(EventListenerInterface listener, EventType eventType, int position) throws RemoteException
      Add a listener as strong reference to the specified position of a queue of listeners.
      Parameters:
      listener - EventListenerInterface; the listener which is interested at events of eventType
      eventType - EventType; 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
      Throws:
      RemoteException - If a network connection failure occurs.
    • addListener

      boolean addListener​(EventListenerInterface listener, EventType eventType, int position, ReferenceType referenceType) throws RemoteException
      Add a listener to the specified position of a queue of listeners.
      Parameters:
      listener - EventListenerInterface; which is interested at certain events
      eventType - EventType; 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
      Throws:
      RemoteException - If a network connection failure occurs.
      See Also:
      WeakReference
    • removeListener

      boolean removeListener​(EventListenerInterface listener, EventType eventType) throws RemoteException
      Remove the subscription of a listener for a specific event.
      Parameters:
      listener - EventListenerInterface; which is no longer interested
      eventType - 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
      Throws:
      RemoteException - If a network connection failure occurs.
    • hasListeners

      boolean hasListeners() throws RemoteException
      Return whether the EventProducer has listeners.
      Returns:
      boolean; whether the EventProducer has listeners or not
      Throws:
      RemoteException - If a network connection failure occurs.
    • numberOfListeners

      int numberOfListeners​(EventType eventType) throws RemoteException
      Return the number of listeners for the provided EventType.
      Parameters:
      eventType - EventType; the event type to return the number of listeners for
      Returns:
      boolean; whether the EventProducer has listeners or not
      Throws:
      RemoteException - If a network connection failure occurs.
    • getEventTypesWithListeners

      Set<EventType> getEventTypesWithListeners() throws RemoteException
      Return the EventTypes for which the EventProducer has listeners.
      Returns:
      Set<EventType>; the EventTypes for which the EventProducer has registered listeners
      Throws:
      RemoteException - If a network connection failure occurs.