Class MethodInvokingMessageHandlingMember<T>

java.lang.Object
org.axonframework.messaging.core.annotation.MethodInvokingMessageHandlingMember<T>
Type Parameters:
T - the target type.
All Implemented Interfaces:
MessageHandlingMember<T>

public class MethodInvokingMessageHandlingMember<T> extends Object implements MessageHandlingMember<T>
Implementation of a MessageHandlingMember that is used to invoke message handler methods on the target type.
Since:
3.0.0
Author:
Allard Buijze
  • Constructor Details

    • MethodInvokingMessageHandlingMember

      public MethodInvokingMessageHandlingMember(Method method, Class<? extends Message> messageType, Class<?> explicitPayloadType, ParameterResolverFactory parameterResolverFactory, Function<Object,MessageStream<?>> returnTypeConverter)
      Initializes a new instance that will invoke the given executable (method) on a target to handle a message of the given messageType.
      Parameters:
      method - the method to invoke on a target
      messageType - the type of message that is expected by the target method
      explicitPayloadType - the expected message payload type
      parameterResolverFactory - factory used to resolve method parameters
  • Method Details

    • 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<T>
      Returns:
      The payload type of messages expected by this handler
    • canHandle

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

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

      public boolean canHandleMessageType(@Nonnull Class<? extends Message> messageType)
      Description copied from interface: MessageHandlingMember
      Checks if this handler 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<T>
      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.
    • typeMatches

      protected boolean typeMatches(Message message)
      Checks if this member can handle the type of the given message. This method does not check if the parameter resolvers of this member are compatible with the given message. Use parametersMatch(Message, ProcessingContext) for that.
      Parameters:
      message - the message to check for
      Returns:
      true if this member can handle the message type. false otherwise
    • parametersMatch

      protected boolean parametersMatch(Message message, ProcessingContext processingContext)
      Checks if the parameter resolvers of this member are compatible with the given message.
      Parameters:
      message - the message to check for
      Returns:
      true if the parameter resolvers can handle this message. false otherwise
    • handleSync

      public Object handleSync(@Nonnull Message message, @Nonnull ProcessingContext context, @Nullable T 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:
      handleSync in interface MessageHandlingMember<T>
      Parameters:
      message - The message to handle.
      context - The context in which the message is being handled.
      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.
    • handle

      public MessageStream<?> handle(@Nonnull Message message, @Nonnull ProcessingContext context, @Nullable T target)
      Description copied from interface: MessageHandlingMember
      Handles the given message within the given context 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. These exceptions should be caught and passed along in a failed MessageStream.

      Specified by:
      handle in interface MessageHandlingMember<T>
      Parameters:
      message - The message to handle.
      context - The context in which the message is being handled.
      target - The target to handle the message.
      Returns:
      The MessageStream containing the response(s), if any, from handling the given message.
    • 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<T>
      Type Parameters:
      R - The value type of the returned attribute.
      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.
    • unwrap

      public <H> Optional<H> unwrap(Class<H> 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<T>
      Type Parameters:
      H - 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
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object