Package org.apache.camel.spi
Interface UnitOfWork
-
public interface UnitOfWorkAn object representing the unit of work processing anExchangewhich allows the use ofSynchronizationhooks. This object might map one-to-one with a transaction in JPA or Spring; or might not.
-
-
Field Summary
Fields Modifier and Type Field Description static StringMDC_BREADCRUMB_IDstatic StringMDC_CAMEL_CONTEXT_IDstatic StringMDC_CORRELATION_IDstatic StringMDC_EXCHANGE_IDstatic StringMDC_MESSAGE_IDstatic StringMDC_ROUTE_IDstatic StringMDC_STEP_IDstatic StringMDC_TRANSACTION_KEY
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddSynchronization(Synchronization synchronization)Adds a synchronization hookvoidafterProcess(Processor processor, Exchange exchange, AsyncCallback callback, boolean doneSync)Strategy for work to be executed after the processingvoidafterRoute(Exchange exchange, Route route)Invoked when this unit of work is done being routed by the given route.AsyncCallbackbeforeProcess(Processor processor, Exchange exchange, AsyncCallback callback)Strategy for work to be executed before processing.voidbeforeRoute(Exchange exchange, Route route)Invoked when this unit of work is about to be routed by the given route.voidbeginTransactedBy(Object key)Mark this UnitOfWork as being transacted by the given transaction key.booleancontainsSynchronization(Synchronization synchronization)Checks if the passed synchronization hook is already part of this unit of work.UnitOfWorkcreateChildUnitOfWork(Exchange childExchange)Create a child unit of work, which is associated to this unit of work as its parent.voiddone(Exchange exchange)Invoked when this unit of work has been completed, whether it has failed or completedvoidendTransactedBy(Object key)Mark this UnitOfWork as not transacted anymore by the given transaction definition.MessagegetOriginalInMessage()Gets the original INMessagethis Unit of Work was started with.RoutegetRoute()Gets theRoutethat thisUnitOfWorkcurrently is being routed through.voidhandoverSynchronization(Exchange target)Handover all the registered synchronizations to the targetExchange.voidhandoverSynchronization(Exchange target, Predicate<Synchronization> filter)Handover all the registered synchronizations to the targetExchange.booleanisBeforeAfterProcess()Whether the unit of work should call the before/after process methods or not.booleanisTransacted()Are we transacted?booleanisTransactedBy(Object key)Are we already transacted by the given transaction key?booleanonPrepare(Exchange exchange)Prepares this unit of work with the given inputExchangeRoutepopRoute()When finished being routed under the currentRouteit should be removed.voidpushRoute(Route route)Pushes theRoutethat thisUnitOfWorkcurrently is being routed through.voidremoveSynchronization(Synchronization synchronization)Removes a synchronization hookvoidreset()Clears the unit of work from user data, so it may be reused.introuteStackLevel()Gets theRoutelevel-of-depth that thisUnitOfWorkcurrently is being routed through.voidsetParentUnitOfWork(UnitOfWork parentUnitOfWork)Sets the parent unit of work.
-
-
-
Field Detail
-
MDC_BREADCRUMB_ID
static final String MDC_BREADCRUMB_ID
- See Also:
- Constant Field Values
-
MDC_EXCHANGE_ID
static final String MDC_EXCHANGE_ID
- See Also:
- Constant Field Values
-
MDC_MESSAGE_ID
static final String MDC_MESSAGE_ID
- See Also:
- Constant Field Values
-
MDC_CORRELATION_ID
static final String MDC_CORRELATION_ID
- See Also:
- Constant Field Values
-
MDC_ROUTE_ID
static final String MDC_ROUTE_ID
- See Also:
- Constant Field Values
-
MDC_STEP_ID
static final String MDC_STEP_ID
- See Also:
- Constant Field Values
-
MDC_CAMEL_CONTEXT_ID
static final String MDC_CAMEL_CONTEXT_ID
- See Also:
- Constant Field Values
-
MDC_TRANSACTION_KEY
static final String MDC_TRANSACTION_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
reset
void reset()
Clears the unit of work from user data, so it may be reused. Important: This API is NOT intended for Camel end users, but used internally by Camel itself.
-
onPrepare
boolean onPrepare(Exchange exchange)
Prepares this unit of work with the given inputExchange- Parameters:
exchange- the exchange- Returns:
- true if the unit of work was created and prepared, false if already prepared
-
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
-
containsSynchronization
boolean containsSynchronization(Synchronization synchronization)
Checks if the passed synchronization hook is already part of this unit of work.- Parameters:
synchronization- the hook- Returns:
- true, if the passed synchronization is part of this unit of work, else false
-
handoverSynchronization
void handoverSynchronization(Exchange target)
Handover all the registered synchronizations to the targetExchange. This is used when a route turns into asynchronous and theExchangethat 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
-
handoverSynchronization
void handoverSynchronization(Exchange target, Predicate<Synchronization> filter)
Handover all the registered synchronizations to the targetExchange. This is used when a route turns into asynchronous and theExchangethat is continued and routed in the async thread should do the on completion callbacks instead of the original synchronous thread.- Parameters:
target- the target exchangefilter- optional filter to only handover if filter returns true
-
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
-
beforeRoute
void beforeRoute(Exchange exchange, Route route)
Invoked when this unit of work is about to be routed by the given route.- Parameters:
exchange- the current exchangeroute- the route
-
afterRoute
void afterRoute(Exchange exchange, Route route)
Invoked when this unit of work is done being routed by the given route.- Parameters:
exchange- the current exchangeroute- the route
-
getOriginalInMessage
Message getOriginalInMessage()
Gets the original INMessagethis Unit of Work was started with. The original message is only returned if the optionRuntimeConfiguration.isAllowUseOriginalMessage()is enabled. If its disabled an IllegalStateException is thrown.- Returns:
- the original IN
Message
-
isTransacted
boolean isTransacted()
Are we transacted?- Returns:
- true if transacted, false otherwise
-
isTransactedBy
boolean isTransactedBy(Object key)
Are we already transacted by the given transaction key?- Parameters:
key- the transaction key- Returns:
- true if already, false otherwise
-
beginTransactedBy
void beginTransactedBy(Object key)
Mark this UnitOfWork as being transacted by the given transaction key. When the transaction is completed then invoke theendTransactedBy(Object)method using the same key.- Parameters:
key- the transaction key
-
endTransactedBy
void endTransactedBy(Object key)
Mark this UnitOfWork as not transacted anymore by the given transaction definition.- Parameters:
key- the transaction key
-
getRoute
Route getRoute()
Gets theRoutethat thisUnitOfWorkcurrently is being routed through. Notice that anExchangecan be routed through multiple routes and thus theRoutecan change over time.- Returns:
- the route, maybe be null if not routed through a route currently.
-
pushRoute
void pushRoute(Route route)
Pushes theRoutethat thisUnitOfWorkcurrently is being routed through. Notice that anExchangecan be routed through multiple routes and thus theRoutecan change over time.- Parameters:
route- the route
-
popRoute
Route popRoute()
When finished being routed under the currentRouteit should be removed.- Returns:
- the route or null if none existed
-
routeStackLevel
int routeStackLevel()
Gets theRoutelevel-of-depth that thisUnitOfWorkcurrently is being routed through. Notice that anExchangecan be routed through multiple routes and thus the level of depth can change over time. If level is 1 then the current route is at the first route (original route). Maybe be 0 if not routed through a route currently.- Returns:
- the route level-of-depth
-
isBeforeAfterProcess
boolean isBeforeAfterProcess()
Whether the unit of work should call the before/after process methods or not.
-
beforeProcess
AsyncCallback beforeProcess(Processor processor, Exchange exchange, AsyncCallback callback)
Strategy for work to be executed before processing. For example the MDCUnitOfWork leverages this to ensure MDC is handled correctly during routing exchanges using the asynchronous routing engine. This requiresisBeforeAfterProcess()returns true to be enabled.- Parameters:
processor- the processor to be executedexchange- the current exchangecallback- the callback- Returns:
- the callback to be used (can return a wrapped callback)
-
afterProcess
void afterProcess(Processor processor, Exchange exchange, AsyncCallback callback, boolean doneSync)
Strategy for work to be executed after the processing This requiresisBeforeAfterProcess()returns true to be enabled.- Parameters:
processor- the processor executedexchange- the current exchangecallback- the callback useddoneSync- whether the process was done synchronously or asynchronously
-
createChildUnitOfWork
UnitOfWork createChildUnitOfWork(Exchange childExchange)
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 child unit of works. 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.- Parameters:
childExchange- the child exchange- Returns:
- the created child unit of work
-
setParentUnitOfWork
void setParentUnitOfWork(UnitOfWork parentUnitOfWork)
Sets the parent unit of work.- Parameters:
parentUnitOfWork- the parent
-
-