Interface Publisher<T>

Type Parameters:
T -
All Known Subinterfaces:
AsyncPublisher<T>
All Known Implementing Classes:
AbstractPublisher, ConcurrentDequePublisher, ConcurrentLockedPublisher, LinkedPublisher

public interface Publisher<T>
Publishes events to multiple subscribers. This interface defines a simple synchronous style publisher/subscriber system.
  • Method Details

    • subscribe

      default Subscription subscribe(Consumer<? super T> consumer)
      Subscribes to a particular event. The supplied Consumer will receive zero or more events in the future until the associated call to Subscription.unsubscribe().
      Parameters:
      consumer - the Consumer which will accept event
      Returns:
      the Subscription
    • subscribe

      Subscription subscribe(BiConsumer<Subscription,? super T> consumer)
      Subscribes to a particular event. The supplied BiConsumer will receive zero or more events in the future until the associated call to Subscription.unsubscribe().
      Parameters:
      consumer - the BiConsumer which will accept event
      Returns:
      the Subscription
    • clear

      void clear()
      Clears all Subscriptions and implicitly removes them from the internal pool. Implementing this interface method is optional, and therefore this may throw an instance of UnsupportedOperationException.
    • publish

      void publish(T t)
      Publishes the event synchronously.
      Parameters:
      t - the event
    • publish

      void publish(T t, Consumer<? super T> onFinish)
      Publishes the supplied event synchronously and calls the Consumer when all Subscriptions have been notified.
      Parameters:
      t - the event
      onFinish - the Consumer to be called after all Subscriptions have been notified
    • publish

      void publish(T t, Consumer<? super T> onFinish, Consumer<Throwable> onException)
      Publishes the supplied event synchronously and calls the Consumer when all Subscriptions have been notified. Additionally, this notifies for every exception thrown in the process.
      Parameters:
      t - the event
      onFinish - the Consumer to be called after all Subscriptions have been notified
      onException - the Consumer which is notified for each exception thrown