public abstract class DisruptorUnitOfWork<T extends Message<?>> extends AbstractUnitOfWork<T>
DisruptorCommandBus
. It expects the executing command message to
target a single aggregate instance.UnitOfWork.Phase
Constructor and Description |
---|
DisruptorUnitOfWork() |
Modifier and Type | Method and Description |
---|---|
protected void |
addHandler(UnitOfWork.Phase phase,
Consumer<UnitOfWork<T>> handler)
Register the given
handler with the Unit of Work. |
<R> R |
executeWithResult(Callable<R> task,
RollbackConfiguration rollbackConfiguration)
Execute the given
task in the context of this Unit of Work. |
ExecutionResult |
getExecutionResult()
Get the result of the task that was executed by this Unit of Work.
|
T |
getMessage()
Get the message that is being processed by the Unit of Work.
|
protected void |
notifyHandlers(UnitOfWork.Phase phase)
Notify the handlers attached to the given
phase . |
Optional<UnitOfWork<?>> |
parent()
Returns an optional for the parent of this Unit of Work.
|
void |
pause()
Pause this Unit of Work by unregistering it with the
CurrentUnitOfWork . |
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. |
void |
resume()
Resume a paused Unit of Work by registering it with the
CurrentUnitOfWork . |
protected void |
setExecutionResult(ExecutionResult executionResult)
Set the execution result of processing the current
Message . |
protected void |
setRollbackCause(Throwable cause)
Sets the cause for rolling back this Unit of Work.
|
UnitOfWork<T> |
transformMessage(Function<T,? extends Message<?>> transformOperator)
Transform the Message being processed using the given operator and stores the result.
|
afterCommit, changePhase, commit, correlationDataProviders, getCorrelationData, isRolledBack, onCleanup, onCommit, onPrepareCommit, onRollback, phase, registerCorrelationDataProvider, resources, rollback, setPhase, start
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
execute, execute, executeWithResult, getOrComputeResource, getOrDefaultResource, getResource, isActive, isCurrent, isRoot, rollback, root
public void reset(T message)
NOT_STARTED
, replacing the message
of this Unit of Work with given message
, and clearing its collection of registered handlers.message
- the new Message that is about to be processed.public void pause()
CurrentUnitOfWork
. This will detach it from the
current thread.public void resume()
CurrentUnitOfWork
. This will attach it to the
current thread again.public Optional<UnitOfWork<?>> parent()
UnitOfWork
parent
in interface UnitOfWork<T extends Message<?>>
parent
in class AbstractUnitOfWork<T extends Message<?>>
public T getMessage()
UnitOfWork
public UnitOfWork<T> transformMessage(Function<T,? extends Message<?>> transformOperator)
UnitOfWork
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.
transformOperator
- The transform operator to apply to the stored messageprotected void notifyHandlers(UnitOfWork.Phase phase)
AbstractUnitOfWork
phase
.notifyHandlers
in class AbstractUnitOfWork<T extends Message<?>>
phase
- The phase for which to invoke registered handlers.protected void addHandler(UnitOfWork.Phase phase, Consumer<UnitOfWork<T>> handler)
AbstractUnitOfWork
handler
with the Unit of Work. The handler will be invoked when the
Unit of Work changes its phase to the given phase
.addHandler
in class AbstractUnitOfWork<T extends Message<?>>
phase
- the Phase of the Unit of Work at which to invoke the handlerhandler
- the handler to addprotected void setExecutionResult(ExecutionResult executionResult)
AbstractUnitOfWork
Message
.setExecutionResult
in class AbstractUnitOfWork<T extends Message<?>>
executionResult
- the ExecutionResult of the currently handled Messageprotected void setRollbackCause(Throwable cause)
AbstractUnitOfWork
setRollbackCause
in class AbstractUnitOfWork<T extends Message<?>>
cause
- The cause for rolling back this Unit of Workpublic <R> R executeWithResult(Callable<R> task, RollbackConfiguration rollbackConfiguration) throws Exception
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.R
- the type of result that is returned after successful executiontask
- the task to executerollbackConfiguration
- configuration that determines whether or not to rollback the unit of work when task
execution failsException
- if an Exception was raised while executing the taskpublic ExecutionResult getExecutionResult()
UnitOfWork
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()
.
null
if the Unit of Work has not
been given a task to execute.Copyright © 2010–2017. All rights reserved.