Interface EventBusAgent


public interface EventBusAgent
An event agent providing means for custom event buses and events.
Since:
5.2.220703
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Agent providing means for custom events.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T extends Serializable>
    BusIdentifier<T>
    createBusIdentifier(@NotNull String identifier, @NotNull Class<T> eventType, @org.jetbrains.annotations.Nullable long... ids)
    Create bus identifier object.
    A bus identifier should be as local and specific as possible to avoid unnecessary event delivery to listeners not interested in the events.
    <T extends Serializable>
    void
    post(@NotNull BusIdentifier<T> bus, T data)
    Post an event on the specified bus.
    Event delivery is asynchronous - this method returns before the event is delivered and processed by all possibly remote listeners.
    Each bus has its own event queue and the events will be delivered in order one event at atime from this queue to the registered listeners.
    <T extends Serializable>
    void
    register(@NotNull BusIdentifier<T> bus, @NotNull Consumer<T> listener)
    Register an event listener for a specified bus.
    <T extends Serializable>
    void
    unregister(@NotNull BusIdentifier<T> bus, @NotNull Consumer<T> listener)
    Unregister an event listener for a specified bus.
    If the listener was not registered this method does nothing.
  • Field Details

  • Method Details

    • post

      <T extends Serializable> void post(@NotNull @NotNull BusIdentifier<T> bus, @NotNull T data)
      Post an event on the specified bus.
      Event delivery is asynchronous - this method returns before the event is delivered and processed by all possibly remote listeners.
      Each bus has its own event queue and the events will be delivered in order one event at atime from this queue to the registered listeners. Event processing in a listener should be as fast as possible to avoid delayed event processing in subsequent listeners.
      The event data is serialized and should be as small as possible to avoid unnecessary networktraffic and overhead.
      Type Parameters:
      T - The type of the events on the bus.
      Parameters:
      bus - The bus to post the event on.
      data - The event data to post.
      Since:
      5.2.220703
      See Also:
    • register

      <T extends Serializable> void register(@NotNull @NotNull BusIdentifier<T> bus, @NotNull @NotNull Consumer<T> listener)
      Register an event listener for a specified bus.
      If the listener was already registered, the listener is moved to last position of the registered listeners. A listener may be registered on multiple buses if the event type is compatible.
      The listener reference will be held with a WeakReference. You have to keep a reference to the listener instance, or it will be automatically removed and unregistered.
      If the listener implements Closeable, its close() method will be called, if theunderlying Connection is closed. A closed Connection no longer delivers any events to a listener.
      Note: Remember to call unregister(BusIdentifier,Consumer) if the listener is no longer used.
      Type Parameters:
      T - The type of the events on the bus.
      Parameters:
      bus - The bus to register the event listener for.
      listener - The event listener.
      Since:
      5.2.220703
      See Also:
    • unregister

      <T extends Serializable> void unregister(@NotNull @NotNull BusIdentifier<T> bus, @NotNull @NotNull Consumer<T> listener)
      Unregister an event listener for a specified bus.
      If the listener was not registered this method does nothing. A listener may be registered on multiple buses if the event type is compatible.
      Type Parameters:
      T - The type of the events on the bus.
      Parameters:
      bus - The bus to unregister the event listener for.
      listener - The event listener.
      Since:
      5.2.220703
      See Also:
    • createBusIdentifier

      static <T extends Serializable> BusIdentifier<T> createBusIdentifier(@NotNull @NotNull String identifier, @NotNull @NotNull Class<T> eventType, @Nullable @org.jetbrains.annotations.Nullable long... ids)
      Create bus identifier object.
      A bus identifier should be as local and specific as possible to avoid unnecessary event delivery to listeners not interested in the events.
      Type Parameters:
      T - The type of the events on the bus.
      Parameters:
      identifier - The string identifier name of the bus.
      eventType - The type of the events on the bus.
      ids - Optional additional ids to identify the bus. For instance a project id if the bus is projectlocal.
      Returns:
      The created bus identifier object.
      Since:
      5.2.220703