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, Segment)
for processing.
Constructor and Description |
---|
AbstractEventProcessor(String name,
EventHandlerInvoker eventHandlerInvoker,
RollbackConfiguration rollbackConfiguration,
ErrorHandler errorHandler,
MessageMonitor<? super EventMessage<?>> messageMonitor)
Initializes an event processor with given
name . |
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 EventHandlerInvoker |
eventHandlerInvoker()
Returns the invoker assigned to this processor.
|
String |
getName()
Returns the name of this event processor.
|
protected void |
processInUnitOfWork(List<? extends EventMessage<?>> eventMessages,
UnitOfWork<? extends EventMessage<?>> unitOfWork,
Segment segment)
Process a batch of events.
|
Registration |
registerInterceptor(MessageHandlerInterceptor<? super EventMessage<?>> interceptor)
Registers the given
interceptor to this event processor. |
protected void |
reportIgnored(EventMessage<?> eventMessage)
Report the given
eventMessage as ignored. |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
shutDown, start
public AbstractEventProcessor(String name, EventHandlerInvoker eventHandlerInvoker, RollbackConfiguration rollbackConfiguration, ErrorHandler errorHandler, MessageMonitor<? super EventMessage<?>> messageMonitor)
name
. Actual handling of event messages is deferred to the
given eventHandlerInvoker
.name
- The name of the event processoreventHandlerInvoker
- The component that handles the individual eventsrollbackConfiguration
- Determines rollback behavior of the UnitOfWork while processing a batch of eventserrorHandler
- Invoked when a UnitOfWork is rolled back during processing. If null
a PropagatingErrorHandler
is used.messageMonitor
- Monitor to be invoked before and after event processing. If null
a NoOpMessageMonitor
is used.public String getName()
EventProcessor
getName
in interface EventProcessor
public Registration registerInterceptor(MessageHandlerInterceptor<? super EventMessage<?>> interceptor)
EventProcessor
interceptor
to this event processor. The interceptor
will
receive each event message that is about to be published but before it has reached its event handlers.
Interceptors are free to modify the event message or stop publication altogether. In
addition, interceptors are able to interact with the UnitOfWork
that is created to process the message.
For example, if a CorrelationDataInterceptor
is registered,
each command or event message triggered in response to an intercepted event will get correlation metadata
from the intercepted event.registerInterceptor
in interface EventProcessor
interceptor
- The interceptor to register.interceptor
. When unregistered the interceptor
will
no longer receive events from this event processor.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 void processInUnitOfWork(List<? extends EventMessage<?>> eventMessages, UnitOfWork<? extends EventMessage<?>> unitOfWork, Segment segment) 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 messagessegment
- The segment for which the events should be processedException
- when an exception occurred during processing of the batchprotected 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–2018. All rights reserved.