Interface EntityCommandHandlerInterceptor<E>
- Type Parameters:
E- The type of the entity modeled by this interface.
CommandMessages dispatched to an entity through its EntityMetamodel.
Unlike the generic MessageHandlerInterceptor, this interceptor is aware of
the entity instance the command targets, allowing it to base its decision (proceed, short-circuit, or otherwise
transform the outcome) on the entity's current state. This is comparable to an EntityCommandHandler, which
for the same reason also receives the entity instance directly.
Interceptors are registered on an EntityMetamodelBuilder through
EntityMetamodelBuilder.commandHandlerInterceptor(EntityCommandHandlerInterceptor). Registration order defines
invocation order: the first registered interceptor is the outermost, invoked before any interceptor registered after
it, before this entity's own command handlers, and before any command is forwarded to a child entity. When this
entity is itself a child of another entity, interceptors registered on the parent entity are invoked before this
entity's own interceptors.
The
CommandHandlerInterceptor annotation is the annotation-based counterpart of this interface. Methods annotated as
such on an entity class are detected and registered through the declarative configuration API.
- Since:
- 5.3.2
- Author:
- Steven van Beelen
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioninterceptOnHandle(CommandMessage command, @Nullable E entity, ProcessingContext context, EntityCommandHandlerInterceptorChain<E> chain) Intercepts the givencommandbefore it reaches this entity's command handlers, or before it is forwarded to a child entity.
-
Method Details
-
interceptOnHandle
MessageStream<?> interceptOnHandle(CommandMessage command, @Nullable E entity, ProcessingContext context, EntityCommandHandlerInterceptorChain<E> chain) Intercepts the givencommandbefore it reaches this entity's command handlers, or before it is forwarded to a child entity.This method is responsible for continuation. To proceed with handling, invoke
EntityCommandHandlerInterceptorChain.proceed(CommandMessage, Object, ProcessingContext)on the givenchain. Not invokingchainshort-circuits the dispatch process, and theMessageStreamreturned by this method becomes the result of handling thecommand.- Parameters:
command- theCommandMessagebeing interceptedentity- the entity instance thecommandtargets, ornullwhen thecommandis a creational command for which no entity instance exists yetcontext- theProcessingContextthecommandis processed inchain- the chain to proceed dispatching thecommand- Returns:
- the
MessageStreamresulting from either proceeding thechain, or a short-circuited result produced by this interceptor
-