Package org.axonframework.eventhandling
Class AnnotationEventHandlerAdapter
java.lang.Object
org.axonframework.eventhandling.AnnotationEventHandlerAdapter
- All Implemented Interfaces:
EventMessageHandler,MessageHandler<EventMessage<?>>
Adapter that turns any bean with
EventHandler annotated methods into an EventMessageHandler.- Since:
- 0.1
- Author:
- Allard Buijze
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAnnotationEventHandlerAdapter(Object annotatedEventListener) Wraps the givenannotatedEventListener, allowing it to be subscribed to an Event Bus.AnnotationEventHandlerAdapter(Object annotatedEventListener, ParameterResolverFactory parameterResolverFactory) Wraps the givenannotatedEventListener, allowing it to be subscribed to an Event Bus.AnnotationEventHandlerAdapter(Object annotatedEventListener, ParameterResolverFactory parameterResolverFactory, HandlerDefinition handlerDefinition) Wraps the givenannotatedEventListener, allowing it to be subscribed to an Event Bus. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanHandle(EventMessage<?> event) Indicates whether this handler can handle the given messagebooleancanHandleType(Class<?> payloadType) Indicates whether this handler can handle messages of given typeClass<?> Returns the instance type that this handler delegates to.handle(EventMessage<?> event) Process the given event.voidPerforms any activities that are required to reset the state managed by handlers assigned to this handler.<R> voidprepareReset(R resetContext) Performs any activities that are required to reset the state managed by handlers assigned to this handler.booleanIndicates whether the handlers managed by this invoker support a reset.
-
Constructor Details
-
AnnotationEventHandlerAdapter
Wraps the givenannotatedEventListener, allowing it to be subscribed to an Event Bus.- Parameters:
annotatedEventListener- the annotated event listener
-
AnnotationEventHandlerAdapter
public AnnotationEventHandlerAdapter(Object annotatedEventListener, ParameterResolverFactory parameterResolverFactory) Wraps the givenannotatedEventListener, allowing it to be subscribed to an Event Bus. The givenparameterResolverFactoryis used to resolve parameter values for handler methods.- Parameters:
annotatedEventListener- the annotated event listenerparameterResolverFactory- the strategy for resolving handler method parameter values
-
AnnotationEventHandlerAdapter
public AnnotationEventHandlerAdapter(Object annotatedEventListener, ParameterResolverFactory parameterResolverFactory, HandlerDefinition handlerDefinition) Wraps the givenannotatedEventListener, allowing it to be subscribed to an Event Bus. The givenparameterResolverFactoryis used to resolve parameter values for handler methods. Handler definition is used to create concrete handlers.- Parameters:
annotatedEventListener- the annotated event listenerparameterResolverFactory- the strategy for resolving handler method parameter valueshandlerDefinition- the handler definition used to create concrete handlers
-
-
Method Details
-
handle
Description copied from interface:EventMessageHandlerProcess the given event. The implementation may decide to process or skip the given event. It is highly unrecommended to throw any exception during the event handling process.- Specified by:
handlein interfaceEventMessageHandler- Specified by:
handlein interfaceMessageHandler<EventMessage<?>>- Parameters:
event- the event to handle- Returns:
- the result of the event handler invocation. Is generally ignored
- Throws:
Exception- when an exception is raised during event handling
-
canHandle
Description copied from interface:MessageHandlerIndicates whether this handler can handle the given message- Specified by:
canHandlein interfaceMessageHandler<EventMessage<?>>- Parameters:
event- The message to verify- Returns:
trueif this handler can handle the message, otherwisefalse
-
canHandleType
Description copied from interface:MessageHandlerIndicates whether this handler can handle messages of given type- Specified by:
canHandleTypein interfaceMessageHandler<EventMessage<?>>- Parameters:
payloadType- The payloadType to verify- Returns:
trueif this handler can handle the payloadType, otherwisefalse
-
getTargetType
Description copied from interface:MessageHandlerReturns the instance type that this handler delegates to.- Specified by:
getTargetTypein interfaceMessageHandler<EventMessage<?>>- Returns:
- Returns the instance type that this handler delegates to
-
prepareReset
public void prepareReset()Description copied from interface:EventMessageHandlerPerforms any activities that are required to reset the state managed by handlers assigned to this handler.- Specified by:
prepareResetin interfaceEventMessageHandler
-
prepareReset
public <R> void prepareReset(R resetContext) Description copied from interface:EventMessageHandlerPerforms any activities that are required to reset the state managed by handlers assigned to this handler.- Specified by:
prepareResetin interfaceEventMessageHandler- Type Parameters:
R- the type of the providedresetContext- Parameters:
resetContext- aRused to support the reset operation
-
supportsReset
public boolean supportsReset()Indicates whether the handlers managed by this invoker support a reset.- Specified by:
supportsResetin interfaceEventMessageHandler- Returns:
trueif a reset is supported, otherwisefalse- Implementation Note:
- This implementation will consider any class that has a single handler that accepts a replay, to support
reset. If no handlers explicitly indicate whether replay is supported, the method returns
true.
-