Package discord4j.core.event
Class ReplayingEventDispatcher.Builder
- java.lang.Object
-
- discord4j.core.event.DefaultEventDispatcher.Builder
-
- discord4j.core.event.ReplayingEventDispatcher.Builder
-
- All Implemented Interfaces:
EventDispatcher.Builder
- Enclosing class:
- ReplayingEventDispatcher
public static class ReplayingEventDispatcher.Builder extends DefaultEventDispatcher.Builder
A builder to createEventDispatcher
instances.
-
-
Field Summary
Fields Modifier and Type Field Description protected Predicate<Event>
replayEventFilter
protected FluxSink.OverflowStrategy
replayEventOverflowStrategy
protected ReplayProcessor<Event>
replayEventProcessor
protected Publisher<?>
stopReplayingTrigger
protected Scheduler
timedTaskScheduler
-
Fields inherited from class discord4j.core.event.DefaultEventDispatcher.Builder
eventProcessor, eventScheduler, overflowStrategy
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EventDispatcher
build()
Create theEventDispatcher
ReplayingEventDispatcher.Builder
eventProcessor(FluxProcessor<Event,Event> eventProcessor)
Set the underlyingFluxProcessor
the dispatcher will use to queue and distribute events.ReplayingEventDispatcher.Builder
eventScheduler(Scheduler eventScheduler)
Set theScheduler
this dispatcher should use to publish events to its subscribers.ReplayingEventDispatcher.Builder
overflowStrategy(FluxSink.OverflowStrategy overflowStrategy)
Set theFluxSink.OverflowStrategy
for dealing with overflow scenarios where too many events are being published.ReplayingEventDispatcher.Builder
replayEventFilter(Predicate<Event> replayEventFilter)
Set a filter used to determine whether an incomingEvent
should be stored for replay.ReplayingEventDispatcher.Builder
replayEventOverflowStrategy(FluxSink.OverflowStrategy replayEventOverflowStrategy)
Set an overflow strategy while pushing events to the replay processor.ReplayingEventDispatcher.Builder
replayEventProcessor(ReplayProcessor<Event> replayEventProcessor)
Set a processor used to store events while no subscribers are connected and will be forwarded to all late subscribers.ReplayingEventDispatcher.Builder
stopReplayingTrigger(Publisher<?> stopReplayingTrigger)
Set a triggerPublisher
that is subscribed upon the first subscriber connects to this dispatcher.ReplayingEventDispatcher.Builder
timedTaskScheduler(Scheduler timedTaskScheduler)
Set a time-capableScheduler
used to detect whether all events have replayed to a subscriber.-
Methods inherited from class discord4j.core.event.DefaultEventDispatcher.Builder
eventSink
-
-
-
-
Field Detail
-
timedTaskScheduler
protected Scheduler timedTaskScheduler
-
replayEventProcessor
protected ReplayProcessor<Event> replayEventProcessor
-
replayEventOverflowStrategy
protected FluxSink.OverflowStrategy replayEventOverflowStrategy
-
stopReplayingTrigger
protected Publisher<?> stopReplayingTrigger
-
-
Method Detail
-
eventProcessor
public ReplayingEventDispatcher.Builder eventProcessor(FluxProcessor<Event,Event> eventProcessor)
Description copied from interface:EventDispatcher.Builder
Set the underlyingFluxProcessor
the dispatcher will use to queue and distribute events. Defaults to using anEmitterProcessor
.Using
EmitterProcessor
only emits events since a subscriber has subscribed to the processor (except for the first one which receives all queued signals until that point), and it allows you to configure the backing queue size while allowing you to use operators likeFlux.repeat()
andFlux.retry()
to drop the triggering signal.- Specified by:
eventProcessor
in interfaceEventDispatcher.Builder
- Overrides:
eventProcessor
in classDefaultEventDispatcher.Builder
- Parameters:
eventProcessor
- the custom processor for events- Returns:
- this builder
-
overflowStrategy
public ReplayingEventDispatcher.Builder overflowStrategy(FluxSink.OverflowStrategy overflowStrategy)
Description copied from interface:EventDispatcher.Builder
Set theFluxSink.OverflowStrategy
for dealing with overflow scenarios where too many events are being published. Defaults to usingFluxSink.OverflowStrategy.BUFFER
to ensure all events are delivered at the cost of higher memory footprint and potentialOutOfMemoryError
scenarios.To only keep the earliest events you can use
FluxSink.OverflowStrategy.DROP
, and to only keep the most recent events, useFluxSink.OverflowStrategy.LATEST
. The number of events that can be queued until this strategy is applied depends on the underlying processor implementation.- Specified by:
overflowStrategy
in interfaceEventDispatcher.Builder
- Overrides:
overflowStrategy
in classDefaultEventDispatcher.Builder
- Parameters:
overflowStrategy
- the custom backpressure strategy- Returns:
- this builder
-
eventScheduler
public ReplayingEventDispatcher.Builder eventScheduler(Scheduler eventScheduler)
Description copied from interface:EventDispatcher.Builder
Set theScheduler
this dispatcher should use to publish events to its subscribers. Using a bounded elastic/blocking-capable one is recommended for general workloads that may have blocking sequences.- Specified by:
eventScheduler
in interfaceEventDispatcher.Builder
- Overrides:
eventScheduler
in classDefaultEventDispatcher.Builder
- Parameters:
eventScheduler
- a customScheduler
to publish events- Returns:
- this builder
-
replayEventProcessor
public ReplayingEventDispatcher.Builder replayEventProcessor(ReplayProcessor<Event> replayEventProcessor)
Set a processor used to store events while no subscribers are connected and will be forwarded to all late subscribers.- Parameters:
replayEventProcessor
- the replay processor to use as backend- Returns:
- this builder
-
replayEventOverflowStrategy
public ReplayingEventDispatcher.Builder replayEventOverflowStrategy(FluxSink.OverflowStrategy replayEventOverflowStrategy)
Set an overflow strategy while pushing events to the replay processor.- Parameters:
replayEventOverflowStrategy
- the strategy to use when pushing values to the replay processor- Returns:
- this builder
-
replayEventFilter
public ReplayingEventDispatcher.Builder replayEventFilter(Predicate<Event> replayEventFilter)
Set a filter used to determine whether an incomingEvent
should be stored for replay.- Parameters:
replayEventFilter
- the filter for events that can be replayed- Returns:
- this builder
-
timedTaskScheduler
public ReplayingEventDispatcher.Builder timedTaskScheduler(Scheduler timedTaskScheduler)
Set a time-capableScheduler
used to detect whether all events have replayed to a subscriber.- Parameters:
timedTaskScheduler
- the scheduler to detect no more events can be replayed- Returns:
- this builder
-
stopReplayingTrigger
public ReplayingEventDispatcher.Builder stopReplayingTrigger(Publisher<?> stopReplayingTrigger)
Set a triggerPublisher
that is subscribed upon the first subscriber connects to this dispatcher. Upon completion, error or cancellation, the replaying window will be closed until all subscribers have disconnected.- Parameters:
stopReplayingTrigger
- the sequence to signal that no more events should be replayed. Can be subscribed to multiple times as subscribers disconnect.- Returns:
- this builder
-
build
public EventDispatcher build()
Description copied from interface:EventDispatcher.Builder
Create theEventDispatcher
- Specified by:
build
in interfaceEventDispatcher.Builder
- Overrides:
build
in classDefaultEventDispatcher.Builder
- Returns:
- an
EventDispatcher
with the configured parameters.
-
-