T
- the target typepublic class AnnotatedMessageHandlingMember<T> extends Object implements MessageHandlingMember<T>
MessageHandlingMember
that is used to invoke message handler methods on the target type.Constructor and Description |
---|
AnnotatedMessageHandlingMember(Executable executable,
Class<? extends Message> messageType,
Class<?> explicitPayloadType,
ParameterResolverFactory parameterResolverFactory)
Initializes a new instance that will invoke the given
executable (method) on a target to handle a message
of the given messageType . |
Modifier and Type | Method and Description |
---|---|
Optional<Map<String,Object>> |
annotationAttributes(Class<? extends Annotation> annotationType)
Get the attributes of an annotation of given
annotationType on the method of the target entity. |
<R> Optional<R> |
attribute(String attributeKey)
Retrieve a single attributes for the given
attributeKey . |
boolean |
canHandle(Message<?> message)
Checks if this handler is capable of handling the given
message . |
boolean |
canHandleMessageType(Class<? extends Message> messageType)
Checks if this handlers is capable of handling
Message implementations of the given messageType . |
boolean |
canHandleType(Class<?> payloadType)
Checks if this handler is capable of handling messages with the given
payloadType . |
boolean |
equals(Object o) |
Object |
handle(Message<?> message,
T target)
Handles the given
message by invoking the appropriate method on given target . |
boolean |
hasAnnotation(Class<? extends Annotation> annotationType)
Checks whether the method of the target entity contains the given
annotationType . |
int |
hashCode() |
protected boolean |
parametersMatch(Message<?> message)
Checks if the parameter resolvers of this member are compatible with the given
message . |
Class<?> |
payloadType()
Returns the payload type of messages that can be processed by this handler.
|
String |
toString() |
protected boolean |
typeMatches(Message<?> message)
Checks if this member can handle the type of the given
message . |
<H> Optional<H> |
unwrap(Class<H> handlerType)
Returns the wrapped handler object if its type is an instance of the given
handlerType . |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
declaringClass, priority, signature
public AnnotatedMessageHandlingMember(Executable executable, Class<? extends Message> messageType, Class<?> explicitPayloadType, ParameterResolverFactory parameterResolverFactory)
executable
(method) on a target to handle a message
of the given messageType
.executable
- 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 parameterspublic Class<?> payloadType()
MessageHandlingMember
payloadType
in interface MessageHandlingMember<T>
public boolean canHandle(Message<?> message)
MessageHandlingMember
message
.canHandle
in interface MessageHandlingMember<T>
message
- The message that is to be handledtrue
if the handler is capable of handling the message, false
otherwisepublic boolean canHandleType(Class<?> payloadType)
MessageHandlingMember
payloadType
.canHandleType
in interface MessageHandlingMember<T>
payloadType
- The payloadType of a message that is to be handledtrue
if the handler is capable of handling the message with given type, false
otherwisepublic boolean canHandleMessageType(Class<? extends Message> messageType)
MessageHandlingMember
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.
canHandleMessageType
in interface MessageHandlingMember<T>
messageType
- the Message
's type to check if it can be handled by this handlertrue
if this handler can handle the given messageType
, false
otherwiseprotected boolean typeMatches(Message<?> message)
message
. This method does not check if the
parameter resolvers of this member are compatible with the given message. Use parametersMatch(Message)
for that.message
- the message to check fortrue
if this member can handle the message type. false
otherwiseprotected boolean parametersMatch(Message<?> message)
message
.message
- the message to check fortrue
if the parameter resolvers can handle this message. false
otherwisepublic Object handle(Message<?> message, T target) throws Exception
MessageHandlingMember
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.handle
in interface MessageHandlingMember<T>
message
- The message to handletarget
- The target to handle the messageException
- when there was a problem that prevented invocation of the method or if an exception was thrown
from the invoked methodpublic boolean hasAnnotation(Class<? extends Annotation> annotationType)
MessageHandlingMember
annotationType
.hasAnnotation
in interface MessageHandlingMember<T>
annotationType
- Annotation to check for on the target methodtrue
if the annotation is present on the target method, false
otherwisepublic Optional<Map<String,Object>> annotationAttributes(Class<? extends Annotation> annotationType)
MessageHandlingMember
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.annotationAttributes
in interface MessageHandlingMember<T>
annotationType
- The annotation to check for on the target methodpublic <R> Optional<R> attribute(String attributeKey)
MessageHandlingMember
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.
attribute
in interface MessageHandlingMember<T>
attributeKey
- the key to retrieve an attribute forOptional
of the attribute referencing the given attributeKey
. Otherwise an
Optional.empty()
will be returnedpublic <H> Optional<H> unwrap(Class<H> handlerType)
MessageHandlingMember
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
.unwrap
in interface MessageHandlingMember<T>
H
- The wrapped handler typehandlerType
- The expected type of the wrapped handlerCopyright © 2010–2022. All rights reserved.