P
- the parent entity typeC
- the child entity typepublic class ChildForwardingCommandMessageHandlingMember<P,C> extends Object implements ForwardingCommandMessageHandlingMember<P>
CommandMessageHandlingMember
that forwards commands to a child entity.Constructor and Description |
---|
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. |
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 |
canForward(CommandMessage<?> message,
P target)
Check if this handler is in a state where it can currently accept the command.
|
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 . |
String |
commandName()
Returns the name of the command that can be handled.
|
Object |
handle(Message<?> message,
P 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 . |
boolean |
isFactoryHandler()
Check if this message handler creates a new instance of the entity of type
T to handle this command. |
Class<?> |
payloadType()
Returns the payload type of messages that can be processed by this handler.
|
int |
priority()
Returns a number representing the priority of this handler over other handlers capable of processing the same
message.
|
String |
routingKey()
Returns the property of the command that is to be used as routing key towards this command handler instance.
|
<HT> Optional<HT> |
unwrap(Class<HT> handlerType)
Returns the wrapped handler object if its type is an instance of the given
handlerType . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
canHandleType, declaringClass, signature
public ChildForwardingCommandMessageHandlingMember(List<MessageHandlingMember<? super C>> childHandlerInterceptors, MessageHandlingMember<? super C> childHandler, BiFunction<CommandMessage<?>,P,C> childEntityResolver)
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
.childHandlerInterceptors
- interceptors for childHandler
childHandler
- handler of the command once a suitable entity is foundchildEntityResolver
- resolver of child entities for a given commandpublic String commandName()
CommandMessageHandlingMember
commandName
in interface CommandMessageHandlingMember<P>
public String routingKey()
CommandMessageHandlingMember
routingKey
in interface CommandMessageHandlingMember<P>
public boolean isFactoryHandler()
CommandMessageHandlingMember
T
to handle this command.
This is for instance the case if the message is handled in the constructor method of the entity.
isFactoryHandler
in interface CommandMessageHandlingMember<P>
true
if this handler is also factory for entities, false
otherwise.public Class<?> payloadType()
MessageHandlingMember
payloadType
in interface MessageHandlingMember<P>
public int priority()
MessageHandlingMember
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.
priority
in interface MessageHandlingMember<P>
public boolean canForward(CommandMessage<?> message, P target)
ForwardingCommandMessageHandlingMember
canForward
in interface ForwardingCommandMessageHandlingMember<P>
message
- The message that is to be forwardedtarget
- The target to forward the command messagetrue
if this handler can forward command to target entity, false
otherwise.public boolean canHandle(@Nonnull Message<?> message)
MessageHandlingMember
message
.canHandle
in interface MessageHandlingMember<P>
message
- The message that is to be handledtrue
if the handler is capable of handling the message, false
otherwisepublic boolean canHandleMessageType(@Nonnull 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<P>
messageType
- the Message
's type to check if it can be handled by this handlertrue
if this handler can handle the given messageType
, false
otherwisepublic Object handle(@Nonnull Message<?> message, @Nullable P 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<P>
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 <HT> Optional<HT> unwrap(Class<HT> 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<P>
HT
- The wrapped handler typehandlerType
- The expected type of the wrapped handlerpublic boolean hasAnnotation(Class<? extends Annotation> annotationType)
MessageHandlingMember
annotationType
.hasAnnotation
in interface MessageHandlingMember<P>
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<P>
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<P>
attributeKey
- the key to retrieve an attribute forOptional
of the attribute referencing the given attributeKey
. Otherwise an
Optional.empty()
will be returnedCopyright © 2010–2024. All rights reserved.