Module id.xfunction

Class ReplayablePublisher<T>

Object
ReplayablePublisher<T>
Type Parameters:
T - input type
All Implemented Interfaces:
AutoCloseable, Flow.Publisher<T>

public class ReplayablePublisher<T> extends Object implements Flow.Publisher<T>, AutoCloseable
Publisher which caches last N submitted items and replays them to new subscribers.

Items are replayed before the Flow.Subscriber.onSubscribe(java.util.concurrent.Flow.Subscription)

  • Constructor Details

    • ReplayablePublisher

      public ReplayablePublisher(int cacheSize)
    • ReplayablePublisher

      public ReplayablePublisher(int cacheSize, Executor executor, int maxBufferCapacity)
  • Method Details

    • submit

      public void submit(T item)
    • subscribe

      public void subscribe(ReplayableSubscriber<? super T> subscriber)
    • subscribe

      public void subscribe(Flow.Subscriber<? super T> subscriber)
      Specified by:
      subscribe in interface Flow.Publisher<T>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getNumberOfItemsInCache

      public int getNumberOfItemsInCache()
    • isCacheEmpty

      public boolean isCacheEmpty()
    • cacheContains

      public boolean cacheContains(T o)
    • clearCache

      public void clearCache()
    • getCacheReadOnly

      public Collection<T> getCacheReadOnly()
    • isSubscribed

      public boolean isSubscribed(Flow.Subscriber<? super T> subscriber)