Package com.couchbase.client.core.cnc
Class DefaultEventBus
- java.lang.Object
-
- com.couchbase.client.core.cnc.DefaultEventBus
-
- All Implemented Interfaces:
EventBus
public class DefaultEventBus extends Object implements EventBus
TheDefaultEventBus
provides the default and very efficient implementation of theEventBus
.It is built on top of a very fast, bounded MPSC (multi-producer single-consumer) queue which allows to quickly send events into the bus without blocking the sender.
Subscribers of this API are considered to be non-blocking and if they have to blocking tasks need to fan them out into their own thread pool.
Keep in mind to properly
start()
andstop(Duration)
since it runs in its own thread!
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultEventBus.Builder
Allows to modify the default configuration of theDefaultEventBus
.-
Nested classes/interfaces inherited from interface com.couchbase.client.core.cnc.EventBus
EventBus.PublishResult
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DefaultEventBus.Builder
builder(Scheduler scheduler)
static DefaultEventBus
create(Scheduler scheduler)
EventBus.PublishResult
publish(Event event)
Try to publish an event.Mono<Void>
start()
Starts theDefaultEventBus
.Mono<Void>
stop(Duration timeout)
Stops theDefaultEventBus
from running.EventSubscription
subscribe(Consumer<Event> consumer)
void
unsubscribe(EventSubscription subscription)
-
-
-
Method Detail
-
builder
public static DefaultEventBus.Builder builder(Scheduler scheduler)
-
create
public static DefaultEventBus create(Scheduler scheduler)
-
subscribe
public EventSubscription subscribe(Consumer<Event> consumer)
Description copied from interface:EventBus
- Specified by:
subscribe
in interfaceEventBus
- Parameters:
consumer
- the consumer which will receive events.- Returns:
- a
EventSubscription
that can be used to unsubscribe.
-
unsubscribe
public void unsubscribe(EventSubscription subscription)
Description copied from interface:EventBus
- Specified by:
unsubscribe
in interfaceEventBus
- Parameters:
subscription
- the subscription used.
-
publish
public EventBus.PublishResult publish(Event event)
Description copied from interface:EventBus
Try to publish an event.- Specified by:
publish
in interfaceEventBus
- Parameters:
event
- the event to publish.- Returns:
- the
EventBus.PublishResult
of th event.
-
start
public Mono<Void> start()
Starts theDefaultEventBus
.
-
-