Package io.ably.lib.util
Class EventEmitter<Event,Listener>
- java.lang.Object
-
- io.ably.lib.util.EventEmitter<Event,Listener>
-
- Type Parameters:
Event- an Enum containing the event names that listeners may be registered forListener- the interface type of the listener
- Direct Known Subclasses:
ChannelBase,Connection
public abstract class EventEmitter<Event,Listener> extends java.lang.ObjectA generic interface for event registration and delivery used in a number of the types in the Realtime client library. For example, theConnectionobject emits events for connection state using the EventEmitter pattern.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classEventEmitter.Filter
-
Constructor Summary
Constructors Constructor Description EventEmitter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidapply(Listener listener, Event event, java.lang.Object... args)voidemit(Event event, java.lang.Object... args)Emits an event, calling registered listeners with the given event name and any other given arguments.voidoff()Deregisters all registrations, for all events and listeners.voidoff(Event event, Listener listener)Removes all registrations that match both the specified listener and the specified event.voidoff(Listener listener)Deregisters the specified listener.voidon(Event event, Listener listener)Registers the provided listener for the specified event.voidon(Listener listener)Registers the provided listener all events.voidonce(Event event, Listener listener)Registers the provided listener for the first occurrence of a single named event specified as the Event argument.voidonce(Listener listener)Registers the provided listener for the first event that is emitted.
-
-
-
Method Detail
-
off
public void off()
Deregisters all registrations, for all events and listeners.Spec: RTE5
-
on
public void on(Listener listener)
Registers the provided listener all events. If on() is called more than once with the same listener and event, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice using on(), and an event is emitted once, the listener would be invoked twice.Spec: RTE4
- Parameters:
listener- The event listener.This listener is invoked on a background thread.
-
once
public void once(Listener listener)
Registers the provided listener for the first event that is emitted. If once() is called more than once with the same listener, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice using once(), and an event is emitted once, the listener would be invoked twice. However, all subsequent events emitted would not invoke the listener as once() ensures that each registration is only invoked once.Spec: RTE4
- Parameters:
listener- The event listener.This listener is invoked on a background thread.
-
off
public void off(Listener listener)
Deregisters the specified listener. Removes all registrations matching the given listener, regardless of whether they are associated with an event or not.Spec: RTE5
- Parameters:
listener- The event listener.
-
on
public void on(Event event, Listener listener)
Registers the provided listener for the specified event. If on() is called more than once with the same listener and event, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice using on(), and an event is emitted once, the listener would be invoked twice.Spec: RTE4
- Parameters:
event- The named event to listen for.listener- The event listener.This listener is invoked on a background thread.
-
once
public void once(Event event, Listener listener)
Registers the provided listener for the first occurrence of a single named event specified as the Event argument. If once() is called more than once with the same listener, the listener is added multiple times to its listener registry. Therefore, as an example, assuming the same listener is registered twice using once(), and an event is emitted once, the listener would be invoked twice. However, all subsequent events emitted would not invoke the listener as once() ensures that each registration is only invoked once.Spec: RTE4
- Parameters:
listener- The event listener.event- The named event to listen for.This listener is invoked on a background thread.
-
off
public void off(Event event, Listener listener)
Removes all registrations that match both the specified listener and the specified event.Spec: RTE5
- Parameters:
listener- The event listener.event- The named event.
-
emit
public void emit(Event event, java.lang.Object... args)
Emits an event, calling registered listeners with the given event name and any other given arguments. If an exception is raised in any of the listeners, the exception is caught by the EventEmitter and the exception is logged to the Ably logger.Spec: RTE5
- Parameters:
event- The named event.args- the arguments to pass to listeners
-
-