Interface EventEmitter

All Known Implementing Classes:
EventEmitterImpl, RegisteringEventEmitter

public interface EventEmitter
Defines the public facing api for classes that wish to emit events. See EventEmitterImpl for the main implementation method descriptions.
See Also:
  • 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 with a dynamic 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.
    void
    off()
    De-register all listeners.
    void
    off(String eventType, int token)
    Unregister a listener from listening to an event type.
    int
    on(String eventType, EventListener listener)
    Register an event listener to be called when an EventType is emitted.
    int
    once(String eventType, EventListener listener)
    Similar to on, except that the listener will be removed after processing one event.
    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)
    Request a response from the first listener to respond.
    void
    respond(Event event)
    Respond to a request.
    void
    respond(Map<String,Object> properties)
    Respond to a request.
  • Method Details

    • on

      int on(String eventType, EventListener listener)
      Register an event listener to be called when an EventType is emitted.
      Parameters:
      eventType -
      listener -
      Returns:
      a unique token that can be used to unregister the listener.
      See Also:
    • once

      int once(String eventType, EventListener listener)
      Similar to on, except that the listener will be removed after processing one event.
      Parameters:
      eventType -
      listener -
      Returns:
      A token, which can be used later to turn the listener off.
      See Also:
    • off

      void off()
      De-register all listeners.
    • off

      void off(String eventType, int token)
      Unregister a listener from listening to an event type. Uses a unique token to identify which listener to remove.
      Parameters:
      eventType -
      token -
    • emit

      void emit(String eventType)
      Emits an Event.
      Parameters:
      eventType -
    • emit

      void emit(String eventType, Map<String,Object> properties)
      Emits an event with a dynamic properties Map.
      Parameters:
      eventType -
      properties -
    • emitNow

      @MainThread 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.
    • request

      void request(String eventType, EventListener listener)
      Requests a response from the first listener to respond. The response is handled by the provided listener, after which the listener is removed.
      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

      void request(String eventType, Map<String,Object> properties, EventListener listener)
      Request a response from the first listener to respond. The response is handled by the provided listener, after which 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. After processing, the response should be removed
      See Also:
    • 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.
      Parameters:
      properties -
    • respond

      void respond(Event event)
      Respond to a request. Should be called within an EventListener and given an Event object with the 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.