Package io.servicetalk.concurrent.api
Class ReplayStrategies
java.lang.Object
io.servicetalk.concurrent.api.ReplayStrategies
Utilities to customize
ReplayStrategy
.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ReplayStrategyBuilder<T>
historyBuilder
(int history) Create aReplayStrategyBuilder
using the history strategy.static <T> ReplayStrategyBuilder<T>
historyTtlBuilder
(int historyHint, Duration ttl, Executor executor) Create aReplayStrategyBuilder
using the historyHint and TTL strategy.static <T> ReplayStrategyBuilder<T>
historyTtlBuilder
(int historyHint, Duration ttl, Executor executor, boolean lazyEviction) Create aReplayStrategyBuilder
using the historyHint and TTL strategy.
-
Method Details
-
historyBuilder
Create aReplayStrategyBuilder
using the history strategy.- Type Parameters:
T
- The type ofReplayStrategyBuilder
.- Parameters:
history
- max number of signals (excludingPublisherSource.Subscriber.onComplete()
andPublisherSource.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 aReplayStrategyBuilder
using the historyHint and TTL strategy.- Type Parameters:
T
- The type ofReplayStrategyBuilder
.- Parameters:
historyHint
- hint for max number of signals (excludingPublisherSource.Subscriber.onComplete()
andPublisherSource.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 thettl
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 aReplayStrategyBuilder
using the historyHint and TTL strategy.- Type Parameters:
T
- The type ofReplayStrategyBuilder
.- Parameters:
historyHint
- hint for max number of signals (excludingPublisherSource.Subscriber.onComplete()
andPublisherSource.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 thettl
argument.lazyEviction
-true
will evict expired items in a lazy fashion when new subscribers arrive. This approach is more likely to retainhistoryHint
elements in memory in steady state, but avoids cost of scheduling timer tasks.false
will evict expired items eagerly when they expire. Ifttl
is lower thathistoryHint
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.
-