Class AggregateDeadlineCommandTranslator
- All Implemented Interfaces:
ScopeAware
DeadlineMessage scoped to an AggregateScopeDescriptor into a command, dispatched
through a CommandGateway.
Implements ScopeAware so it can be reached through a ScopeAwareProvider the same way a Saga manager
is. Its send(Message, ProcessingContext, ScopeDescriptor) dispatches the deadline's payload and metadata as
a command, and writes the AggregateScopeDescriptor's identifier into the dispatched command's metadata under
"scope-descriptor-based-entity-identifier".
AggregateDeadlineEntityIdResolverConfigurationEnhancer registers the resolver that reads this metadata entry
as the application-wide default, used whenever the command's payload carries no @TargetEntityId.
A deadline scheduled without a payload carries null as its Message.payload(). Since a null
payload cannot name the command to dispatch, this translator falls back to the deadline's
DeadlineMessage.getDeadlineName() in that case, dispatched as both the command's name and its payload, so the
migrated handler becomes @CommandHandler(commandName = "<deadlineName>") void handle(String command, ...).
Constructed and registered by the AggregateDeadlineCommandTranslatorConfigurationEnhancer.
- Since:
- 5.4.0
- Author:
- Steven van Beelen
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAggregateDeadlineCommandTranslator(CommandGateway commandGateway) Initializes anAggregateDeadlineCommandTranslator, dispatching translated commands through the givencommandGateway. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanResolve(ScopeDescriptor scopeDescription) Check whether this implementation can resolve aScopeobject based on the providedscopeDescription.voidsend(Message message, ProcessingContext context, ScopeDescriptor scopeDescription)
-
Constructor Details
-
AggregateDeadlineCommandTranslator
Initializes anAggregateDeadlineCommandTranslator, dispatching translated commands through the givencommandGateway.- Parameters:
commandGateway- theCommandGatewayto dispatch a fired aggregate deadline's command through
-
-
Method Details
-
canResolve
Check whether this implementation can resolve aScopeobject based on the providedscopeDescription. Will returntruein case it should be able to resolve the Scope andfalseif it cannot.Returns
truefor everyAggregateScopeDescriptor, regardless of the aggregate type it describes, since routing to the right entity is delegated to the dispatched command's@TargetEntityId, not resolved here.- Specified by:
canResolvein interfaceScopeAware- Parameters:
scopeDescription- aScopeDescriptordescribing theScopeto be resolved- Returns:
truein case it should be able to resolve the Scope andfalseif it cannot
-
send
public void send(Message message, ProcessingContext context, ScopeDescriptor scopeDescription) throws Exception Send aMessageto aScopewhich is described by the givenscopeDescription.Dispatches the
message's payload and metadata as a command through the configuredCommandGateway, passing the givencontextalong so the command runs within the deadline's firing unit of work. Waits for the command's result withFutureUtils.joinAndUnwrap(java.util.concurrent.CompletableFuture), rethrowing a failure so the caller applies its own failure handling.A
messagewhose payload is anUnknownDeadlinePayload(its stored type could not be resolved) is not dispatched: this method logs a warning naming the deadline, the stored type and the aggregate scope, and returns.A
messagewhose payload isnullis dispatched as aGenericCommandMessagenamed after, and carrying as its payload,DeadlineMessage.getDeadlineName(), since anullpayload carries no type to derive a command name from.The dispatched command's metadata always carries the
scopeDescription's identifier under "scope-descriptor-based-entity-identifier", so the target entity can be resolved from it instead of from the payload.- Specified by:
sendin interfaceScopeAware- Parameters:
message- TheMessageto be sent to aScope.context- TheProcessingContextin which themessageis being processed.scopeDescription- ADextendingScopeDescriptor, describing theScopeto send the givenmessageto.- Throws:
IllegalArgumentException- if the givenmessageis not aDeadlineMessage, or if the givenscopeDescriptionis not anAggregateScopeDescriptorException- if sending themessagefailed. Might occur if the message handling process throws an exception.
-