public class DefaultUnitOfWork<T extends Message<?>> extends AbstractUnitOfWork<T>
UnitOfWork.Phase
Constructor and Description |
---|
DefaultUnitOfWork(T message)
Initializes a Unit of Work (without starting it).
|
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> ResultMessage<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 . |
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.
|
static <T extends Message<?>> |
startAndGet(T message)
Starts a new DefaultUnitOfWork instance, registering it a CurrentUnitOfWork.
|
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, parent, phase, registerCorrelationDataProvider, resources, rollback, setPhase, start
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
attachTransaction, execute, execute, executeWithResult, getOrComputeResource, getOrDefaultResource, getResource, isActive, isCurrent, isRoot, rollback, root
public DefaultUnitOfWork(T message)
message
- the message that will be processed in the context of the unit of workpublic static <T extends Message<?>> DefaultUnitOfWork<T> startAndGet(T message)
Note that this Unit Of Work type is not meant to be shared among different Threads. A single DefaultUnitOfWork instance should be used exclusively by the Thread that created it.
message
- the message that will be processed in the context of the unit of workpublic <R> ResultMessage<R> executeWithResult(Callable<R> task, @Nonnull RollbackConfiguration rollbackConfiguration)
UnitOfWork
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.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 failsprotected void setRollbackCause(Throwable cause)
AbstractUnitOfWork
setRollbackCause
in class AbstractUnitOfWork<T extends Message<?>>
cause
- The cause for rolling back this Unit of Workprotected 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 addpublic 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 messagepublic 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.protected void setExecutionResult(ExecutionResult executionResult)
AbstractUnitOfWork
Message
.setExecutionResult
in class AbstractUnitOfWork<T extends Message<?>>
executionResult
- the ExecutionResult of the currently handled MessageCopyright © 2010–2024. All rights reserved.