Package 

Class RegisteringEventEmitter

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

    
    public class RegisteringEventEmitter
     implements EventEmitter
                        

    The RegisteringEventEmitter allows developers to constrain which events their Components are intended to listen for and emit. If a component attempts to emit or listen for an event that it hasn't explicitly listed, an exception will be thrown.

    Registration occurs by creating a new instance of RegisteringEventEmitter, using a shared EventEmitter (typically EventEmitterImpl), and the class to be registered. The class in question MUST be decorated with two annotations: ListensFor and Emits. Each takes a String[], populated with EventType strings, attached to their 'events' property. Each annotation MUST be included, even if the component has no intention of listening or emitting any events.

    For example, the following component class declartion:

    @Emits(events = {EventType.PLAY, EventType.STOP})@ListensFor(events = {EventType.PLAY})public class SampleComponent implements Component

    • Method Summary

      Modifier and Type Method Description
      List<String> getAllowedEmittedEvents() Retrieves a list of all Events that are allowed to be emitted in thisRegisteringEventEmitter.
      List<String> getAllowedListenEvents() Retrieves a list of all Events that are allowed to be listened in thisRegisteringEventEmitter.
      int on(String eventType, EventListener listener) Add a listener for an EventType, filtered by what the component is allowed to listen for.
      int once(String eventType, EventListener listener) Add a listener for an EventType, filtered by what the component is allowed to listen for.
      void off() Remove all listeners.
      void off(String eventType, int token) Remove a listener from handling an event of EventType.
      void emit(String eventType) Emits an Event of EventType.
      void emit(String eventType, Map<String, Object> properties) Emits and Event of EventType, provided the Component is allowed to do so.
      void emitNow(String eventType, Map<String, Object> properties) Emits an event immediately instead of waiting for the handler.
      EventEmitter getRootEmitter() Retrieve the underlying EventEmitter provided when initializing this emitter.
      static RegisteringEventEmitter build(EventEmitter incomingEmitter, Class<out Component> componentClass) Factory method to create a new RegisteringEventEmitter given an existing EventEmitter anda Component implementation.
      void request(String eventType, EventListener listener) Requests a response from the first listener to respond.
      void request(String eventType, Map<String, Object> properties, EventListener listener) Requests a response from the first listener to respond.
      void respond(Map<String, Object> properties) Respond to a request.
      void respond(Event event) Respond to a request.
      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

    • Method Detail

      • on

         int on(String eventType, EventListener listener)

        Add a listener for an EventType, filtered by what the component is allowed to listen for. The response token shouldbe cached by component for use later in the component lifecycle

      • once

         int once(String eventType, EventListener listener)

        Add a listener for an EventType, filtered by what the component is allowed to listen for. This listener will behandled only once, at which point it is removed. The response token shouldbe cached by component for use later in the component lifecycle

      • off

         void off()

        Remove all listeners.

      • off

         void off(String eventType, int token)

        Remove a listener from handling an event of EventType. Requires a token given by on() or once()

      • emit

         void emit(String eventType)

        Emits an Event of EventType. However, the Event will only be emitted if the component is allowed to do so

      • emit

         void emit(String eventType, Map<String, Object> properties)

        Emits and Event of EventType, provided the Component is allowed to do so. Will also pass along a set of Stringproperties.

      • emitNow

         void emitNow(String eventType, Map<String, Object> properties)

        Emits an event immediately instead of waiting for the handler.

        Parameters:
        eventType - The event type.
        properties - The properties to send when processing the event.
      • build

         static RegisteringEventEmitter build(EventEmitter incomingEmitter, Class<out Component> componentClass)

        Factory method to create a new RegisteringEventEmitter given an existing EventEmitter anda Component implementation. All RegisteringEventEmitters should be created with this method.

        Parameters:
        incomingEmitter - an existing EventEmitter, could also be a RegisteringEventEmitter
        componentClass - the Component implementation to be managed by this emitter
      • request

         void request(String eventType, EventListener listener)

        Requests a response from the first listener to respond. The response is handled by the provided listener, afterwhich the listener 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)

        Requests a response from the first listener to respond. The response is handled by the provided listener, afterwhich the listener is removed. The provided properties map is passed on to the responding listener

        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)

        Respond to a request. Should be placed within an EventListener and via some means (e.g. the token of an InvocationContainer)know which Request Listener to respond to. See

      • respond

         void respond(Event event)

        Respond to a request. Should be called within an EventListener and given an Event object withthe appropriate REQUEST_TOKEN value

        Parameters:
        event - an Event object with, at minimum, the necessary REQUEST_TOKEN value
      • enable

         void enable()

        Enables listener registration and event emitting.

      • disable

         void disable()

        Disables listener registration and event emitting.