org.apache.camel.spi
Interface UnitOfWork

All Known Implementing Classes:
DefaultUnitOfWork

public interface UnitOfWork

An object representing the unit of work processing an Exchange which allows the use of Synchronization hooks. This object might map one-to-one with a transaction in JPA or Spring; or might not.

Version:
$Revision: 20114 $

Method Summary
 void addSynchronization(Synchronization synchronization)
          Adds a synchronization hook
 void beginTransactedBy(Object transactionDefinition)
          Mark this UnitOfWork as being transacted by the given transaction definition.
 void done(Exchange exchange)
          Invoked when this unit of work has been completed, whether it has failed or completed
 void endTransactedBy(Object transactionDefinition)
          Mark this UnitOfWork as not transacted anymore by the given transaction definition.
 String getId()
          Returns the unique ID of this unit of work, lazily creating one if it does not yet have one
 Message getOriginalInMessage()
          Gets the original IN Message this Unit of Work was started with.
 RouteContext getRouteContext()
          Gets the RouteContext that this UnitOfWork currently is being routed through.
 TracedRouteNodes getTracedRouteNodes()
          Gets tracing information
 void handoverSynchronization(Exchange target)
          Handover all the registered synchronizations to the target Exchange.
 boolean isTransacted()
          Are we transacted?
 boolean isTransactedBy(Object transactionDefinition)
          Are we already transacted by the given transaction definition

The definition will most likely be a Spring TransactionTemplate when using Spring Transaction

 RouteContext popRouteContext()
          When finished being routed under the current RouteContext it should be removed.
 void pushRouteContext(RouteContext routeContext)
          Pushes the RouteContext that this UnitOfWork currently is being routed through.
 void removeSynchronization(Synchronization synchronization)
          Removes a synchronization hook
 

Method Detail

addSynchronization

void addSynchronization(Synchronization synchronization)
Adds a synchronization hook

Parameters:
synchronization - the hook

removeSynchronization

void removeSynchronization(Synchronization synchronization)
Removes a synchronization hook

Parameters:
synchronization - the hook

handoverSynchronization

void handoverSynchronization(Exchange target)
Handover all the registered synchronizations to the target Exchange.

This is used when a route turns into asynchronous and the Exchange that is continued and routed in the async thread should do the on completion callbacks instead of the original synchronous thread.

Parameters:
target - the target exchange

done

void done(Exchange exchange)
Invoked when this unit of work has been completed, whether it has failed or completed

Parameters:
exchange - the current exchange

getId

String getId()
Returns the unique ID of this unit of work, lazily creating one if it does not yet have one

Returns:
the unique ID

getOriginalInMessage

Message getOriginalInMessage()
Gets the original IN Message this Unit of Work was started with.

Returns:
the original IN Message

getTracedRouteNodes

TracedRouteNodes getTracedRouteNodes()
Gets tracing information

Returns:
trace information

isTransacted

boolean isTransacted()
Are we transacted?

Returns:
true if transacted, false otherwise

isTransactedBy

boolean isTransactedBy(Object transactionDefinition)
Are we already transacted by the given transaction definition

The definition will most likely be a Spring TransactionTemplate when using Spring Transaction

Parameters:
transactionDefinition - the transaction definition
Returns:
true if already, false otherwise

beginTransactedBy

void beginTransactedBy(Object transactionDefinition)
Mark this UnitOfWork as being transacted by the given transaction definition.

The definition will most likely be a Spring TransactionTemplate when using Spring Transaction

When the transaction is completed then invoke the endTransactedBy(Object) method.

Parameters:
transactionDefinition - the transaction definition

endTransactedBy

void endTransactedBy(Object transactionDefinition)
Mark this UnitOfWork as not transacted anymore by the given transaction definition.

The definition will most likely be a Spring TransactionTemplate when using Spring Transaction

Parameters:
transactionDefinition - the transaction definition

getRouteContext

RouteContext getRouteContext()
Gets the RouteContext that this UnitOfWork currently is being routed through.

Notice that an Exchange can be routed through multiple routes and thus the RouteContext can change over time.

Returns:
the route context
See Also:
pushRouteContext(RouteContext), popRouteContext()

pushRouteContext

void pushRouteContext(RouteContext routeContext)
Pushes the RouteContext that this UnitOfWork currently is being routed through.

Notice that an Exchange can be routed through multiple routes and thus the RouteContext can change over time.

Parameters:
routeContext - the route context

popRouteContext

RouteContext popRouteContext()
When finished being routed under the current RouteContext it should be removed.

Returns:
the route context or null if none existed


Apache CAMEL