Interface Event.Emitter<T>

Type Parameters:
T - type of the event object
Enclosing class:
Event

@Contract public static interface Event.Emitter<T>
To publish an event, simply inject an instance of this type (correctly typed with your event object) into your service, and call emit(Object, Qualifier...) on it when needed.

A single service can inject more than one instance, if it wants to publish events of different types. The type of the event is determining which events are published (i.e. qualifiers or any other annotation are not relevant, only the type of the object).

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    emit(T eventObject, Qualifier... qualifiers)
    Emit an event.
    emitAsync(T eventObject, Qualifier... qualifiers)
    Emit an event.
  • Method Details

    • emit

      void emit(T eventObject, Qualifier... qualifiers)
      Emit an event. The method blocks until all observers are processed.

      Only observers with the same qualifiers as specified will be notified.

      Parameters:
      eventObject - event object to deliver to the observers
      qualifiers - qualifiers (zero or more) that qualify this event instance
      Throws:
      EventDispatchException - if any exception is encountered, the first one is the cause, and all others are added as a suppressed exception to the thrown exception
    • emitAsync

      CompletionStage<T> emitAsync(T eventObject, Qualifier... qualifiers)
      Emit an event. The method returns immediately with a completion stage that will get completed when all observers are notified. If any observer throws an exception, an EventDispatchException is created, all exceptions are added as suppressed to it, and it is thrown, so CompletionStage.exceptionally(java.util.function.Function) is invoked on the returned stage.

      Only observers with the same qualifiers as specified will be notified.

      Parameters:
      eventObject - event object to deliver to the listeners
      qualifiers - qualifiers (zero or more) that qualify this event instance
      Returns:
      completion stage to observe completion events