Class MessageProcessingContext<T extends Message<?>>
java.lang.Object
org.axonframework.messaging.unitofwork.MessageProcessingContext<T>
Maintains the context around the processing of a single Message. This class notifies handlers when the Unit of Work
processing the Message transitions to a new
UnitOfWork.Phase.- Since:
- 3.0
- Author:
- Rene de Waele
-
Constructor Summary
ConstructorsConstructorDescriptionMessageProcessingContext(T message) Creates a new processing context for the givenmessage. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHandler(UnitOfWork.Phase phase, Consumer<UnitOfWork<T>> handler) Adds a handler to the collection.Get the result of processing theMessage.Get the Message that is being processed in this context.voidnotifyHandlers(UnitOfWork<T> unitOfWork, UnitOfWork.Phase phase) Invoke the handlers in this collection attached to the givenphase.voidReset the processing context.voidsetExecutionResult(ExecutionResult executionResult) Set the execution result of processing the currentMessage.voidtransformMessage(Function<T, ? extends Message<?>> transformOperator) Transform the Message being processed using the given operator.
-
Constructor Details
-
MessageProcessingContext
Creates a new processing context for the givenmessage.- Parameters:
message- The Message that is to be processed.
-
-
Method Details
-
notifyHandlers
Invoke the handlers in this collection attached to the givenphase.- Parameters:
unitOfWork- The Unit of Work that is changing its phasephase- The phase for which attached handlers should be invoked
-
addHandler
Adds a handler to the collection. Note that the order in which you register the handlers determines the order in which they will be handled during the various stages of a unit of work.- Parameters:
phase- The phase of the unit of work to attach the handler tohandler- The handler to invoke in the given phase
-
setExecutionResult
Set the execution result of processing the currentMessage. In case this context has a previously set ExecutionResult, setting a new result is only allowed if the new result is an exception result. In case the previously set result is also an exception result, the exception in the new execution result is added to the original exception as a suppressed exception.- Parameters:
executionResult- the ExecutionResult of the currently handled Message
-
getMessage
Get the Message that is being processed in this context.- Returns:
- the Message that is being processed
-
getExecutionResult
Get the result of processing theMessage. If the Message has not been processed yet this method returnsnull.- Returns:
- The result of processing the Message, or
nullif the Message hasn't been processed
-
transformMessage
Transform the Message being processed using the given operator.- Parameters:
transformOperator- The transform operator to apply to the stored message
-
reset
Reset the processing context. This clears the execution result and map with registered handlers, and replaces the current Message with the givenmessage.- Parameters:
message- The new message that is being processed
-