Package 

Class EventEmitter


  • 
    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 void off() Deregisters all registrations, for all events and listeners.
      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).
      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.
      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.
      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).
      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.
      synchronized void off(Event event, Listener listener) Removes all registrations that match both the specified listener and the specified event.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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