Interface MessageHandlingMember<T>
- Type Parameters:
T- The type of entity to which the message handler will delegate the actual handling of the message
- All Known Subinterfaces:
CommandHandlingMember<T>,EventHandlingMember<T>,MessageInterceptingMember<T>,QueryHandlingMember<T>
- All Known Implementing Classes:
MethodInvokingMessageHandlingMember,WrappedMessageHandlingMember
- Since:
- 3.0.0
- Author:
- Allard Buijze
-
Method Summary
Modifier and TypeMethodDescriptiondefault <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.default booleancanHandleType(Class<?> payloadType) Checks if this handler is capable of handling messages with the givenpayloadType.default Class<?> Gets the declaring class of this Message Handling Member.handle(Message message, ProcessingContext context, T target) Handles the givenmessagewithin the givencontextby invoking the appropriate method on giventarget.handleSync(Message message, ProcessingContext context, T target) Deprecated, for removal: This API element is subject to removal in a future version.Class<?> Returns the payload type of messages that can be processed by this handler.default intpriority()Returns a number representing the priority of this handler over other handlers capable of processing the same message.default StringReturns the signature of the member.<HT> Optional<HT> Returns the wrapped handler object if its type is an instance of the givenhandlerType.
-
Method Details
-
payloadType
Class<?> payloadType()Returns the payload type of messages that can be processed by this handler.- Returns:
- The payload type of messages expected by this handler
-
priority
default int priority()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.
- Returns:
- Number indicating the priority of this handler over other handlers
-
canHandle
Checks if this handler is capable of handling the givenmessage.- 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
Checks if this handler is capable of handling messages with the givenpayloadType.- 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
Checks 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.- Parameters:
messageType- TheMessage's type to check if it can be handled by this handler.- Returns:
trueif this handler can handle the givenmessageType,falseotherwise.
-
handleSync
@Internal @Deprecated(forRemoval=true, since="5.2.0") Object handleSync(@Nonnull Message message, @Nonnull ProcessingContext context, @Nullable T target) throws Exception Deprecated, for removal: This API element is subject to removal in a future version.In favor ofhandle(Message, ProcessingContext, Object).Handles 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.- 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
MessageStream<?> handle(@Nonnull Message message, @Nonnull ProcessingContext context, @Nullable T target) Handles 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.- 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.
-
unwrap
Returns 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.- 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
-
declaringClass
Gets the declaring class of this Message Handling Member.- Returns:
- the declaring class of this Message Handling Member
-
signature
Returns the signature of the member. This may be used in logging or exceptions to demarcate the actual class member invoked. If this member does not have a signature,"__unknown__"is returned.- Returns:
- the signature of the handling member
-
attribute
Retrieve 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.- 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.
-
handle(Message, ProcessingContext, Object).