Package discord4j.core.event
Class DefaultEventDispatcher.Builder
- java.lang.Object
-
- discord4j.core.event.DefaultEventDispatcher.Builder
-
- All Implemented Interfaces:
EventDispatcher.Builder
- Direct Known Subclasses:
ReplayingEventDispatcher.Builder
- Enclosing class:
- DefaultEventDispatcher
public static class DefaultEventDispatcher.Builder extends Object implements EventDispatcher.Builder
A builder to createEventDispatcherinstances.
-
-
Field Summary
Fields Modifier and Type Field Description protected FluxProcessor<Event,Event>eventProcessorprotected SchedulereventSchedulerprotected FluxSink.OverflowStrategyoverflowStrategy
-
Constructor Summary
Constructors Modifier Constructor Description protectedBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EventDispatcherbuild()Create theEventDispatcherDefaultEventDispatcher.BuildereventProcessor(FluxProcessor<Event,Event> eventProcessor)Set the underlyingFluxProcessorthe dispatcher will use to queue and distribute events.DefaultEventDispatcher.BuildereventScheduler(Scheduler eventScheduler)Set theSchedulerthis dispatcher should use to publish events to its subscribers.SinksEventDispatcher.BuildereventSink(Function<Sinks.ManySpec,Sinks.Many<Event>> eventSinkFactory)Set the underlyingSinks.Manythe dispatcher will use to queue and distribute events.DefaultEventDispatcher.BuilderoverflowStrategy(FluxSink.OverflowStrategy overflowStrategy)Set theFluxSink.OverflowStrategyfor dealing with overflow scenarios where too many events are being published.
-
-
-
Field Detail
-
eventProcessor
protected FluxProcessor<Event,Event> eventProcessor
-
overflowStrategy
protected FluxSink.OverflowStrategy overflowStrategy
-
eventScheduler
protected Scheduler eventScheduler
-
-
Method Detail
-
eventSink
public SinksEventDispatcher.Builder eventSink(Function<Sinks.ManySpec,Sinks.Many<Event>> eventSinkFactory)
Description copied from interface:EventDispatcher.BuilderSet the underlyingSinks.Manythe dispatcher will use to queue and distribute events. Defaults to using a multicast buffering sink.- Specified by:
eventSinkin interfaceEventDispatcher.Builder- Parameters:
eventSinkFactory- the custom sink factory for events- Returns:
- this builder
-
eventProcessor
public DefaultEventDispatcher.Builder eventProcessor(FluxProcessor<Event,Event> eventProcessor)
Description copied from interface:EventDispatcher.BuilderSet the underlyingFluxProcessorthe dispatcher will use to queue and distribute events. Defaults to using anEmitterProcessor.Using
EmitterProcessoronly 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:
eventProcessorin interfaceEventDispatcher.Builder- Parameters:
eventProcessor- the custom processor for events- Returns:
- this builder
-
overflowStrategy
public DefaultEventDispatcher.Builder overflowStrategy(FluxSink.OverflowStrategy overflowStrategy)
Description copied from interface:EventDispatcher.BuilderSet theFluxSink.OverflowStrategyfor dealing with overflow scenarios where too many events are being published. Defaults to usingFluxSink.OverflowStrategy.BUFFERto ensure all events are delivered at the cost of higher memory footprint and potentialOutOfMemoryErrorscenarios.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:
overflowStrategyin interfaceEventDispatcher.Builder- Parameters:
overflowStrategy- the custom backpressure strategy- Returns:
- this builder
-
eventScheduler
public DefaultEventDispatcher.Builder eventScheduler(Scheduler eventScheduler)
Description copied from interface:EventDispatcher.BuilderSet theSchedulerthis 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:
eventSchedulerin interfaceEventDispatcher.Builder- Parameters:
eventScheduler- a customSchedulerto publish events- Returns:
- this builder
-
build
public EventDispatcher build()
Description copied from interface:EventDispatcher.BuilderCreate theEventDispatcher- Specified by:
buildin interfaceEventDispatcher.Builder- Returns:
- an
EventDispatcherwith the configured parameters.
-
-