org.apache.camel.impl
Class MDCUnitOfWork

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

public class MDCUnitOfWork
extends DefaultUnitOfWork

This unit of work supports MDC.

Version:

Field Summary
static String MDC_CORRELATION_ID
           
static String MDC_EXCHANGE_ID
           
static String MDC_ROUTE_ID
           
static String MDC_TRANSACTION_KEY
           
 
Fields inherited from class org.apache.camel.impl.DefaultUnitOfWork
log
 
Constructor Summary
MDCUnitOfWork(Exchange exchange)
           
 
Method Summary
 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 beginTransactedBy(Object key)
          Mark this UnitOfWork as being transacted by the given transaction key.
 void clear()
          Clears information put on the MDC by this MDCUnitOfWork
 void endTransactedBy(Object key)
          Mark this UnitOfWork as not transacted anymore by the given transaction definition.
 UnitOfWork newInstance(Exchange exchange)
           
 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 stop()
          Stops the service
 String toString()
           
 
Methods inherited from class org.apache.camel.impl.DefaultUnitOfWork
addSynchronization, beginSubUnitOfWork, createChildUnitOfWork, done, endSubUnitOfWork, getId, getOriginalInMessage, getRouteContext, getSubUnitOfWorkCallback, getTracedRouteNodes, handoverSynchronization, isTransacted, isTransactedBy, removeSynchronization, setParentUnitOfWork, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MDC_EXCHANGE_ID

public static final String MDC_EXCHANGE_ID
See Also:
Constant Field Values

MDC_CORRELATION_ID

public static final String MDC_CORRELATION_ID
See Also:
Constant Field Values

MDC_ROUTE_ID

public static final String MDC_ROUTE_ID
See Also:
Constant Field Values

MDC_TRANSACTION_KEY

public static final String MDC_TRANSACTION_KEY
See Also:
Constant Field Values
Constructor Detail

MDCUnitOfWork

public MDCUnitOfWork(Exchange exchange)
Method Detail

newInstance

public UnitOfWork newInstance(Exchange exchange)

stop

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

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

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
Overrides:
pushRouteContext in class DefaultUnitOfWork
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
Overrides:
popRouteContext in class DefaultUnitOfWork
Returns:
the route context or null if none existed

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
Overrides:
beginTransactedBy in class DefaultUnitOfWork
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
Overrides:
endTransactedBy in class DefaultUnitOfWork
Parameters:
key - the transaction key

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
Overrides:
beforeProcess in class DefaultUnitOfWork
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
Overrides:
afterProcess in class DefaultUnitOfWork
Parameters:
processor - the processor executed
exchange - the current exchange
callback - the callback used
doneSync - whether the process was done synchronously or asynchronously

clear

public void clear()
Clears information put on the MDC by this MDCUnitOfWork


toString

public String toString()
Overrides:
toString in class DefaultUnitOfWork


Apache CAMEL