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-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 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
Modifier and Type Method Description boolean
addListener(EventListenerInterface listener, EventType eventType)
Add a listener as strong reference to the BEGINNING of a queue of listeners.boolean
addListener(EventListenerInterface listener, EventType eventType, int position)
Add a listener as strong reference to the specified position of a queue of listeners.boolean
addListener(EventListenerInterface listener, EventType eventType, int position, ReferenceType referenceType)
Add a listener to the specified position of a queue of listeners.boolean
addListener(EventListenerInterface listener, EventType eventType, ReferenceType referenceType)
Add a listener to the BEGINNING of a queue of listeners.Set<EventType>
getEventTypesWithListeners()
Return the EventTypes 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(EventType eventType)
Return the number of listeners for the provided EventType.boolean
removeListener(EventListenerInterface listener, EventType eventType)
Remove the subscription of a listener for a specific event.
-
Field Details
-
FIRST_POSITION
static final int FIRST_POSITIONThe FIRST_POSITION in the queue.- See Also:
- Constant Field Values
-
LAST_POSITION
static final int LAST_POSITIONThe LAST_POSITION in the queue.- See Also:
- Constant Field Values
-
-
Method Details
-
getSourceId
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
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
- 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 RemoteExceptionAdd a listener to the BEGINNING of a queue of listeners.- Parameters:
listener
- EventListenerInterface; the listener which is interested at events of eventTypeeventType
- EventType; 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, EventType eventType, int position) throws RemoteExceptionAdd 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
- EventType; 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, EventType eventType, int position, ReferenceType referenceType) throws RemoteExceptionAdd a listener to the specified position of a queue of listeners.- Parameters:
listener
- EventListenerInterface; which is interested at certain eventseventType
- EventType; 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, EventType eventType) throws RemoteExceptionRemove the subscription of a listener for a specific event.- Parameters:
listener
- EventListenerInterface; which is no longer interestedeventType
- 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
Return whether the EventProducer has listeners.- Returns:
- boolean; whether the EventProducer has listeners or not
- Throws:
RemoteException
- If a network connection failure occurs.
-
numberOfListeners
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
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.
-