-
public abstract class EventEmitter<Event, Listener>A generic interface for event registration and delivery used in a number of the types in the Realtime client library. For example, the io.ably.lib.realtime.Connection object emits events for connection state using the EventEmitter pattern.
-
-
Method Summary
Modifier and Type Method Description synchronized voidoff()Deregisters all registrations, for all events and listeners. synchronized voidon(Listener listener)Registers the provided listener all events.If on() is called more than once with the same listener, the listeneris only added once.Note: This is in deviation from the spec (see below). synchronized voidonce(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. synchronized voidoff(Listener listener)Deregisters the specified listener.Removes all registrations matching the given listener, regardless of whether they are associated with an event or not. synchronized voidon(Event event, Listener listener)Registers the provided listener for the specified event.If on() is called more than once with the same listener, even witha different event, the original listener is replaced.Note: This is in deviation from the spec (see below). synchronized voidonce(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. synchronized voidoff(Event event, Listener listener)Removes all registrations that match both the specified listener and the specified event. synchronized voidemit(Event event, Array<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. -
-
Method Detail
-
off
synchronized void off()
Deregisters all registrations, for all events and listeners.
Spec: RTE5
-
on
synchronized void on(Listener listener)
Registers the provided listener all events.If on() is called more than once with the same listener, the listeneris only added once.Note: This is in deviation from the spec (see below).
Spec: RTE4
- Parameters:
listener- The event listener.
-
once
synchronized 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.
-
off
synchronized 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
synchronized 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, even witha different event, the original listener is replaced.Note: This is in deviation from the spec (see below).
Spec: RTE4
- Parameters:
event- The named event to listen for.listener- The event listener.
-
once
synchronized 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:
event- The named event to listen for.listener- The event listener.
-
off
synchronized void off(Event event, Listener listener)
Removes all registrations that match both the specified listener and the specified event.
Spec: RTE5
- Parameters:
event- The named event.listener- The event listener.
-
emit
synchronized void emit(Event event, Array<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
-
-
-
-