Class EventEmitterImpl

java.lang.Object
com.brightcove.player.event.EventEmitterImpl
All Implemented Interfaces:
EventEmitter

public class EventEmitterImpl extends Object implements EventEmitter
The 'Main' implementation of EventEmitter. Most Components should use this, as should RegisteringEventEmitter.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected android.os.Handler
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Disables listener registration and event emitting.
    void
    emit(String eventType)
    Emits an event.
    void
    emit(String eventType, Map<String,Object> properties)
    Emits an event, passing along the properties map
    void
    emitNow(String eventType, Map<String,Object> properties)
    Emits an event immediately instead of waiting for the handler.
    void
    Enables listener registration and event emitting.
    protected com.brightcove.player.event.InvocationContainer
    getInvocationContainerByToken(List<com.brightcove.player.event.InvocationContainer> invocations, int token)
    Returns the InvocationContainer in a list of Containers which matches the token
    protected int
    getInvocationContainerPositionByToken(List<com.brightcove.player.event.InvocationContainer> invocations, int token)
    Returns the position of an invocationContainer
    void
    off()
    Removes all listeners.
    void
    off(String eventType, int token)
    Removes a listener from an event queue, using the token as a reference
    int
    on(String eventType, EventListener listener)
    Adds the listener to the event queue, returns a token that the caller can use to off itself.
    int
    once(String eventType, EventListener listener)
    Similar to on, except that the listener is removed after processing one event.
    void
    request(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(String eventType, Map<String,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(Map<String,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 Details

    • handler

      protected android.os.Handler handler
  • Constructor Details

    • EventEmitterImpl

      public EventEmitterImpl()
  • Method Details

    • on

      public int on(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:
    • once

      public int once(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:
    • off

      public void off()
      Removes all listeners.
      Specified by:
      off in interface EventEmitter
    • off

      public void off(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:
    • emit

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

      public void emit(String eventType, Map<String,Object> properties)
      Emits an event, passing along the properties map
      Specified by:
      emit in interface EventEmitter
      Parameters:
      eventType -
      properties -
      See Also:
    • emitNow

      @RestrictTo(LIBRARY) @MainThread public void emitNow(String eventType, Map<String,Object> properties)
      Description copied from interface: EventEmitter
      Emits an event immediately instead of waiting for the handler.
      Specified by:
      emitNow in interface EventEmitter
      Parameters:
      eventType - The event type.
      properties - The properties to send when processing the event.
    • request

      public void request(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:
    • request

      public void request(String eventType, Map<String,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:
    • respond

      public void respond(Map<String,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:
    • getInvocationContainerPositionByToken

      protected int getInvocationContainerPositionByToken(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(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