public class EventBus extends java.lang.Object implements Bus<Event<?>>, reactor.fn.Consumer<Event<?>>
Event Consumers that can
subsequently be notified of events. A consumer is typically registered with a Selector which, by matching on
the notification key, governs which events the consumer will receive. When a Reactor is notified of
an Event, a task is dispatched using the reactor's Dispatcher which causes it to be executed on a
thread based on the implementation of the Dispatcher being used.| Modifier and Type | Class and Description |
|---|---|
class |
EventBus.ReplyToConsumer<E extends Event<?>,V> |
static class |
EventBus.ReplyToEvent<T> |
| Constructor and Description |
|---|
EventBus(reactor.core.Dispatcher dispatcher)
Create a new Reactor that uses the given
Dispatcher. |
EventBus(reactor.core.Dispatcher dispatcher,
Router router)
Create a new Reactor that uses the given
Dispatcher. |
EventBus(reactor.core.Dispatcher dispatcher,
Router router,
reactor.fn.Consumer<java.lang.Throwable> dispatchErrorHandler,
reactor.fn.Consumer<java.lang.Throwable> uncaughtErrorHandler) |
EventBus(Registry<reactor.fn.Consumer<? extends Event<?>>> consumerRegistry,
reactor.core.Dispatcher dispatcher,
Router router,
reactor.fn.Consumer<java.lang.Throwable> dispatchErrorHandler,
reactor.fn.Consumer<java.lang.Throwable> uncaughtErrorHandler)
Create a new Reactor that uses the given
dispatacher and eventRouter. |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(Event<?> event) |
static EventBusSpec |
config()
Create a new
EventBusSpec to configure a Reactor. |
static EventBus |
create()
Create a new synchronous
EventBus |
static EventBus |
create(reactor.core.Dispatcher dispatcher)
Create a new
EventBus using the given Dispatcher. |
static EventBus |
create(reactor.Environment env)
Create a new
EventBus using the given Environment. |
static EventBus |
create(reactor.Environment env,
reactor.core.Dispatcher dispatcher)
|
static EventBus |
create(reactor.Environment env,
java.lang.String dispatcher)
Create a new
EventBus using the given Environment and dispatcher name. |
Registry<reactor.fn.Consumer<? extends Event<?>>> |
getConsumerRegistry()
Get the
Registry is use to maintain the Consumers currently listening for events on this Reactor. |
reactor.core.Dispatcher |
getDispatcher()
Get the
Dispatcher currently in use. |
reactor.fn.Consumer<java.lang.Throwable> |
getDispatchErrorHandler() |
java.util.UUID |
getId()
Get the unique, time-used
UUID of this Reactor. |
Router |
getRouter()
Get the
Router used to route events to Consumers. |
reactor.fn.Consumer<java.lang.Throwable> |
getUncaughtErrorHandler() |
EventBus |
notify(java.lang.Object key)
Notify this component that the consumers registered with a
Selector that matches the key should be
triggered with a null input argument. |
EventBus |
notify(java.lang.Object key,
Event<?> ev)
Notify this component that an
Event is ready to be processed. |
EventBus |
notify(java.lang.Object key,
reactor.fn.Supplier<? extends Event<?>> supplier)
Notify this component that the given
Supplier can provide an event that's ready to be
processed. |
EventBus |
notify(org.reactivestreams.Publisher<?> source,
java.lang.Object key)
Pass values accepted by this
Stream into the given Bus, notifying with the given key. |
<T> EventBus |
notify(org.reactivestreams.Publisher<? extends T> source,
reactor.fn.Function<? super T,?> keyMapper)
Pass values accepted by this
Stream into the given Bus, notifying with the given key. |
org.reactivestreams.Publisher<? extends Event<?>> |
on(Selector broadcastSelector)
|
<T extends Event<?>> |
on(Selector selector,
reactor.fn.Consumer<T> consumer)
Register a
Consumer to be triggered when a notification matches the given Selector. |
<T> reactor.fn.Consumer<Event<T>> |
prepare(java.lang.Object key)
Create an optimized path for publishing notifications to the given key.
|
<T extends Event<?>,V> |
receive(Selector sel,
reactor.fn.Function<T,V> fn)
Assign a
Function to receive an Event and produce a reply of the given type. |
boolean |
respondsToKey(java.lang.Object key)
|
<T> void |
schedule(reactor.fn.Consumer<T> consumer,
T data)
Schedule an arbitrary
Consumer to be executed on the current Reactor Dispatcher, passing the given . |
EventBus |
send(java.lang.Object key,
Event<?> ev)
|
EventBus |
send(java.lang.Object key,
Event<?> ev,
Bus replyTo)
|
EventBus |
send(java.lang.Object key,
reactor.fn.Supplier<? extends Event<?>> supplier)
|
EventBus |
send(java.lang.Object key,
reactor.fn.Supplier<? extends Event<?>> supplier,
Bus replyTo)
|
<T extends Event<?>> |
sendAndReceive(java.lang.Object key,
Event<?> event,
reactor.fn.Consumer<T> reply)
Register the given
Consumer on an anonymous Selector and
set the given event's replyTo property to the corresponding anonymous key, then register the consumer to
receive replies from the Function assigned to handle the given key. |
<T extends Event<?>> |
sendAndReceive(java.lang.Object key,
reactor.fn.Supplier<? extends Event<?>> supplier,
reactor.fn.Consumer<T> reply)
Register the given
Consumer on an anonymous Selector and
set the event's replyTo property to the corresponding anonymous key, then register the consumer to receive
replies from the Function assigned to handle the given key. |
public EventBus(@Nullable
reactor.core.Dispatcher dispatcher)
Dispatcher. The reactor will use a default Router that broadcast events to all of the registered consumers that match
the notification key and does not perform any type conversion.dispatcher - The Dispatcher to use. May be null in which case a new SynchronousDispatcher is usedpublic EventBus(@Nullable
reactor.core.Dispatcher dispatcher,
@Nullable
Router router)
Dispatcher. The reactor will use a default CachingRegistry.dispatcher - The Dispatcher to use. May be null in which case a new synchronous dispatcher
is used.router - The Router used to route events to Consumers. May be null in
which case the
default event router that broadcasts events to all of the registered consumers that match the notification key and does not perform any type conversion
will be used.public EventBus(@Nullable
reactor.core.Dispatcher dispatcher,
@Nullable
Router router,
@Nullable
reactor.fn.Consumer<java.lang.Throwable> dispatchErrorHandler,
@Nullable
reactor.fn.Consumer<java.lang.Throwable> uncaughtErrorHandler)
public EventBus(@Nonnull
Registry<reactor.fn.Consumer<? extends Event<?>>> consumerRegistry,
@Nullable
reactor.core.Dispatcher dispatcher,
@Nullable
Router router,
@Nullable
reactor.fn.Consumer<java.lang.Throwable> dispatchErrorHandler,
@Nullable
reactor.fn.Consumer<java.lang.Throwable> uncaughtErrorHandler)
dispatacher and eventRouter.dispatcher - The Dispatcher to use. May be null in which case a new synchronous
dispatcher is used.router - The Router used to route events to Consumers. May be null in which case the
default event router that broadcasts events to all of the registered consumers that match the notification key and does not perform any type
conversion will be used.consumerRegistry - The Registry to be used to match Selector and dispatch to Consumer.public static EventBusSpec config()
EventBusSpec to configure a Reactor.public static EventBus create(reactor.Environment env)
EventBus using the given Environment.env - The Environment to use.EventBuspublic static EventBus create(reactor.core.Dispatcher dispatcher)
EventBus using the given Dispatcher.dispatcher - The name of the Dispatcher to use.EventBuspublic static EventBus create(reactor.Environment env, java.lang.String dispatcher)
EventBus using the given Environment and dispatcher name.env - The Environment to use.dispatcher - The name of the Dispatcher to use.EventBuspublic static EventBus create(reactor.Environment env, reactor.core.Dispatcher dispatcher)
env - The Environment to use.dispatcher - The Dispatcher to use.EventBuspublic java.util.UUID getId()
UUID of this Reactor.UUID of this Reactor.public Registry<reactor.fn.Consumer<? extends Event<?>>> getConsumerRegistry()
Registry is use to maintain the Consumers currently listening for events on this Reactor.Registry in use.public reactor.core.Dispatcher getDispatcher()
Dispatcher currently in use.Dispatcher.public Router getRouter()
Router used to route events to Consumers.Router.public reactor.fn.Consumer<java.lang.Throwable> getDispatchErrorHandler()
public reactor.fn.Consumer<java.lang.Throwable> getUncaughtErrorHandler()
public boolean respondsToKey(java.lang.Object key)
BusrespondsToKey in interface Bus<Event<?>>key - The key to be matched by Selectorspublic <T extends Event<?>> Registration<reactor.fn.Consumer<? extends Event<?>>> on(Selector selector, reactor.fn.Consumer<T> consumer)
BusConsumer to be triggered when a notification matches the given Selector.on in interface Bus<Event<?>>selector - The Selector to be used for matchingconsumer - The Consumer to be triggeredRegistration object that allows the caller to interact with the given mappingpublic org.reactivestreams.Publisher<? extends Event<?>> on(Selector broadcastSelector)
broadcastSelector - the Selector/Object tuple to listen toPublisherpublic EventBus notify(java.lang.Object key, Event<?> ev)
BusEvent is ready to be processed.public final EventBus notify(@Nonnull org.reactivestreams.Publisher<?> source, @Nonnull java.lang.Object key)
Stream into the given Bus, notifying with the given key.key - the key to notify onsource - the Publisher to consumepublic final <T> EventBus notify(@Nonnull org.reactivestreams.Publisher<? extends T> source, @Nonnull reactor.fn.Function<? super T,?> keyMapper)
Stream into the given Bus, notifying with the given key.source - the Publisher to consumekeyMapper - the key function mapping each incoming data to a key to notify onpublic <T extends Event<?>,V> Registration<reactor.fn.Consumer<? extends Event<?>>> receive(Selector sel, reactor.fn.Function<T,V> fn)
Function to receive an Event and produce a reply of the given type.sel - The Selector to be used for matchingfn - The transformative Function to call to receive an EventRegistration object that allows the caller to interact with the given mappingpublic EventBus notify(java.lang.Object key, reactor.fn.Supplier<? extends Event<?>> supplier)
Supplier can provide an event that's ready to be
processed.public EventBus notify(java.lang.Object key)
Selector that matches the key should be
triggered with a null input argument.key - The key to be matched by Selectorspublic EventBus send(java.lang.Object key, Event<?> ev)
Event and register an internal Consumer that will take the
output of a previously-registered Function and respond using the key set on the Event's replyTo property.key - The key to be matched by Selectorsev - The Eventpublic EventBus send(java.lang.Object key, reactor.fn.Supplier<? extends Event<?>> supplier, Bus replyTo)
public <T extends Event<?>> EventBus sendAndReceive(java.lang.Object key, Event<?> event, reactor.fn.Consumer<T> reply)
Consumer on an anonymous Selector and
set the given event's replyTo property to the corresponding anonymous key, then register the consumer to
receive replies from the Function assigned to handle the given key.key - The key to be matched by Selectorsevent - The event to notify.reply - The consumer to register as a reply handler.public <T extends Event<?>> EventBus sendAndReceive(java.lang.Object key, reactor.fn.Supplier<? extends Event<?>> supplier, reactor.fn.Consumer<T> reply)
Consumer on an anonymous Selector and
set the event's replyTo property to the corresponding anonymous key, then register the consumer to receive
replies from the Function assigned to handle the given key.key - The key to be matched by Selectorssupplier - The supplier to supply the event.reply - The consumer to register as a reply handler.public <T> reactor.fn.Consumer<Event<T>> prepare(java.lang.Object key)
public <T> void schedule(reactor.fn.Consumer<T> consumer,
T data)
Consumer to be executed on the current Reactor Dispatcher, passing the given .T - The type of the data.consumer - The Consumer to invoke.data - The data to pass to the consumer.