Package 

Class EventEmitterImpl

  • All Implemented Interfaces:
    com.brightcove.player.event.EventEmitter

    
    public class EventEmitterImpl
     implements EventEmitter
                        

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

    • Method Summary

      Modifier and Type Method Description
      int on(String eventType, EventListener listener) Adds the listener to the event queue, returns a token that thecaller can use to off itself.
      int once(String eventType, EventListener listener) Similar to on, except that the listener is removed afterprocessing one event.
      void off() Removes all listeners.
      void off(String eventType, int token) Removes a listener from an event queue, using the token as a reference
      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 request(String eventType, EventListener listener) Attaches a listener and fires off an event of eventType, with the hope that there's a corresponding listener setto '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(Map<String, Object> properties) Meant to respond to a request event.
      void respond(Event event) Convenience method to save the user from typing event.
      void enable() Enables listener registration and event emitting.
      void disable() Disables listener registration and event emitting.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EventEmitterImpl

        EventEmitterImpl()
    • Method Detail

      • on

         int on(String eventType, EventListener listener)

        Adds the listener to the event queue, returns a token that thecaller can use to off itself. Calls to on are stored in theorder they arrive, which means that during event propagation,the listeners will be executed in the order they were added.

        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
      • once

         int once(String eventType, EventListener listener)

        Similar to on, except that the listener is removed afterprocessing one event.

        Parameters:
        eventType - Same as for 'on'; a string representing the event to be listened for
        listener - Subclass of EventListener
      • off

         void off()

        Removes all listeners.

      • off

         void off(String eventType, int token)

        Removes a listener from an event queue, using the token as a reference

        Parameters:
        eventType - A string representing the Event type
        token - Integer-valued token that was created during 'on'
      • emit

         void emit(String eventType)

        Emits an event. All listeners attached to this event will be processed

      • request

         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 setto '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

        Parameters:
        eventType - The type of Event to emit and expect a response from
        listener - A listener to process the response.
      • request

         void request(String eventType, Map<String, Object> properties, EventListener listener)

        Similar to above, except the properties map is passed along

        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.
      • respond

         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 duringthe request, the respond fires an event 'directly' at said listener. Note that if the properties map does not containEvent.REQUEST_TOKEN, this method is a no-op. The intent for this behavior is that if an EventListener contains acall to respond, but there was no actual request, nothing should break (e.g. several 'play' event listeners, butonly one is intended to respond to requests.

      • respond

         void respond(Event event)

        Convenience method to save the user from typing event.properties when responding

        Parameters:
        event - An Event containing properties to pass on to the Request listener
      • enable

         void enable()

        Enables listener registration and event emitting.

      • disable

         void disable()

        Disables listener registration and event emitting.