Class AnnotationEventHandlerAdapter

java.lang.Object
org.axonframework.eventhandling.AnnotationEventHandlerAdapter
All Implemented Interfaces:
EventMessageHandler, MessageHandler<EventMessage<?>>

public class AnnotationEventHandlerAdapter extends Object implements EventMessageHandler
Adapter that turns any bean with EventHandler annotated methods into an EventMessageHandler.
Since:
0.1
Author:
Allard Buijze
See Also:
  • Constructor Details

    • AnnotationEventHandlerAdapter

      public AnnotationEventHandlerAdapter(Object annotatedEventListener)
      Wraps the given annotatedEventListener, allowing it to be subscribed to an Event Bus.
      Parameters:
      annotatedEventListener - the annotated event listener
    • AnnotationEventHandlerAdapter

      public AnnotationEventHandlerAdapter(Object annotatedEventListener, ParameterResolverFactory parameterResolverFactory)
      Wraps the given annotatedEventListener, allowing it to be subscribed to an Event Bus. The given parameterResolverFactory is used to resolve parameter values for handler methods.
      Parameters:
      annotatedEventListener - the annotated event listener
      parameterResolverFactory - the strategy for resolving handler method parameter values
    • AnnotationEventHandlerAdapter

      public AnnotationEventHandlerAdapter(Object annotatedEventListener, ParameterResolverFactory parameterResolverFactory, HandlerDefinition handlerDefinition)
      Wraps the given annotatedEventListener, allowing it to be subscribed to an Event Bus. The given parameterResolverFactory is used to resolve parameter values for handler methods. Handler definition is used to create concrete handlers.
      Parameters:
      annotatedEventListener - the annotated event listener
      parameterResolverFactory - the strategy for resolving handler method parameter values
      handlerDefinition - the handler definition used to create concrete handlers
  • Method Details

    • handle

      public Object handle(EventMessage<?> event) throws Exception
      Description copied from interface: EventMessageHandler
      Process 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:
      handle in interface EventMessageHandler
      Specified by:
      handle in interface MessageHandler<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

      public boolean canHandle(EventMessage<?> event)
      Description copied from interface: MessageHandler
      Indicates whether this handler can handle the given message
      Specified by:
      canHandle in interface MessageHandler<EventMessage<?>>
      Parameters:
      event - The message to verify
      Returns:
      true if this handler can handle the message, otherwise false
    • canHandleType

      public boolean canHandleType(Class<?> payloadType)
      Description copied from interface: MessageHandler
      Indicates whether this handler can handle messages of given type
      Specified by:
      canHandleType in interface MessageHandler<EventMessage<?>>
      Parameters:
      payloadType - The payloadType to verify
      Returns:
      true if this handler can handle the payloadType, otherwise false
    • getTargetType

      public Class<?> getTargetType()
      Description copied from interface: MessageHandler
      Returns the instance type that this handler delegates to.
      Specified by:
      getTargetType in interface MessageHandler<EventMessage<?>>
      Returns:
      Returns the instance type that this handler delegates to
    • prepareReset

      public void prepareReset()
      Description copied from interface: EventMessageHandler
      Performs any activities that are required to reset the state managed by handlers assigned to this handler.
      Specified by:
      prepareReset in interface EventMessageHandler
    • prepareReset

      public <R> void prepareReset(R resetContext)
      Description copied from interface: EventMessageHandler
      Performs any activities that are required to reset the state managed by handlers assigned to this handler.
      Specified by:
      prepareReset in interface EventMessageHandler
      Type Parameters:
      R - the type of the provided resetContext
      Parameters:
      resetContext - a R used to support the reset operation
    • supportsReset

      public boolean supportsReset()
      Indicates whether the handlers managed by this invoker support a reset.
      Specified by:
      supportsReset in interface EventMessageHandler
      Returns:
      true if a reset is supported, otherwise false
      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.