Class ReplayStrategies

java.lang.Object
io.servicetalk.concurrent.api.ReplayStrategies

public final class ReplayStrategies extends Object
Utilities to customize ReplayStrategy.
  • Method Details

    • historyBuilder

      public static <T> ReplayStrategyBuilder<T> historyBuilder(int history)
      Create a ReplayStrategyBuilder using the history strategy.
      Type Parameters:
      T - The type of ReplayStrategyBuilder.
      Parameters:
      history - max number of signals (excluding PublisherSource.Subscriber.onComplete() and PublisherSource.Subscriber.onError(Throwable)) to retain.
      Returns:
      a ReplayStrategyBuilder using the history strategy.
    • historyTtlBuilder

      public static <T> ReplayStrategyBuilder<T> historyTtlBuilder(int historyHint, Duration ttl, Executor executor)
      Create a ReplayStrategyBuilder using the historyHint and TTL strategy.
      Type Parameters:
      T - The type of ReplayStrategyBuilder.
      Parameters:
      historyHint - hint for max number of signals (excluding PublisherSource.Subscriber.onComplete() and PublisherSource.Subscriber.onError(Throwable)) to retain. Due to concurrency between threads (timer, accumulation, subscribe) the maximum number of signals delivered to new subscribers may potentially be more but this hint provides a general bound for memory when concurrency subsides.
      ttl - duration each element will be retained before being removed.
      executor - used to enforce the ttl argument.
      Returns:
      a ReplayStrategyBuilder using the historyHint and TTL strategy.
    • historyTtlBuilder

      public static <T> ReplayStrategyBuilder<T> historyTtlBuilder(int historyHint, Duration ttl, Executor executor, boolean lazyEviction)
      Create a ReplayStrategyBuilder using the historyHint and TTL strategy.
      Type Parameters:
      T - The type of ReplayStrategyBuilder.
      Parameters:
      historyHint - hint for max number of signals (excluding PublisherSource.Subscriber.onComplete() and PublisherSource.Subscriber.onError(Throwable)) to retain. Due to concurrency between threads (timer, accumulation, subscribe) the maximum number of signals delivered to new subscribers may potentially be more but this hint provides a general bound for memory when concurrency subsides.
      ttl - duration each element will be retained before being removed.
      executor - used to enforce the ttl argument.
      lazyEviction -
      • true will evict expired items in a lazy fashion when new subscribers arrive. This approach is more likely to retain historyHint elements in memory in steady state, but avoids cost of scheduling timer tasks.
      • false will evict expired items eagerly when they expire. If ttl is lower that historyHint relative to signal arrival rate this can use less memory but schedules time tasks.

        Note that timer expiration is done concurrently which may cause gaps in signal delivery to new subscribers. For example:

                 initial accumulation state: [onNext1, onNext2, onNext3, onNext4]
                 Thread1: add new subscriber, subscriber does request(4), deliver onNext1
                 Thread2: expire onNext1, onNext2, onNext3
                 Thread1: [deliver onNext2,] deliver onNext4
                   Note that onNext2 may or may not be delivered, and onNext3 was not delivered.
               
      Returns:
      a ReplayStrategyBuilder using the historyHint and TTL strategy.