Class EventQueue<T>

java.lang.Object
nl.colorize.util.EventQueue<T>
Type Parameters:
T - The type of event that can be subscribed to.
All Implemented Interfaces:
Flow.Subscriber<T>

public class EventQueue<T> extends Object implements Flow.Subscriber<T>
Subscribes to asynchronous events and accumulates all received events and errors in queue, so that they can be processed at a later time.

Instances of this class are thread-safe: Events can be received and processed on different threads.

See Also:
  • Constructor Details

    • EventQueue

      public EventQueue()
  • Method Details

    • onSubscribe

      public void onSubscribe(Flow.Subscription newSubscription)
      Specified by:
      onSubscribe in interface Flow.Subscriber<T>
    • onNext

      public void onNext(T event)
      Specified by:
      onNext in interface Flow.Subscriber<T>
    • onError

      public void onError(Throwable error)
      Specified by:
      onError in interface Flow.Subscriber<T>
    • onComplete

      public void onComplete()
      Specified by:
      onComplete in interface Flow.Subscriber<T>
    • flush

      public void flush(Consumer<T> onEvent, Consumer<Exception> onError)
      Flushes the event queue, invoking the specified callback functions for all events and errors that have been received since the last time the event queue was flushed. Events and errors are processed in the order they were received.
    • clear

      public void clear()
      Clears this event queue, without processing the events and errors that are currently in it.
    • subscribe

      public static <T> EventQueue<T> subscribe(Subject<T> subject)
      Factory method that creates an EventQueue and immediately subscribes it to the specified Subject.