org.apache.camel.impl
Class DefaultUnitOfWork

java.lang.Object
  extended by org.apache.camel.impl.DefaultUnitOfWork
All Implemented Interfaces:
Service, UnitOfWork
Direct Known Subclasses:
MDCUnitOfWork

public class DefaultUnitOfWork
extends Object
implements UnitOfWork, Service

The default implementation of UnitOfWork


Field Summary
protected  org.slf4j.Logger log
           
 
Constructor Summary
DefaultUnitOfWork(Exchange exchange)
           
 
Method Summary
 void addSynchronization(Synchronization synchronization)
          Adds a synchronization hook
 void afterProcess(Processor processor, Exchange exchange, AsyncCallback callback, boolean doneSync)
          Strategy for optional work to be executed after the processing
 AsyncCallback beforeProcess(Processor processor, Exchange exchange, AsyncCallback callback)
          Strategy for optional work to be execute before processing

For example the MDCUnitOfWork leverages this to ensure MDC is handled correctly during routing exchanges using the asynchronous routing engine.

 void beginSubUnitOfWork(Exchange exchange)
          Begins a SubUnitOfWork, where sub (child) unit of works participate in a parent unit of work.
 void beginTransactedBy(Object key)
          Mark this UnitOfWork as being transacted by the given transaction key.
 UnitOfWork createChildUnitOfWork(Exchange childExchange)
          Create a child unit of work, which is associated to this unit of work as its parent.
 void done(Exchange exchange)
          Invoked when this unit of work has been completed, whether it has failed or completed
 void endSubUnitOfWork(Exchange exchange)
          Ends a SubUnitOfWork.
 void endTransactedBy(Object key)
          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.
 SubUnitOfWorkCallback getSubUnitOfWorkCallback()
          Gets the SubUnitOfWorkCallback if this unit of work participates in a sub unit of work.
 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 key)
          Are we already transacted by the given transaction key?
 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
 void setParentUnitOfWork(UnitOfWork parentUnitOfWork)
          Sets the parent unit of work.
 void start()
          Starts the service
 void stop()
          Stops the service
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected final transient org.slf4j.Logger log
Constructor Detail

DefaultUnitOfWork

public DefaultUnitOfWork(Exchange exchange)
Method Detail

setParentUnitOfWork

public void setParentUnitOfWork(UnitOfWork parentUnitOfWork)
Description copied from interface: UnitOfWork
Sets the parent unit of work.

Specified by:
setParentUnitOfWork in interface UnitOfWork
Parameters:
parentUnitOfWork - the parent

createChildUnitOfWork

public UnitOfWork createChildUnitOfWork(Exchange childExchange)
Description copied from interface: UnitOfWork
Create a child unit of work, which is associated to this unit of work as its parent.

This is often used when EIPs need to support SubUnitOfWorks. For example a splitter, where the sub messages of the splitter all participate in the same sub unit of work. That sub unit of work then decides whether the Splitter (in general) is failed or a processed successfully.

Specified by:
createChildUnitOfWork in interface UnitOfWork
Parameters:
childExchange - the child exchange
Returns:
the created child unit of work
See Also:
SubUnitOfWork, SubUnitOfWorkCallback

start

public void start()
           throws Exception
Description copied from interface: Service
Starts the service

Specified by:
start in interface Service
Throws:
Exception - is thrown if starting failed

stop

public void stop()
          throws Exception
Description copied from interface: Service
Stops the service

Specified by:
stop in interface Service
Throws:
Exception - is thrown if stopping failed

addSynchronization

public void addSynchronization(Synchronization synchronization)
Description copied from interface: UnitOfWork
Adds a synchronization hook

Specified by:
addSynchronization in interface UnitOfWork
Parameters:
synchronization - the hook

removeSynchronization

public void removeSynchronization(Synchronization synchronization)
Description copied from interface: UnitOfWork
Removes a synchronization hook

Specified by:
removeSynchronization in interface UnitOfWork
Parameters:
synchronization - the hook

handoverSynchronization

public void handoverSynchronization(Exchange target)
Description copied from interface: UnitOfWork
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.

Specified by:
handoverSynchronization in interface UnitOfWork
Parameters:
target - the target exchange

done

public void done(Exchange exchange)
Description copied from interface: UnitOfWork
Invoked when this unit of work has been completed, whether it has failed or completed

Specified by:
done in interface UnitOfWork
Parameters:
exchange - the current exchange

getId

public String getId()
Description copied from interface: UnitOfWork
Returns the unique ID of this unit of work, lazily creating one if it does not yet have one

Specified by:
getId in interface UnitOfWork
Returns:
the unique ID

getOriginalInMessage

public Message getOriginalInMessage()
Description copied from interface: UnitOfWork
Gets the original IN Message this Unit of Work was started with.

Important: This is subject for change in a later Camel release, where we plan to only support getting the original IN message if you have enabled this option explicit.

Specified by:
getOriginalInMessage in interface UnitOfWork
Returns:
the original IN Message, may return null in a later Camel release (see important note).

getTracedRouteNodes

public TracedRouteNodes getTracedRouteNodes()
Description copied from interface: UnitOfWork
Gets tracing information

Specified by:
getTracedRouteNodes in interface UnitOfWork
Returns:
trace information

isTransacted

public boolean isTransacted()
Description copied from interface: UnitOfWork
Are we transacted?

Specified by:
isTransacted in interface UnitOfWork
Returns:
true if transacted, false otherwise

isTransactedBy

public boolean isTransactedBy(Object key)
Description copied from interface: UnitOfWork
Are we already transacted by the given transaction key?

Specified by:
isTransactedBy in interface UnitOfWork
Parameters:
key - the transaction key
Returns:
true if already, false otherwise

beginTransactedBy

public void beginTransactedBy(Object key)
Description copied from interface: UnitOfWork
Mark this UnitOfWork as being transacted by the given transaction key.

When the transaction is completed then invoke the UnitOfWork.endTransactedBy(Object) method using the same key.

Specified by:
beginTransactedBy in interface UnitOfWork
Parameters:
key - the transaction key

endTransactedBy

public void endTransactedBy(Object key)
Description copied from interface: UnitOfWork
Mark this UnitOfWork as not transacted anymore by the given transaction definition.

Specified by:
endTransactedBy in interface UnitOfWork
Parameters:
key - the transaction key

getRouteContext

public RouteContext getRouteContext()
Description copied from interface: UnitOfWork
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.

Specified by:
getRouteContext in interface UnitOfWork
Returns:
the route context
See Also:
UnitOfWork.pushRouteContext(RouteContext), UnitOfWork.popRouteContext()

pushRouteContext

public void pushRouteContext(RouteContext routeContext)
Description copied from interface: UnitOfWork
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.

Specified by:
pushRouteContext in interface UnitOfWork
Parameters:
routeContext - the route context

popRouteContext

public RouteContext popRouteContext()
Description copied from interface: UnitOfWork
When finished being routed under the current RouteContext it should be removed.

Specified by:
popRouteContext in interface UnitOfWork
Returns:
the route context or null if none existed

beforeProcess

public AsyncCallback beforeProcess(Processor processor,
                                   Exchange exchange,
                                   AsyncCallback callback)
Description copied from interface: UnitOfWork
Strategy for optional work to be execute before processing

For example the MDCUnitOfWork leverages this to ensure MDC is handled correctly during routing exchanges using the asynchronous routing engine.

Specified by:
beforeProcess in interface UnitOfWork
Parameters:
processor - the processor to be executed
exchange - the current exchange
callback - the callback
Returns:
the callback to be used (can return a wrapped callback)

afterProcess

public void afterProcess(Processor processor,
                         Exchange exchange,
                         AsyncCallback callback,
                         boolean doneSync)
Description copied from interface: UnitOfWork
Strategy for optional work to be executed after the processing

Specified by:
afterProcess in interface UnitOfWork
Parameters:
processor - the processor executed
exchange - the current exchange
callback - the callback used
doneSync - whether the process was done synchronously or asynchronously

beginSubUnitOfWork

public void beginSubUnitOfWork(Exchange exchange)
Description copied from interface: UnitOfWork
Begins a SubUnitOfWork, where sub (child) unit of works participate in a parent unit of work. The SubUnitOfWork will callback to the parent unit of work using SubUnitOfWorkCallbacks.

Specified by:
beginSubUnitOfWork in interface UnitOfWork
Parameters:
exchange - the exchange

endSubUnitOfWork

public void endSubUnitOfWork(Exchange exchange)
Description copied from interface: UnitOfWork
Ends a SubUnitOfWork.

The UnitOfWork.beginSubUnitOfWork(org.apache.camel.Exchange) must have been invoked prior to this operation.

Specified by:
endSubUnitOfWork in interface UnitOfWork
Parameters:
exchange - the exchange

getSubUnitOfWorkCallback

public SubUnitOfWorkCallback getSubUnitOfWorkCallback()
Description copied from interface: UnitOfWork
Gets the SubUnitOfWorkCallback if this unit of work participates in a sub unit of work.

Specified by:
getSubUnitOfWorkCallback in interface UnitOfWork
Returns:
the callback, or null if this unit of work is not part of a sub unit of work.
See Also:
UnitOfWork.beginSubUnitOfWork(org.apache.camel.Exchange)

toString

public String toString()
Overrides:
toString in class Object


Apache CAMEL