Package org.axonframework.eventhandling
Class AbstractEventBus
java.lang.Object
org.axonframework.eventhandling.AbstractEventBus
- All Implemented Interfaces:
EventBus,MessageDispatchInterceptorSupport<EventMessage<?>>,SubscribableMessageSource<EventMessage<?>>
- Direct Known Subclasses:
AbstractEventStore,SimpleEventBus
Base class for the Event Bus. In case events are published while a Unit of Work is active the Unit of Work root
coordinates the timing and order of the publication.
This implementation of the EventBus directly forwards all published events (in the callers' thread) to
subscribed event processors.
- Since:
- 3.0
- Author:
- Allard Buijze, René de Waele
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract Builder class to instantiateAbstractEventBusimplementations. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractEventBus(AbstractEventBus.Builder builder) Instantiate anAbstractEventBusbased on the fields contained in theAbstractEventBus.Builder. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterCommit(List<? extends EventMessage<?>> events) Process giveneventsafter the Unit of Work has been committed.protected voidcommit(List<? extends EventMessage<?>> events) Process giveneventswhile the Unit of Work root is being committed.protected List<? extends EventMessage<?>> intercept(List<? extends EventMessage<?>> events) Invokes all the dispatch interceptors.protected voidprepareCommit(List<? extends EventMessage<?>> events) Process giveneventswhile the Unit of Work root is preparing for commit.voidpublish(List<? extends EventMessage<?>> events) Publish a collection of events on this bus (one, or multiple).protected List<EventMessage<?>> Returns a list of all the events staged for publication in this Unit of Work.registerDispatchInterceptor(MessageDispatchInterceptor<? super EventMessage<?>> dispatchInterceptor) Register the given DispatchInterceptor.subscribe(Consumer<List<? extends EventMessage<?>>> eventProcessor) Subscribe the givenmessageProcessorto this message source.
-
Constructor Details
-
AbstractEventBus
Instantiate anAbstractEventBusbased on the fields contained in theAbstractEventBus.Builder.- Parameters:
builder- theAbstractEventBus.Builderused to instantiate anAbstractEventBusinstance
-
-
Method Details
-
subscribe
Description copied from interface:SubscribableMessageSourceSubscribe the givenmessageProcessorto this message source. When subscribed, it will receive all messages published to this source.If the given
messageProcessoris already subscribed, nothing happens.- Specified by:
subscribein interfaceSubscribableMessageSource<EventMessage<?>>- Parameters:
eventProcessor- The message processor to subscribe- Returns:
- a handle to unsubscribe the
messageProcessor. When unsubscribed it will no longer receive messages.
-
registerDispatchInterceptor
public Registration registerDispatchInterceptor(@Nonnull MessageDispatchInterceptor<? super EventMessage<?>> dispatchInterceptor) Register the given DispatchInterceptor. After registration, the interceptor will be invoked for each Message dispatched on the messaging component that it was registered to. In case a Unit of Work is active, thepreprocessoris not invoked by this Event Bus until the Unit of Work root is committed.- Specified by:
registerDispatchInterceptorin interfaceMessageDispatchInterceptorSupport<EventMessage<?>>- Parameters:
dispatchInterceptor-- Returns:
- A Registration, which may be used to deregister the interceptor.
-
publish
Description copied from interface:EventBusPublish a collection of events on this bus (one, or multiple). The events will be dispatched to all subscribed listeners.Implementations may treat the given
eventsas a single batch and distribute the events as such to all subscribed EventListeners. -
queuedMessages
Returns a list of all the events staged for publication in this Unit of Work. Changing this list will not affect the publication of events.- Returns:
- a list of all the events staged for publication
-
intercept
Invokes all the dispatch interceptors.- Parameters:
events- The original events being published- Returns:
- The events to actually publish
-
prepareCommit
Process giveneventswhile the Unit of Work root is preparing for commit. The default implementation signals the registeredMessageMonitorthat the given events are ingested and passes the events to each registered event processor.- Parameters:
events- Events to be published by this Event Bus
-
commit
Process giveneventswhile the Unit of Work root is being committed. The default implementation does nothing.- Parameters:
events- Events to be published by this Event Bus
-
afterCommit
Process giveneventsafter the Unit of Work has been committed. The default implementation does nothing.- Parameters:
events- Events to be published by this Event Bus
-