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 for -
Listener
- the interface type of the listener
- Direct Known Subclasses:
-
ChannelBase
,Connection
A generic interface for event registration and delivery used in a number of the types in the Realtime client library.
For example, the
Connection
object emits events for connection state using the EventEmitter pattern.-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
void
Emits an event, calling registered listeners with the given event name and any other given arguments.void
off()
Deregisters all registrations, for all events and listeners.void
Removes all registrations that match both the specified listener and the specified event.void
Deregisters the specified listener.void
Registers the provided listener for the specified event.void
Registers the provided listener all events.void
Registers the provided listener for the first occurrence of a single named event specified as the Event argument.void
Registers the provided listener for the first event that is emitted.
-
Constructor Details
-
EventEmitter
public EventEmitter()
-
-
Method Details
-
off
public void off()Deregisters all registrations, for all events and listeners.Spec: RTE5
-
on
Registers the provided listener all events. If on() is called more than once with the same listener, the listener is only added once. Note: This is in deviation from the spec (see below).Spec: RTE4
- Parameters:
-
listener
- The event listener.This listener is invoked on a background thread.
-
once
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
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
Registers the provided listener for the specified event. If on() is called more than once with the same listener, even with a 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.This listener is invoked on a background thread.
-
once
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
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
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
-
apply
-