Package org.djutils.event
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-2021 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 Summary
Fields Modifier and Type Field Description static int
FIRST_POSITION
The FIRST_POSITION in the queue.static int
LAST_POSITION
The LAST_POSITION in the queue.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
addListener(EventListenerInterface listener, EventTypeInterface eventType)
Add a listener as strong reference to the BEGINNING of a queue of listeners.boolean
addListener(EventListenerInterface listener, EventTypeInterface eventType, int position)
Add a listener as strong reference to the specified position of a queue of listeners.boolean
addListener(EventListenerInterface listener, EventTypeInterface eventType, int position, ReferenceType referenceType)
Add a listener to the specified position of a queue of listeners.boolean
addListener(EventListenerInterface listener, EventTypeInterface eventType, ReferenceType referenceType)
Add a listener to the BEGINNING of a queue of listeners.Set<EventTypeInterface>
getEventTypesWithListeners()
Return the EventTypeInterfaces for which the EventProducer has listeners.Serializable
getSourceId()
Provide the sourceId that will be transmitted with the fired Event.boolean
hasListeners()
Return whether the EventProducer has listeners.int
numberOfListeners(EventTypeInterface eventType)
Return the number of listeners for the provided EventTypeInterface.boolean
removeListener(EventListenerInterface listener, EventTypeInterface eventType)
Remove the subscription of a listener for a specific event.
-
-
-
Field Detail
-
FIRST_POSITION
static final int FIRST_POSITION
The FIRST_POSITION in the queue.- See Also:
- Constant Field Values
-
LAST_POSITION
static final int LAST_POSITION
The LAST_POSITION in the queue.- See Also:
- Constant Field Values
-
-
Method Detail
-
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, EventTypeInterface 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 eventTypeeventType
- EventTypeInterface; 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, EventTypeInterface 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 eventTypeeventType
- EventTypeInterface; the events of interestreferenceType
- 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, EventTypeInterface 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 eventTypeeventType
- EventTypeInterface; the events of interestposition
- 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, EventTypeInterface 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 eventseventType
- EventTypeInterface; the events of interestposition
- int; the position of the listener in the queuereferenceType
- 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, EventTypeInterface eventType) throws RemoteException
Remove the subscription of a listener for a specific event.- Parameters:
listener
- EventListenerInterface; which is no longer interestedeventType
- 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
- 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(EventTypeInterface eventType) throws RemoteException
Return the number of listeners for the provided EventTypeInterface.- Parameters:
eventType
- EventTypeInterface; 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<EventTypeInterface> getEventTypesWithListeners() throws RemoteException
Return the EventTypeInterfaces for which the EventProducer has listeners.- Returns:
- Set<EventTypeInterface>; the EventTypeInterfaces for which the EventProducer has registered listeners
- Throws:
RemoteException
- If a network connection failure occurs.
-
-