T
- The type of message handled by this Unit of Workpublic class BatchingUnitOfWork<T extends Message<?>> extends AbstractUnitOfWork<T>
UnitOfWork.Phase
Constructor and Description |
---|
BatchingUnitOfWork(List<T> messages)
Initializes a BatchingUnitOfWork for processing the given list of
messages . |
BatchingUnitOfWork(T... messages)
Initializes a BatchingUnitOfWork for processing the given batch of
messages . |
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.
|
Map<Message<?>,ExecutionResult> |
getExecutionResults()
Returns a Map of
ExecutionResult per Message. |
T |
getMessage()
Get the message that is being processed by the Unit of Work.
|
List<? extends Message<?>> |
getMessages()
Get the batch of messages that is being processed (or has been processed) by this unit of work.
|
boolean |
isFirstMessage()
Checks if the message being processed now is the first of the batch being processed in this unit of work.
|
boolean |
isFirstMessage(Message<?> message)
Checks if the given
message is the first of the batch being processed in this unit of work. |
boolean |
isLastMessage()
Checks if the message being processed now is the last of the batch being processed in this unit of work.
|
boolean |
isLastMessage(Message<?> message)
Checks if the given
message is the last of the batch being processed in this 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.
|
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
execute, execute, executeWithResult, getOrComputeResource, getOrDefaultResource, getResource, isActive, isCurrent, isRoot, rollback, root
@SafeVarargs public BatchingUnitOfWork(T... messages)
messages
.messages
- batch of messages to processpublic <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 implementation executes the given
task
for each of its messages. The return value is the
result of the last executed task.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 Map<Message<?>,ExecutionResult> getExecutionResults()
ExecutionResult
per Message. If the Unit of Work has not been given a task
to execute, the ExecutionResult is null
for each 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 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 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 setRollbackCause(Throwable cause)
AbstractUnitOfWork
setRollbackCause
in class AbstractUnitOfWork<T extends Message<?>>
cause
- The cause for rolling back this Unit of Workprotected 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 List<? extends Message<?>> getMessages()
public boolean isLastMessage(Message<?> message)
message
is the last of the batch being processed in this unit of work.message
- the message to check fortrue
if the message is the last of this batch, false
otherwisepublic boolean isLastMessage()
true
if the message is the last of this batch, false
otherwisepublic boolean isFirstMessage(Message<?> message)
message
is the first of the batch being processed in this unit of work.message
- the message to checktrue
if the message is the first of this batch, false
otherwisepublic boolean isFirstMessage()
true
if the message is the first of this batch, false
otherwiseCopyright © 2010–2017. All rights reserved.