Class ChildForwardingCommandMessageHandlingMember<P,C>

java.lang.Object
org.axonframework.modelling.command.inspection.ChildForwardingCommandMessageHandlingMember<P,C>
Type Parameters:
P - the parent entity type
C - the child entity type
All Implemented Interfaces:
CommandMessageHandlingMember<P>, MessageHandlingMember<P>, ForwardingCommandMessageHandlingMember<P>

public class ChildForwardingCommandMessageHandlingMember<P,C> extends Object implements ForwardingCommandMessageHandlingMember<P>
Implementation of a CommandMessageHandlingMember that forwards commands to a child entity.
Since:
3.0
Author:
Allard Buijze
  • Constructor Details

    • ChildForwardingCommandMessageHandlingMember

      public ChildForwardingCommandMessageHandlingMember(List<MessageHandlingMember<? super C>> childHandlerInterceptors, MessageHandlingMember<? super C> childHandler, BiFunction<CommandMessage<?>,P,C> childEntityResolver)
      Initializes a ChildForwardingCommandMessageHandlingMember that routes commands to a compatible child entity. Child entities are resolved using the given childEntityResolver. If an entity is found the command will be handled using the given childHandler.
      Parameters:
      childHandlerInterceptors - interceptors for childHandler
      childHandler - handler of the command once a suitable entity is found
      childEntityResolver - resolver of child entities for a given command
  • Method Details

    • commandName

      public String commandName()
      Description copied from interface: CommandMessageHandlingMember
      Returns the name of the command that can be handled.
      Specified by:
      commandName in interface CommandMessageHandlingMember<P>
      Returns:
      The name of the command that can be handled
    • routingKey

      public String routingKey()
      Description copied from interface: CommandMessageHandlingMember
      Returns the property of the command that is to be used as routing key towards this command handler instance. If multiple handlers instances are available, a sending component is responsible to route commands with the same routing key value to the correct instance.
      Specified by:
      routingKey in interface CommandMessageHandlingMember<P>
      Returns:
      The property of the command to use as routing key
    • isFactoryHandler

      public boolean isFactoryHandler()
      Description copied from interface: CommandMessageHandlingMember
      Check if this message handler creates a new instance of the entity of type T to handle this command.

      This is for instance the case if the message is handled in the constructor method of the entity.

      Specified by:
      isFactoryHandler in interface CommandMessageHandlingMember<P>
      Returns:
      true if this handler is also factory for entities, false otherwise.
    • payloadType

      public Class<?> payloadType()
      Description copied from interface: MessageHandlingMember
      Returns the payload type of messages that can be processed by this handler.
      Specified by:
      payloadType in interface MessageHandlingMember<P>
      Returns:
      The payload type of messages expected by this handler
    • priority

      public int priority()
      Description copied from interface: MessageHandlingMember
      Returns a number representing the priority of this handler over other handlers capable of processing the same message.

      In general, a handler with a higher priority will receive the message before (or instead of) handlers with a lower priority. However, the priority value may not be the only indicator that is used to determine the order of invocation. For instance, a message processor may decide to ignore the priority value if one message handler is a more specific handler of the message than another handler.

      Specified by:
      priority in interface MessageHandlingMember<P>
      Returns:
      Number indicating the priority of this handler over other handlers
    • canForward

      public boolean canForward(CommandMessage<?> message, P target)
      Description copied from interface: ForwardingCommandMessageHandlingMember
      Check if this handler is in a state where it can currently accept the command.
      Specified by:
      canForward in interface ForwardingCommandMessageHandlingMember<P>
      Parameters:
      message - The message that is to be forwarded
      target - The target to forward the command message
      Returns:
      true if this handler can forward command to target entity, false otherwise.
    • canHandle

      public boolean canHandle(@Nonnull Message<?> message)
      Description copied from interface: MessageHandlingMember
      Checks if this handler is capable of handling the given message.
      Specified by:
      canHandle in interface MessageHandlingMember<P>
      Parameters:
      message - The message that is to be handled
      Returns:
      true if the handler is capable of handling the message, false otherwise
    • canHandleMessageType

      public boolean canHandleMessageType(@Nonnull Class<? extends Message> messageType)
      Description copied from interface: MessageHandlingMember
      Checks if this handlers is capable of handling Message implementations of the given messageType.

      It is recommended to suppress the raw type use validation of the messageType parameter when implementing this method, as usage of this method with a Message generic would required reflection or casting otherwise.

      Specified by:
      canHandleMessageType in interface MessageHandlingMember<P>
      Parameters:
      messageType - the Message's type to check if it can be handled by this handler
      Returns:
      true if this handler can handle the given messageType, false otherwise
    • handle

      public Object handle(@Nonnull Message<?> message, @Nullable P target) throws Exception
      Description copied from interface: MessageHandlingMember
      Handles the given message by invoking the appropriate method on given target. This may result in an exception if the given target is not capable of handling the message or if an exception is thrown during invocation of the method.
      Specified by:
      handle in interface MessageHandlingMember<P>
      Parameters:
      message - The message to handle
      target - The target to handle the message
      Returns:
      The message handling result in case the invocation was successful
      Throws:
      Exception - when there was a problem that prevented invocation of the method or if an exception was thrown from the invoked method
    • unwrap

      public <HT> Optional<HT> unwrap(Class<HT> handlerType)
      Description copied from interface: MessageHandlingMember
      Returns the wrapped handler object if its type is an instance of the given handlerType. For instance, if this method is invoked with Executable and the message is handled by a method of the target entity, then this method will return the method handle as a Method.
      Specified by:
      unwrap in interface MessageHandlingMember<P>
      Type Parameters:
      HT - The wrapped handler type
      Parameters:
      handlerType - The expected type of the wrapped handler
      Returns:
      An Optional containing the wrapped handler object or an empty Optional if the handler is not an instance of the given handlerType
    • hasAnnotation

      public boolean hasAnnotation(Class<? extends Annotation> annotationType)
      Description copied from interface: MessageHandlingMember
      Checks whether the method of the target entity contains the given annotationType.
      Specified by:
      hasAnnotation in interface MessageHandlingMember<P>
      Parameters:
      annotationType - Annotation to check for on the target method
      Returns:
      true if the annotation is present on the target method, false otherwise
    • annotationAttributes

      public Optional<Map<String,Object>> annotationAttributes(Class<? extends Annotation> annotationType)
      Description copied from interface: MessageHandlingMember
      Get the attributes of an annotation of given annotationType on the method of the target entity. If the annotation is present on the target method an Optional is returned containing the properties mapped by their name. If the annotation is not present an empty Optional is returned.
      Specified by:
      annotationAttributes in interface MessageHandlingMember<P>
      Parameters:
      annotationType - The annotation to check for on the target method
      Returns:
      An optional containing a map of the properties of the annotation, or an empty optional if the annotation is missing on the method
    • attribute

      public <R> Optional<R> attribute(String attributeKey)
      Description copied from interface: MessageHandlingMember
      Retrieve a single attributes for the given attributeKey. If this MessageHandlingMember does not hold a value referencing the attributeKey, an Optional.empty() is returned. Otherwise a non-empty Optional containing the attribute will be provided.

      When using the method, consider checking the HandlerAttributes for a list of common handler attributes.

      Specified by:
      attribute in interface MessageHandlingMember<P>
      Parameters:
      attributeKey - the key to retrieve an attribute for
      Returns:
      a non-empty Optional of the attribute referencing the given attributeKey. Otherwise an Optional.empty() will be returned