Package org.apache.camel.spi
Interface UnitOfWork
-
public interface UnitOfWork
An object representing the unit of work processing anExchange
which allows the use ofSynchronization
hooks. 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 String
MDC_BREADCRUMB_ID
static String
MDC_CAMEL_CONTEXT_ID
static String
MDC_CORRELATION_ID
static String
MDC_EXCHANGE_ID
static String
MDC_MESSAGE_ID
static String
MDC_ROUTE_ID
static String
MDC_STEP_ID
static String
MDC_TRANSACTION_KEY
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addSynchronization(Synchronization synchronization)
Adds a synchronization hookvoid
afterProcess(Processor processor, Exchange exchange, AsyncCallback callback, boolean doneSync)
Strategy for work to be executed after the processingvoid
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 work to be executed before processing.void
beforeRoute(Exchange exchange, Route route)
Invoked when this unit of work is about to be routed by the given route.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 completedvoid
endTransactedBy(Object key)
Mark this UnitOfWork as not transacted anymore by the given transaction definition.Message
getOriginalInMessage()
Gets the original INMessage
this Unit of Work was started with.Route
getRoute()
Gets theRoute
that thisUnitOfWork
currently is being routed through.void
handoverSynchronization(Exchange target)
Handover all the registered synchronizations to the targetExchange
.void
handoverSynchronization(Exchange target, Predicate<Synchronization> filter)
Handover all the registered synchronizations to the targetExchange
.boolean
isBeforeAfterProcess()
Whether the unit of work should call the before/after process methods or not.boolean
isTransacted()
Are we transacted?boolean
isTransactedBy(Object key)
Are we already transacted by the given transaction key?boolean
onPrepare(Exchange exchange)
Prepares this unit of work with the given inputExchange
Route
popRoute()
When finished being routed under the currentRoute
it should be removed.void
pushRoute(Route route)
Pushes theRoute
that thisUnitOfWork
currently is being routed through.void
removeSynchronization(Synchronization synchronization)
Removes a synchronization hookvoid
reset()
Clears the unit of work from user data, so it may be reused.int
routeStackLevel()
Gets theRoute
level-of-depth that thisUnitOfWork
currently is being routed through.void
setParentUnitOfWork(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 theExchange
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
-
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 theExchange
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 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 INMessage
this 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 theRoute
that thisUnitOfWork
currently is being routed through. Notice that anExchange
can be routed through multiple routes and thus theRoute
can change over time.- Returns:
- the route, maybe be null if not routed through a route currently.
-
pushRoute
void pushRoute(Route route)
Pushes theRoute
that thisUnitOfWork
currently is being routed through. Notice that anExchange
can be routed through multiple routes and thus theRoute
can change over time.- Parameters:
route
- the route
-
popRoute
Route popRoute()
When finished being routed under the currentRoute
it should be removed.- Returns:
- the route or null if none existed
-
routeStackLevel
int routeStackLevel()
Gets theRoute
level-of-depth that thisUnitOfWork
currently is being routed through. Notice that anExchange
can 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
-
-