public class DefaultUnitOfWork extends Object implements UnitOfWork, Service
UnitOfWork| Modifier | Constructor and Description |
|---|---|
|
DefaultUnitOfWork(Exchange exchange) |
protected |
DefaultUnitOfWork(Exchange exchange,
org.slf4j.Logger logger) |
| Modifier and Type | Method and Description |
|---|---|
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
|
void |
afterRoute(Exchange exchange,
Route route)
Invoked when this unit of work is done being routed by the given route.
|
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 |
beforeRoute(Exchange exchange,
Route route)
Invoked when this unit of work is about to be routed by the given route.
|
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.
|
boolean |
containsSynchronization(Synchronization synchronization)
Checks if the passed synchronization hook is already part of this unit of work.
|
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() |
public DefaultUnitOfWork(Exchange exchange)
protected DefaultUnitOfWork(Exchange exchange, org.slf4j.Logger logger)
public void setParentUnitOfWork(UnitOfWork parentUnitOfWork)
UnitOfWorksetParentUnitOfWork in interface UnitOfWorkparentUnitOfWork - the parentpublic UnitOfWork createChildUnitOfWork(Exchange childExchange)
UnitOfWorkSubUnitOfWorks. 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.createChildUnitOfWork in interface UnitOfWorkchildExchange - the child exchangeSubUnitOfWork,
SubUnitOfWorkCallbackpublic void start()
throws Exception
Servicepublic void stop()
throws Exception
Servicepublic void addSynchronization(Synchronization synchronization)
UnitOfWorkaddSynchronization in interface UnitOfWorksynchronization - the hookpublic void removeSynchronization(Synchronization synchronization)
UnitOfWorkremoveSynchronization in interface UnitOfWorksynchronization - the hookpublic boolean containsSynchronization(Synchronization synchronization)
UnitOfWorkcontainsSynchronization in interface UnitOfWorksynchronization - the hookpublic void handoverSynchronization(Exchange target)
UnitOfWorkExchange.
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.handoverSynchronization in interface UnitOfWorktarget - the target exchangepublic void done(Exchange exchange)
UnitOfWorkdone in interface UnitOfWorkexchange - the current exchangepublic void beforeRoute(Exchange exchange, Route route)
UnitOfWorkbeforeRoute in interface UnitOfWorkexchange - the current exchangeroute - the routepublic void afterRoute(Exchange exchange, Route route)
UnitOfWorkafterRoute in interface UnitOfWorkexchange - the current exchangeroute - the routepublic String getId()
UnitOfWorkgetId in interface UnitOfWorkpublic Message getOriginalInMessage()
UnitOfWorkMessage this Unit of Work was started with.
The original message is only returned if the option RuntimeConfiguration.isAllowUseOriginalMessage()
is enabled. If its disabled, then null is returned.getOriginalInMessage in interface UnitOfWorkMessage, or null if using original message is disabled.public TracedRouteNodes getTracedRouteNodes()
UnitOfWorkgetTracedRouteNodes in interface UnitOfWorkpublic boolean isTransacted()
UnitOfWorkisTransacted in interface UnitOfWorkpublic boolean isTransactedBy(Object key)
UnitOfWorkisTransactedBy in interface UnitOfWorkkey - the transaction keypublic void beginTransactedBy(Object key)
UnitOfWorkUnitOfWork.endTransactedBy(Object) method using the same key.beginTransactedBy in interface UnitOfWorkkey - the transaction keypublic void endTransactedBy(Object key)
UnitOfWorkendTransactedBy in interface UnitOfWorkkey - the transaction keypublic RouteContext getRouteContext()
UnitOfWorkRouteContext 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.getRouteContext in interface UnitOfWorkUnitOfWork.pushRouteContext(RouteContext),
UnitOfWork.popRouteContext()public void pushRouteContext(RouteContext routeContext)
UnitOfWorkRouteContext 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.pushRouteContext in interface UnitOfWorkrouteContext - the route contextpublic RouteContext popRouteContext()
UnitOfWorkRouteContext
it should be removed.popRouteContext in interface UnitOfWorkpublic AsyncCallback beforeProcess(Processor processor, Exchange exchange, AsyncCallback callback)
UnitOfWorkMDCUnitOfWork leverages this
to ensure MDC is handled correctly during routing exchanges using the
asynchronous routing engine.beforeProcess in interface UnitOfWorkprocessor - the processor to be executedexchange - the current exchangecallback - the callbackpublic void afterProcess(Processor processor, Exchange exchange, AsyncCallback callback, boolean doneSync)
UnitOfWorkafterProcess in interface UnitOfWorkprocessor - the processor executedexchange - the current exchangecallback - the callback useddoneSync - whether the process was done synchronously or asynchronouslypublic void beginSubUnitOfWork(Exchange exchange)
UnitOfWorkSubUnitOfWork, 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.beginSubUnitOfWork in interface UnitOfWorkexchange - the exchangepublic void endSubUnitOfWork(Exchange exchange)
UnitOfWorkSubUnitOfWork.
The UnitOfWork.beginSubUnitOfWork(org.apache.camel.Exchange) must have been invoked
prior to this operation.endSubUnitOfWork in interface UnitOfWorkexchange - the exchangepublic SubUnitOfWorkCallback getSubUnitOfWorkCallback()
UnitOfWorkSubUnitOfWorkCallback if this unit of work participates in a sub unit of work.getSubUnitOfWorkCallback in interface UnitOfWorkUnitOfWork.beginSubUnitOfWork(org.apache.camel.Exchange)Apache Camel