public abstract class AbstractEventProcessor extends Object implements EventProcessor
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.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractEventProcessor.Builder
Abstract Builder class to instantiate a
AbstractEventProcessor . |
Modifier | Constructor and Description |
---|---|
protected |
AbstractEventProcessor(AbstractEventProcessor.Builder builder)
Instantiate a
AbstractEventProcessor based on the fields contained in the AbstractEventProcessor.Builder . |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canHandle(EventMessage<?> eventMessage,
Segment segment)
Indicates whether the processor can/should handle the given
eventMessage for the given segment . |
protected boolean |
canHandleType(Class<?> payloadType) |
EventHandlerInvoker |
eventHandlerInvoker()
Returns the invoker assigned to this processor.
|
List<MessageHandlerInterceptor<? super EventMessage<?>>> |
getHandlerInterceptors()
Return the list of already registered
MessageHandlerInterceptor s for this event processor. |
String |
getName()
Returns the name of this event processor.
|
protected void |
processInUnitOfWork(List<? extends EventMessage<?>> eventMessages,
UnitOfWork<? extends EventMessage<?>> unitOfWork)
Process a batch of events.
|
protected void |
processInUnitOfWork(List<? extends EventMessage<?>> eventMessages,
UnitOfWork<? extends EventMessage<?>> unitOfWork,
Collection<Segment> processingSegments)
Process a batch of events.
|
Registration |
registerHandlerInterceptor(MessageHandlerInterceptor<? super EventMessage<?>> interceptor)
Register the given
handlerInterceptor . |
protected void |
reportIgnored(EventMessage<?> eventMessage)
Report the given
eventMessage as ignored. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
shutDown, shutdownAsync, start
protected AbstractEventProcessor(AbstractEventProcessor.Builder builder)
AbstractEventProcessor
based on the fields contained in the AbstractEventProcessor.Builder
.
Will assert that the Event Processor name
, EventHandlerInvoker
and ErrorHandler
are not
null
, and will throw an AxonConfigurationException
if any of them is null
.
builder
- the AbstractEventProcessor.Builder
used to instantiate a AbstractEventProcessor
instancepublic String getName()
EventProcessor
getName
in interface EventProcessor
public Registration registerHandlerInterceptor(MessageHandlerInterceptor<? super EventMessage<?>> interceptor)
MessageHandlerInterceptorSupport
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.registerHandlerInterceptor
in interface MessageHandlerInterceptorSupport<EventMessage<?>>
interceptor
- The interceptor to registerpublic List<MessageHandlerInterceptor<? super EventMessage<?>>> getHandlerInterceptors()
EventProcessor
MessageHandlerInterceptor
s for this event processor.
To register a new interceptor use MessageHandlerInterceptorSupport.registerHandlerInterceptor(MessageHandlerInterceptor)
getHandlerInterceptors
in interface EventProcessor
protected boolean canHandle(EventMessage<?> eventMessage, Segment segment) throws Exception
eventMessage
for the given segment
.
This implementation will delegate the decision to the EventHandlerInvoker
.
eventMessage
- The message for which to identify if the processor can handle itsegment
- The segment for which the event should be processedtrue
if the event message should be handled, otherwise false
Exception
- if the errorHandler
throws an Exception back on the
ErrorHandler.handleError(ErrorContext)
callprotected boolean canHandleType(Class<?> payloadType)
protected final void processInUnitOfWork(List<? extends EventMessage<?>> eventMessages, UnitOfWork<? extends EventMessage<?>> unitOfWork) throws Exception
UnitOfWork
. Before each message is handled
the event processor creates an interceptor chain containing all registered interceptors
.eventMessages
- The batch of messages that is to be processedunitOfWork
- The Unit of Work that has been prepared to process the messagesException
- when an exception occurred during processing of the batchprotected void processInUnitOfWork(List<? extends EventMessage<?>> eventMessages, UnitOfWork<? extends EventMessage<?>> unitOfWork, Collection<Segment> processingSegments) throws Exception
UnitOfWork
. Before each message is handled
the event processor creates an interceptor chain containing all registered interceptors
.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 workException
- when an exception occurred during processing of the batchpublic EventHandlerInvoker eventHandlerInvoker()
protected void reportIgnored(EventMessage<?> eventMessage)
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.
eventMessage
- the message that has been ignored.Copyright © 2010–2020. All rights reserved.