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 Summary
ConstructorsConstructorDescriptionMethodInvokingMessageHandlingMember(Method method, Class<? extends Message> messageType, Class<?> explicitPayloadType, ParameterResolverFactory parameterResolverFactory, Function<Object, MessageStream<?>> returnTypeConverter) Initializes a new instance that will invoke the givenexecutable(method) on a target to handle a message of the givenmessageType. -
Method Summary
Modifier and TypeMethodDescription<R> Optional<R> Retrieve a single attributes for the givenattributeKey.booleancanHandle(Message message, ProcessingContext context) Checks if this handler is capable of handling the givenmessage.booleancanHandleMessageType(Class<? extends Message> messageType) Checks if this handler is capable of handlingMessageimplementations of the givenmessageType.booleancanHandleType(Class<?> payloadType) Checks if this handler is capable of handling messages with the givenpayloadType.booleanhandle(Message message, ProcessingContext context, T target) Handles the givenmessagewithin the givencontextby invoking the appropriate method on giventarget.handleSync(Message message, ProcessingContext context, T target) Handles the givenmessageby invoking the appropriate method on giventarget.inthashCode()protected booleanparametersMatch(Message message, ProcessingContext processingContext) Checks if the parameter resolvers of this member are compatible with the givenmessage.Class<?> Returns the payload type of messages that can be processed by this handler.toString()protected booleantypeMatches(Message message) Checks if this member can handle the type of the givenmessage.<H> Optional<H> Returns the wrapped handler object if its type is an instance of the givenhandlerType.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.axonframework.messaging.core.annotation.MessageHandlingMember
declaringClass, priority, signature
-
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 givenexecutable(method) on a target to handle a message of the givenmessageType.- Parameters:
method- the method to invoke on a targetmessageType- the type of message that is expected by the target methodexplicitPayloadType- the expected message payload typeparameterResolverFactory- factory used to resolve method parameters
-
-
Method Details
-
payloadType
Description copied from interface:MessageHandlingMemberReturns the payload type of messages that can be processed by this handler.- Specified by:
payloadTypein interfaceMessageHandlingMember<T>- Returns:
- The payload type of messages expected by this handler
-
canHandle
Description copied from interface:MessageHandlingMemberChecks if this handler is capable of handling the givenmessage.- Specified by:
canHandlein interfaceMessageHandlingMember<T>- Parameters:
message- The message that is to be handled.context- The context in which the message is being handled.- Returns:
trueif the handler is capable of handling the message,falseotherwise.
-
canHandleType
Description copied from interface:MessageHandlingMemberChecks if this handler is capable of handling messages with the givenpayloadType.- Specified by:
canHandleTypein interfaceMessageHandlingMember<T>- Parameters:
payloadType- The payloadType of a message that is to be handled- Returns:
trueif the handler is capable of handling the message with given type,falseotherwise.
-
canHandleMessageType
Description copied from interface:MessageHandlingMemberChecks if this handler is capable of handlingMessageimplementations of the givenmessageType.It is recommended to suppress the raw type use validation of the
messageTypeparameter when implementing this method, as usage of this method with aMessagegeneric would required reflection or casting otherwise.- Specified by:
canHandleMessageTypein interfaceMessageHandlingMember<T>- Parameters:
messageType- TheMessage's type to check if it can be handled by this handler.- Returns:
trueif this handler can handle the givenmessageType,falseotherwise.
-
typeMatches
Checks if this member can handle the type of the givenmessage. This method does not check if the parameter resolvers of this member are compatible with the given message. UseparametersMatch(Message, ProcessingContext)for that.- Parameters:
message- the message to check for- Returns:
trueif this member can handle the message type.falseotherwise
-
parametersMatch
Checks if the parameter resolvers of this member are compatible with the givenmessage.- Parameters:
message- the message to check for- Returns:
trueif the parameter resolvers can handle this message.falseotherwise
-
handleSync
public Object handleSync(@Nonnull Message message, @Nonnull ProcessingContext context, @Nullable T target) throws Exception Description copied from interface:MessageHandlingMemberHandles the givenmessageby invoking the appropriate method on giventarget. 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:
handleSyncin interfaceMessageHandlingMember<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:MessageHandlingMemberHandles the givenmessagewithin the givencontextby invoking the appropriate method on giventarget.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:
handlein interfaceMessageHandlingMember<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
MessageStreamcontaining the response(s), if any, from handling the givenmessage.
-
attribute
Description copied from interface:MessageHandlingMemberRetrieve a single attributes for the givenattributeKey. If thisMessageHandlingMemberdoes not hold a value referencing theattributeKey, anOptional.empty()is returned. Otherwise, a non-emptyOptionalcontaining the attribute will be provided.When using the method, consider checking the
HandlerAttributesfor a list of common handler attributes.- Specified by:
attributein interfaceMessageHandlingMember<T>- Type Parameters:
R- The value type of the returned attribute.- Parameters:
attributeKey- The key to retrieve an attribute for.- Returns:
- A non-empty
Optionalof the attribute referencing the givenattributeKey. Otherwise, anOptional.empty()will be returned.
-
unwrap
Description copied from interface:MessageHandlingMemberReturns the wrapped handler object if its type is an instance of the givenhandlerType. For instance, if this method is invoked withExecutableand the message is handled by a method of the target entity, then this method will return the method handle as aMethod.- Specified by:
unwrapin interfaceMessageHandlingMember<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
-
hashCode
public int hashCode() -
equals
-