Package net.phoenix

Class EventEmitter<T extends Event>

java.lang.Object
net.phoenix.EventEmitter<T>
Type Parameters:
T - Event type. Either should be a class that extends Event OR a generic type (EventEmitter<? extends Event>)

public class EventEmitter<T extends Event> extends Object
Standard event emitter class
  • Constructor Details

    • EventEmitter

      public EventEmitter()
  • Method Details

    • emit

      public void emit(String channel, T object)
      Calls all the events under a channel
      Parameters:
      channel - Channel to send event
      object - Instance of event to send
      Throws:
      IllegalArgumentException - Throws exception if the event passed is different to the EventHandler type
    • on

      public String on(Callback<T> callback)
      Awaits for a method under the global channel
      Throws:
      IllegalArgumentException - Throws exception if the event passed is different to the EventHandler type
    • on

      public String on(Callback<T> callback, EventEmitter.Priority priority)
      Awaits for a method under the global channel
      Throws:
      IllegalArgumentException - Throws exception if the event passed is different to the EventHandler type
    • emit

      public void emit(T object)
      Awaits for a method under the global channel
      Throws:
      IllegalArgumentException - Throws exception if the event passed is different to the EventHandler type
    • on

      public String on(String channel, Callback<T> callback)
      Register an event handler with default priority of LOW
      Parameters:
      channel - The channel you want to listen for
      callback - Event handler. Can be used as a lambda; (channel, event) -> {}
      Returns:
      Event handler UUID used in off()
      See Also:
    • on

      public String on(String channel, Callback<T> callback, EventEmitter.Priority priority)
      Register an event handler with a custom priority
      Parameters:
      channel - The channel you want to listen for
      callback - Event handler. Can be used as a lambda; (channel, event) -> {}
      priority - Priority level
      Returns:
      Event handler UUID used in off()
      See Also:
    • await

      public T await(String channel) throws InterruptedException
      Awaits for a method under the global channel
      Throws:
      InterruptedException - Throws exception if the thread is interrupted
    • off

      public void off(String uuid)
      Disable a eventHandler
      Parameters:
      uuid - UUID of event handler to remove. UUID is the value returned by EventEmitter#on