Class DisruptorUnitOfWork<T extends Message<?>>

java.lang.Object
org.axonframework.messaging.unitofwork.AbstractUnitOfWork<T>
org.axonframework.disruptor.commandhandling.DisruptorUnitOfWork<T>
All Implemented Interfaces:
UnitOfWork<T>
Direct Known Subclasses:
CommandHandlingEntry

public abstract class DisruptorUnitOfWork<T extends Message<?>> extends AbstractUnitOfWork<T>
Specialized UnitOfWork instance for the DisruptorCommandBus. It expects the executing command message to target a single aggregate instance.
Since:
2.0
Author:
Allard Buijze
  • Constructor Details

    • DisruptorUnitOfWork

      public DisruptorUnitOfWork()
  • Method Details

    • reset

      public void reset(T message)
      Resets the state of this Unit of Work, by setting its phase to NOT_STARTED, replacing the message of this Unit of Work with given message, and clearing its collection of registered handlers.
      Parameters:
      message - the new Message that is about to be processed.
    • pause

      public void pause()
      Pause this Unit of Work by deregistering it with the CurrentUnitOfWork. This will detach it from the current thread.
    • resume

      public void resume()
      Resume a paused Unit of Work by registering it with the CurrentUnitOfWork. This will attach it to the current thread again.
    • parent

      public Optional<UnitOfWork<?>> parent()
      Description copied from interface: UnitOfWork
      Returns an optional for the parent of this Unit of Work. The optional holds the Unit of Work that was active when this Unit of Work was started. In case no other Unit of Work was active when this Unit of Work was started the optional is empty, indicating that this is the Unit of Work root.
      Specified by:
      parent in interface UnitOfWork<T extends Message<?>>
      Overrides:
      parent in class AbstractUnitOfWork<T extends Message<?>>
      Returns:
      an optional parent Unit of Work
    • getMessage

      public T getMessage()
      Description copied from interface: UnitOfWork
      Get the message that is being processed by the Unit of Work. A Unit of Work processes a single Message over its life cycle.
      Returns:
      the Message being processed by this Unit of Work
    • transformMessage

      public UnitOfWork<T> transformMessage(Function<T,? extends Message<?>> transformOperator)
      Description copied from interface: UnitOfWork
      Transform the Message being processed using the given operator and stores the result.

      Implementations should take caution not to change the message type to a type incompatible with the current Unit of Work. For example, do not return a CommandMessage when transforming an EventMessage.

      Parameters:
      transformOperator - The transform operator to apply to the stored message
      Returns:
      this Unit of Work
    • notifyHandlers

      protected void notifyHandlers(UnitOfWork.Phase phase)
      Description copied from class: AbstractUnitOfWork
      Notify the handlers attached to the given phase.
      Specified by:
      notifyHandlers in class AbstractUnitOfWork<T extends Message<?>>
      Parameters:
      phase - The phase for which to invoke registered handlers.
    • addHandler

      protected void addHandler(UnitOfWork.Phase phase, Consumer<UnitOfWork<T>> handler)
      Description copied from class: AbstractUnitOfWork
      Register the given handler with the Unit of Work. The handler will be invoked when the Unit of Work changes its phase to the given phase.
      Specified by:
      addHandler in class AbstractUnitOfWork<T extends Message<?>>
      Parameters:
      phase - the Phase of the Unit of Work at which to invoke the handler
      handler - the handler to add
    • setExecutionResult

      protected void setExecutionResult(ExecutionResult executionResult)
      Description copied from class: AbstractUnitOfWork
      Set the execution result of processing the current Message.
      Specified by:
      setExecutionResult in class AbstractUnitOfWork<T extends Message<?>>
      Parameters:
      executionResult - the ExecutionResult of the currently handled Message
    • setRollbackCause

      protected void setRollbackCause(Throwable cause)
      Description copied from class: AbstractUnitOfWork
      Sets the cause for rolling back this Unit of Work.
      Specified by:
      setRollbackCause in class AbstractUnitOfWork<T extends Message<?>>
      Parameters:
      cause - The cause for rolling back this Unit of Work
    • executeWithResult

      public <R> ResultMessage<R> executeWithResult(Callable<R> task, @Nonnull RollbackConfiguration rollbackConfiguration)
      Execute the given task in the context of this Unit of Work. If the Unit of Work is not started yet it will be started.

      If the task executes successfully the Unit of Work is committed and the result of the task is returned. If execution fails, the rollbackConfiguration determines if the Unit of Work should be rolled back or committed.

      This feature is not supported by this Unit of Work.

      Type Parameters:
      R - the type of result that is returned after successful execution
      Parameters:
      task - the task to execute
      rollbackConfiguration - configuration that determines whether or not to rollback the unit of work when task execution fails
      Returns:
      The result of the task wrapped in Result Message
    • getExecutionResult

      public ExecutionResult getExecutionResult()
      Description copied from interface: UnitOfWork
      Get the result of the task that was executed by this Unit of Work. If the Unit of Work has not been given a task to execute this method returns null.

      Note that the value of the returned ExecutionResult's ExecutionResult.isExceptionResult() does not determine whether or not the UnitOfWork has been rolled back. To check whether or not the UnitOfWork was rolled back check UnitOfWork.isRolledBack().

      Returns:
      The result of the task executed by this Unit of Work, or null if the Unit of Work has not been given a task to execute.