com.brightcove.player.event

## Class EventEmitterImpl

- java.lang.Object
- - com.brightcove.player.event.EventEmitterImpl

- All Implemented Interfaces:
    EventEmitter

      public class EventEmitterImpl
      extends java.lang.Object
      implements EventEmitter

  The 'Main' implementation of EventEmitter. Most Components should use this, as should RegisteringEventEmitter.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected android.os.Handler` | `handler`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `EventEmitterImpl()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `disable()` Disables listener registration and event emitting.
    `void` | `emit(java.lang.String eventType)` Emits an event.
    `void` | `emit(java.lang.String eventType, java.util.Map<java.lang.String,java.lang.Object> properties)` Emits an event, passing along the properties map
    `void` | `enable()` Enables listener registration and event emitting.
    `protected com.brightcove.player.event.InvocationContainer` | `getInvocationContainerByToken(java.util.List<com.brightcove.player.event.InvocationContainer> invocations, int token)` Returns the InvocationContainer in a list of Containers which matches the token
    `protected int` | `getInvocationContainerPositionByToken(java.util.List<com.brightcove.player.event.InvocationContainer> invocations, int token)` Returns the position of an invocationContainer
    `void` | `off()` Removes all listeners.
    `void` | `off(java.lang.String eventType, int token)` Removes a listener from an event queue, using the token as a reference
    `int` | `on(java.lang.String eventType, EventListener listener)` Adds the listener to the event queue, returns a token that the caller can use to off itself.
    `int` | `once(java.lang.String eventType, EventListener listener)` Similar to on, except that the listener is removed after processing one event.
    `void` | `request(java.lang.String eventType, EventListener listener)` Attaches a listener and fires off an event of eventType, with the hope that there's a corresponding listener set to 'respond' to the listener specified in the request.
    `void` | `request(java.lang.String eventType, java.util.Map<java.lang.String,java.lang.Object> properties, EventListener listener)` Similar to above, except the properties map is passed along
    `void` | `respond(Event event)` Convenience method to save the user from typing event.properties when responding
    `void` | `respond(java.util.Map<java.lang.String,java.lang.Object> properties)` Meant to respond to a request event.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### handler

          protected android.os.Handler handler

  - ### Constructor Detail

    - #### EventEmitterImpl

          public EventEmitterImpl()

  - ### Method Detail

    - #### on

          public int on(java.lang.String eventType,
                        EventListener listener)

      Adds the listener to the event queue, returns a token that the caller can use to off itself. Calls to on are stored in the order they arrive, which means that during event propagation, the listeners will be executed in the order they were added.
      Specified by:
        `on` in interface `EventEmitter`
      Parameters:
        `eventType` - A String representing the Event to be listened for
        `listener` - An abstract class of EventListener, that contains a method to process during an Event's firing
      Returns:
        token An integer representing the id token of the listener. Objects that invoke this method should cache the token, which is used as a reference to remove a Listener
      See Also:
        `EventListener`, `EventEmitter.on(String, com.brightcove.player.event.EventListener)`

    - #### once

          public int once(java.lang.String eventType,
                          EventListener listener)

      Similar to on, except that the listener is removed after processing one event.
      Specified by:
        `once` in interface `EventEmitter`
      Parameters:
        `eventType` - Same as for 'on'; a string representing the event to be listened for
        `listener` - Subclass of EventListener
      Returns:
        token
      See Also:
        `EventListener`, `EventEmitter.once(String, com.brightcove.player.event.EventListener)`

    - #### off

          public void off()

      Removes all listeners.
      Specified by:
        `off` in interface `EventEmitter`

    - #### off

          public void off(java.lang.String eventType,
                          int token)

      Removes a listener from an event queue, using the token as a reference
      Specified by:
        `off` in interface `EventEmitter`
      Parameters:
        `eventType` - A string representing the Event type
        `token` - Integer-valued token that was created during 'on'
      See Also:
        `EventEmitter.off(String, int)`

    - #### emit

          public void emit(java.lang.String eventType)

      Emits an event. All listeners attached to this event will be processed
      Specified by:
        `emit` in interface `EventEmitter`
      Parameters:
        `eventType` -
      See Also:
        `EventEmitter.emit(String)`

    - #### emit

          public void emit(java.lang.String eventType,
                           java.util.Map<java.lang.String,java.lang.Object> properties)

      Emits an event, passing along the properties map
      Specified by:
        `emit` in interface `EventEmitter`
      Parameters:
        `eventType` -
        `properties` -
      See Also:
        `EventEmitter.emit(String, java.util.Map)`

    - #### request

          public void request(java.lang.String eventType,
                              EventListener listener)

      Attaches a listener and fires off an event of eventType, with the hope that there's a corresponding listener set to 'respond' to the listener specified in the request. The flow looks something like: request ->emit eventType -> eventType listener picks up event -> respond -> listener passed into request is called After the listener is executed, it is removed
      Specified by:
        `request` in interface `EventEmitter`
      Parameters:
        `eventType` - The type of Event to emit and expect a response from
        `listener` - A listener to process the response. After processing, the response should be removed
      See Also:
        `EventEmitter.request(String, com.brightcove.player.event.EventListener)`, `EventListener`

    - #### request

          public void request(java.lang.String eventType,
                              java.util.Map<java.lang.String,java.lang.Object> properties,
                              EventListener listener)

      Similar to above, except the properties map is passed along
      Specified by:
        `request` in interface `EventEmitter`
      Parameters:
        `eventType` - The type of Event to emit and expect a response from
        `properties` - A Map of properties to pass along the event chain
        `listener` - A listener to process the response. After processing, the response should be removed
      See Also:
        `EventEmitter.request(String, java.util.Map, com.brightcove.player.event.EventListener)`, `EventListener`

    - #### respond

          public void respond(java.util.Map<java.lang.String,java.lang.Object> properties)

      Meant to respond to a request event. By way of using Event.REQUEST_TOKEN to identify the listener created during the request, the respond fires an event 'directly' at said listener. Note that if the properties map does not contain Event.REQUEST_TOKEN, this method is a no-op. The intent for this behavior is that if an EventListener contains a call to respond, but there was no actual request, nothing should break (e.g. several 'play' event listeners, but only one is intended to respond to requests.
      Specified by:
        `respond` in interface `EventEmitter`
      Parameters:
        `properties` -

    - #### respond

          public void respond(Event event)

      Convenience method to save the user from typing event.properties when responding
      Specified by:
        `respond` in interface `EventEmitter`
      Parameters:
        `event` - An Event containing properties to pass on to the Request listener
      See Also:
        `Event`

    - #### getInvocationContainerPositionByToken

          protected int getInvocationContainerPositionByToken(java.util.List<com.brightcove.player.event.InvocationContainer> invocations,
                                                              int token)

      Returns the position of an invocationContainer
      Parameters:
        `token` -
      Returns:
        The position in the queue of the invocation container associated with the token.
      See Also:
        `InvocationContainer`

    - #### getInvocationContainerByToken

          protected com.brightcove.player.event.InvocationContainer getInvocationContainerByToken(java.util.List<com.brightcove.player.event.InvocationContainer> invocations,
                                                                                                  int token)

      Returns the InvocationContainer in a list of Containers which matches the token
      Parameters:
        `invocations` -
        `token` -
      Returns:
        The invocation container associated with the token.
      See Also:
        `InvocationContainer`

    - #### enable

          public void enable()

      Enables listener registration and event emitting.
      Specified by:
        `enable` in interface `EventEmitter`

    - #### disable

          public void disable()

      Disables listener registration and event emitting.
      Specified by:
        `disable` in interface `EventEmitter`