Class ListenerSet<T extends @NonNull Object>
- java.lang.Object
-
- com.google.android.exoplayer2.util.ListenerSet<T>
-
- Type Parameters:
T
- The listener type.
public final class ListenerSet<T extends @NonNull Object> extends Object
A set of listeners.Events are guaranteed to arrive in the order in which they happened even if a new event is triggered recursively from another listener.
Events are also guaranteed to be only sent to the listeners registered at the time the event was enqueued and haven't been removed since.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ListenerSet.Event<T>
An event sent to a listener.static interface
ListenerSet.IterationFinishedEvent<T>
An event sent to a listener when all other events sent during oneLooper
message queue iteration were handled by the listener.
-
Constructor Summary
Constructors Constructor Description ListenerSet(Looper looper, Clock clock, ListenerSet.IterationFinishedEvent<T> iterationFinishedEvent)
Creates a new listener set.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(T listener)
Adds a listener to the set.void
clear()
Removes all listeners from the set.ListenerSet<T>
copy(Looper looper, Clock clock, ListenerSet.IterationFinishedEvent<T> iterationFinishedEvent)
Copies the listener set.ListenerSet<T>
copy(Looper looper, ListenerSet.IterationFinishedEvent<T> iterationFinishedEvent)
Copies the listener set.void
flushEvents()
Notifies listeners of events previously enqueued withqueueEvent(int, Event)
.void
queueEvent(int eventFlag, ListenerSet.Event<T> event)
Adds an event that is sent to the listeners whenflushEvents()
is called.void
release()
Releases the set of listeners immediately.void
remove(T listener)
Removes a listener from the set.void
sendEvent(int eventFlag, ListenerSet.Event<T> event)
int
size()
Returns the number of added listeners.
-
-
-
Constructor Detail
-
ListenerSet
public ListenerSet(Looper looper, Clock clock, ListenerSet.IterationFinishedEvent<T> iterationFinishedEvent)
Creates a new listener set.- Parameters:
looper
- ALooper
used to call listeners on. The sameLooper
must be used to call all other methods of this class.clock
- AClock
.iterationFinishedEvent
- AnListenerSet.IterationFinishedEvent
sent when all other events sent during oneLooper
message queue iteration were handled by the listeners.
-
-
Method Detail
-
copy
@CheckResult public ListenerSet<T> copy(Looper looper, ListenerSet.IterationFinishedEvent<T> iterationFinishedEvent)
Copies the listener set.- Parameters:
looper
- The newLooper
for the copied listener set.iterationFinishedEvent
- The newListenerSet.IterationFinishedEvent
sent when all other events sent during oneLooper
message queue iteration were handled by the listeners.- Returns:
- The copied listener set.
-
copy
@CheckResult public ListenerSet<T> copy(Looper looper, Clock clock, ListenerSet.IterationFinishedEvent<T> iterationFinishedEvent)
Copies the listener set.- Parameters:
looper
- The newLooper
for the copied listener set.clock
- The newClock
for the copied listener set.iterationFinishedEvent
- The newListenerSet.IterationFinishedEvent
sent when all other events sent during oneLooper
message queue iteration were handled by the listeners.- Returns:
- The copied listener set.
-
add
public void add(T listener)
Adds a listener to the set.If a listener is already present, it will not be added again.
- Parameters:
listener
- The listener to be added.
-
remove
public void remove(T listener)
Removes a listener from the set.If the listener is not present, nothing happens.
- Parameters:
listener
- The listener to be removed.
-
clear
public void clear()
Removes all listeners from the set.
-
size
public int size()
Returns the number of added listeners.
-
queueEvent
public void queueEvent(int eventFlag, ListenerSet.Event<T> event)
Adds an event that is sent to the listeners whenflushEvents()
is called.- Parameters:
eventFlag
- An integer indicating the type of the event, orC.INDEX_UNSET
to report this event without flag.event
- The event.
-
flushEvents
public void flushEvents()
Notifies listeners of events previously enqueued withqueueEvent(int, Event)
.
-
sendEvent
public void sendEvent(int eventFlag, ListenerSet.Event<T> event)
- Parameters:
eventFlag
- An integer flag indicating the type of the event, orC.INDEX_UNSET
to report this event without flag.event
- The event.
-
release
public void release()
Releases the set of listeners immediately.This will ensure no events are sent to any listener after this method has been called.
-
-