
io.lettuce.core.event.DefaultEventBus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lettuce-core Show documentation
Show all versions of lettuce-core Show documentation
Advanced and thread-safe Java Redis client for synchronous, asynchronous, and
reactive usage. Supports Cluster, Sentinel, Pipelining, Auto-Reconnect, Codecs
and much more.
The newest version!
package io.lettuce.core.event;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;
import reactor.core.scheduler.Scheduler;
import io.lettuce.core.event.jfr.EventRecorder;
/**
* Default implementation for an {@link EventBus}. Events are published using a {@link Scheduler} and events are recorded
* through {@link EventRecorder#record(Event) EventRecorder}.
*
* @author Mark Paluch
* @since 3.4
*/
public class DefaultEventBus implements EventBus {
private final Sinks.Many bus;
private final Scheduler scheduler;
private final EventRecorder recorder = EventRecorder.getInstance();
public DefaultEventBus(Scheduler scheduler) {
this.bus = Sinks.many().multicast().directBestEffort();
this.scheduler = scheduler;
}
@Override
public Flux get() {
return bus.asFlux().onBackpressureDrop().publishOn(scheduler);
}
@Override
public void publish(Event event) {
recorder.record(event);
Sinks.EmitResult emitResult;
while ((emitResult = bus.tryEmitNext(event)) == Sinks.EmitResult.FAIL_NON_SERIALIZED) {
// busy-loop
}
if (emitResult != Sinks.EmitResult.FAIL_ZERO_SUBSCRIBER) {
emitResult.orThrow();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy