Annotation Interface CommandHandlerInterceptor


@Documented @Retention(RUNTIME) @Target({METHOD,ANNOTATION_TYPE}) public @interface CommandHandlerInterceptor
Annotation used to mark methods on Aggregate members which can intercept commands. If a non-root entity of the Aggregate is to intercept a command, the field declaring that entity must be annotated with AggregateMember. Command handler interceptor may intercept multiple commands depending on inheritance hierarchy of commands or on command name pattern provided. Any incoming command that matches the signature of the annotated method and the commandNamePattern() will be intercepted by the annotated method.

It is possible to specify InterceptorChain parameter as part of command handler interceptor signature. If this parameter is not specified, command handler will be executed automatically, as if the InterceptorChain.proceed() was invoked as the last instruction.

If a parameter of type InterceptorChain is defined, it must be called to have the command handler invoked. It may choose to return the result of the InterceptorChain.proceed() call directly, change it, or even discard it.

Annotated methods that do not declare an InterceptorChain parameter must declare a void return type, as they cannot alter the result of an invocation, other than by throwing an exception.

There are two ways to prevent command handler of specified command to be executed:

It is possible to have multiple interceptors for the same command. In that case, if there are interceptors in both parent and child entity, the method in the parent entity will be invoked first. The order of invocation of interceptors within the same entity is not specified.

Since:
3.3
Author:
Milan Savic
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Will filter commands which names match this pattern and invoke handler only with those commands.
    Specifies the type of message payload that can be handled by the member method.
  • Element Details

    • commandNamePattern

      String commandNamePattern
      Will filter commands which names match this pattern and invoke handler only with those commands.
      Returns:
      pattern used to filter command names
      Default:
      ".*"
    • payloadType

      Class<?> payloadType
      Specifies the type of message payload that can be handled by the member method. The payload of the message should be assignable to this type. Defaults to any Object.
      Default:
      java.lang.Object.class