Class MessageProcessingContext<T extends Message<?>>

java.lang.Object
org.axonframework.messaging.unitofwork.MessageProcessingContext<T>

public class MessageProcessingContext<T extends Message<?>> extends Object
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 Details

    • MessageProcessingContext

      public MessageProcessingContext(T message)
      Creates a new processing context for the given message.
      Parameters:
      message - The Message that is to be processed.
  • Method Details

    • notifyHandlers

      public void notifyHandlers(UnitOfWork<T> unitOfWork, UnitOfWork.Phase phase)
      Invoke the handlers in this collection attached to the given phase.
      Parameters:
      unitOfWork - The Unit of Work that is changing its phase
      phase - The phase for which attached handlers should be invoked
    • addHandler

      public void addHandler(UnitOfWork.Phase phase, Consumer<UnitOfWork<T>> handler)
      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 to
      handler - The handler to invoke in the given phase
    • setExecutionResult

      public void setExecutionResult(ExecutionResult executionResult)
      Set the execution result of processing the current Message. 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

      public T getMessage()
      Get the Message that is being processed in this context.
      Returns:
      the Message that is being processed
    • getExecutionResult

      public ExecutionResult getExecutionResult()
      Get the result of processing the Message. If the Message has not been processed yet this method returns null.
      Returns:
      The result of processing the Message, or null if the Message hasn't been processed
    • transformMessage

      public void transformMessage(Function<T,? extends Message<?>> transformOperator)
      Transform the Message being processed using the given operator.
      Parameters:
      transformOperator - The transform operator to apply to the stored message
    • reset

      public void reset(T message)
      Reset the processing context. This clears the execution result and map with registered handlers, and replaces the current Message with the given message.
      Parameters:
      message - The new message that is being processed