Class AbstractEventProcessor

java.lang.Object
org.axonframework.eventhandling.AbstractEventProcessor
All Implemented Interfaces:
EventProcessor, MessageHandlerInterceptorSupport<EventMessage<?>>
Direct Known Subclasses:
PooledStreamingEventProcessor, SubscribingEventProcessor, TrackingEventProcessor

public abstract class AbstractEventProcessor extends Object implements EventProcessor
Abstract implementation of an EventProcessor. Before processing of a batch of messages this implementation creates a Unit of Work to process the batch.

Actual handling of events is deferred to an EventHandlerInvoker. Before each message is handled by the invoker this event processor creates an interceptor chain containing all registered interceptors.

Implementations are in charge of providing the events that need to be processed. Once these events are obtained they can be passed to method processInUnitOfWork(List, UnitOfWork, Collection) for processing.

Since:
3.0
Author:
Rene de Waele
  • Field Details

  • Constructor Details

  • Method Details

    • getName

      public String getName()
      Description copied from interface: EventProcessor
      Returns the name of this event processor. This name is used to detect distributed instances of the same event processor. Multiple instances referring to the same logical event processor (on different JVM's) must have the same name.
      Specified by:
      getName in interface EventProcessor
      Returns:
      the name of this event processor
    • registerHandlerInterceptor

      public Registration registerHandlerInterceptor(@Nonnull MessageHandlerInterceptor<? super EventMessage<?>> interceptor)
      Description copied from interface: MessageHandlerInterceptorSupport
      Register the given handlerInterceptor. After registration, the interceptor will be invoked for each handled Message on the messaging component that it was registered to, prior to invoking the message's handler.
      Specified by:
      registerHandlerInterceptor in interface MessageHandlerInterceptorSupport<EventMessage<?>>
      Parameters:
      interceptor - The interceptor to register
      Returns:
      A Registration, which may be used to deregister the interceptor.
    • getHandlerInterceptors

      public List<MessageHandlerInterceptor<? super EventMessage<?>>> getHandlerInterceptors()
      Description copied from interface: EventProcessor
      Return the list of already registered MessageHandlerInterceptors for this event processor. To register a new interceptor use MessageHandlerInterceptorSupport.registerHandlerInterceptor(MessageHandlerInterceptor)
      Specified by:
      getHandlerInterceptors in interface EventProcessor
      Returns:
      the list of registered interceptors of this event processor
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • canHandle

      protected boolean canHandle(EventMessage<?> eventMessage, Segment segment) throws Exception
      Indicates whether the processor can/should handle the given eventMessage for the given segment.

      This implementation will delegate the decision to the EventHandlerInvoker.

      Parameters:
      eventMessage - The message for which to identify if the processor can handle it
      segment - The segment for which the event should be processed
      Returns:
      true if the event message should be handled, otherwise false
      Throws:
      Exception - if the errorHandler throws an Exception back on the ErrorHandler.handleError(ErrorContext) call
    • canHandleType

      protected boolean canHandleType(Class<?> payloadType)
    • processInUnitOfWork

      protected final void processInUnitOfWork(List<? extends EventMessage<?>> eventMessages, UnitOfWork<? extends EventMessage<?>> unitOfWork) throws Exception
      Process a batch of events. The messages are processed in a new UnitOfWork. Before each message is handled the event processor creates an interceptor chain containing all registered interceptors.
      Parameters:
      eventMessages - The batch of messages that is to be processed
      unitOfWork - The Unit of Work that has been prepared to process the messages
      Throws:
      Exception - when an exception occurred during processing of the batch
    • processInUnitOfWork

      protected void processInUnitOfWork(List<? extends EventMessage<?>> eventMessages, UnitOfWork<? extends EventMessage<?>> unitOfWork, Collection<Segment> processingSegments) throws Exception
      Process a batch of events. The messages are processed in a new UnitOfWork. Before each message is handled the event processor creates an interceptor chain containing all registered interceptors.
      Parameters:
      eventMessages - The batch of messages that is to be processed
      unitOfWork - The Unit of Work that has been prepared to process the messages
      processingSegments - The segments for which the events should be processed in this unit of work
      Throws:
      Exception - when an exception occurred during processing of the batch
    • eventHandlerInvoker

      public EventHandlerInvoker eventHandlerInvoker()
      Returns the invoker assigned to this processor. The invoker is responsible for invoking the correct handler methods for any given message.
      Returns:
      the invoker assigned to this processor
    • reportIgnored

      protected void reportIgnored(EventMessage<?> eventMessage)
      Report the given eventMessage as ignored. Any registered MessageMonitor shall be notified of the ignored message.

      Typically, messages are ignored when they are received by a processor that has no suitable Handler for the type of Event received.

      Parameters:
      eventMessage - the message that has been ignored.