Class AbstractEventBus

java.lang.Object
org.axonframework.eventhandling.AbstractEventBus
All Implemented Interfaces:
EventBus, MessageDispatchInterceptorSupport<EventMessage<?>>, SubscribableMessageSource<EventMessage<?>>
Direct Known Subclasses:
AbstractEventStore, SimpleEventBus

public abstract class AbstractEventBus extends Object implements EventBus
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
  • Constructor Details

  • Method Details

    • subscribe

      public Registration subscribe(@Nonnull Consumer<List<? extends EventMessage<?>>> eventProcessor)
      Description copied from interface: SubscribableMessageSource
      Subscribe the given messageProcessor to this message source. When subscribed, it will receive all messages published to this source.

      If the given messageProcessor is already subscribed, nothing happens.

      Specified by:
      subscribe in interface SubscribableMessageSource<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, the preprocessor is not invoked by this Event Bus until the Unit of Work root is committed.

      Specified by:
      registerDispatchInterceptor in interface MessageDispatchInterceptorSupport<EventMessage<?>>
      Parameters:
      dispatchInterceptor -
      Returns:
      A Registration, which may be used to deregister the interceptor.
    • publish

      public void publish(@Nonnull List<? extends EventMessage<?>> events)
      Description copied from interface: EventBus
      Publish a collection of events on this bus (one, or multiple). The events will be dispatched to all subscribed listeners.

      Implementations may treat the given events as a single batch and distribute the events as such to all subscribed EventListeners.

      Specified by:
      publish in interface EventBus
      Parameters:
      events - The collection of events to publish
    • queuedMessages

      protected List<EventMessage<?>> 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

      protected List<? extends EventMessage<?>> intercept(List<? extends EventMessage<?>> events)
      Invokes all the dispatch interceptors.
      Parameters:
      events - The original events being published
      Returns:
      The events to actually publish
    • prepareCommit

      protected void prepareCommit(List<? extends EventMessage<?>> events)
      Process given events while the Unit of Work root is preparing for commit. The default implementation signals the registered MessageMonitor that 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

      protected void commit(List<? extends EventMessage<?>> events)
      Process given events while the Unit of Work root is being committed. The default implementation does nothing.
      Parameters:
      events - Events to be published by this Event Bus
    • afterCommit

      protected void afterCommit(List<? extends EventMessage<?>> events)
      Process given events after the Unit of Work has been committed. The default implementation does nothing.
      Parameters:
      events - Events to be published by this Event Bus