Class AbstractEventProcessor
- All Implemented Interfaces:
EventProcessor,MessageHandlerInterceptorSupport<EventMessage<?>>
- Direct Known Subclasses:
PooledStreamingEventProcessor,SubscribingEventProcessor,TrackingEventProcessor
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract Builder class to instantiate aAbstractEventProcessor. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aAbstractEventProcessorbased on the fields contained in theAbstractEventProcessor.Builder. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanHandle(EventMessage<?> eventMessage, Segment segment) Indicates whether the processor can/should handle the giveneventMessagefor the givensegment.protected booleancanHandleType(Class<?> payloadType) Returns the invoker assigned to this processor.List<MessageHandlerInterceptor<? super EventMessage<?>>> Return the list of already registeredMessageHandlerInterceptors for this event processor.getName()Returns the name of this event processor.protected final voidprocessInUnitOfWork(List<? extends EventMessage<?>> eventMessages, UnitOfWork<? extends EventMessage<?>> unitOfWork) Process a batch of events.protected voidprocessInUnitOfWork(List<? extends EventMessage<?>> eventMessages, UnitOfWork<? extends EventMessage<?>> unitOfWork, Collection<Segment> processingSegments) Process a batch of events.registerHandlerInterceptor(MessageHandlerInterceptor<? super EventMessage<?>> interceptor) Register the givenhandlerInterceptor.protected voidreportIgnored(EventMessage<?> eventMessage) Report the giveneventMessageas ignored.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.axonframework.eventhandling.EventProcessor
isError, isRunning, shutDown, shutdownAsync, start
-
Field Details
-
spanFactory
-
-
Constructor Details
-
AbstractEventProcessor
Instantiate aAbstractEventProcessorbased on the fields contained in theAbstractEventProcessor.Builder.Will assert that the Event Processor
name,EventHandlerInvokerandErrorHandlerare notnull, and will throw anAxonConfigurationExceptionif any of them isnull.- Parameters:
builder- theAbstractEventProcessor.Builderused to instantiate aAbstractEventProcessorinstance
-
-
Method Details
-
getName
Description copied from interface:EventProcessorReturns 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:
getNamein interfaceEventProcessor- Returns:
- the name of this event processor
-
registerHandlerInterceptor
public Registration registerHandlerInterceptor(@Nonnull MessageHandlerInterceptor<? super EventMessage<?>> interceptor) Description copied from interface:MessageHandlerInterceptorSupportRegister the givenhandlerInterceptor. 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:
registerHandlerInterceptorin interfaceMessageHandlerInterceptorSupport<EventMessage<?>>- Parameters:
interceptor- The interceptor to register- Returns:
- A Registration, which may be used to deregister the interceptor.
-
getHandlerInterceptors
Description copied from interface:EventProcessorReturn the list of already registeredMessageHandlerInterceptors for this event processor. To register a new interceptor useMessageHandlerInterceptorSupport.registerHandlerInterceptor(MessageHandlerInterceptor)- Specified by:
getHandlerInterceptorsin interfaceEventProcessor- Returns:
- the list of registered interceptors of this event processor
-
toString
-
canHandle
Indicates whether the processor can/should handle the giveneventMessagefor the givensegment.This implementation will delegate the decision to the
EventHandlerInvoker.- Parameters:
eventMessage- The message for which to identify if the processor can handle itsegment- The segment for which the event should be processed- Returns:
trueif the event message should be handled, otherwisefalse- Throws:
Exception- if theerrorHandlerthrows an Exception back on theErrorHandler.handleError(ErrorContext)call
-
canHandleType
-
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 newUnitOfWork. Before each message is handled the event processor creates an interceptor chain containing all registeredinterceptors.- Parameters:
eventMessages- The batch of messages that is to be processedunitOfWork- 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 newUnitOfWork. Before each message is handled the event processor creates an interceptor chain containing all registeredinterceptors.- Parameters:
eventMessages- The batch of messages that is to be processedunitOfWork- The Unit of Work that has been prepared to process the messagesprocessingSegments- 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
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
Report the giveneventMessageas ignored. Any registeredMessageMonitorshall 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.
-