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
TheDefaultEventBusprovides 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 classDefaultEventBus.BuilderAllows 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.Builderbuilder(Scheduler scheduler)static DefaultEventBuscreate(Scheduler scheduler)EventBus.PublishResultpublish(Event event)Try to publish an event.Mono<Void>start()Starts theDefaultEventBus.Mono<Void>stop(Duration timeout)Stops theDefaultEventBusfrom running.EventSubscriptionsubscribe(Consumer<Event> consumer)voidunsubscribe(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:
subscribein interfaceEventBus- Parameters:
consumer- the consumer which will receive events.- Returns:
- a
EventSubscriptionthat can be used to unsubscribe.
-
unsubscribe
public void unsubscribe(EventSubscription subscription)
Description copied from interface:EventBus- Specified by:
unsubscribein interfaceEventBus- Parameters:
subscription- the subscription used.
-
publish
public EventBus.PublishResult publish(Event event)
Description copied from interface:EventBusTry to publish an event.- Specified by:
publishin interfaceEventBus- Parameters:
event- the event to publish.- Returns:
- the
EventBus.PublishResultof th event.
-
start
public Mono<Void> start()
Starts theDefaultEventBus.
-
-