public interface OptimisticLockingAggregationRepository extends AggregationRepository
AggregationRepository
which also supports
optimistic locking.
If the underlying implementation cannot perform optimistic locking, it should
not implement this interface.MemoryAggregationRepository
Modifier and Type | Interface and Description |
---|---|
static class |
OptimisticLockingAggregationRepository.OptimisticLockingException
Exception used by an AggregationRepository to indicate that an optimistic
update error has occurred and that the operation should be retried by the caller. |
Modifier and Type | Method and Description |
---|---|
Exchange |
add(CamelContext camelContext,
String key,
Exchange oldExchange,
Exchange newExchange)
Add the given
Exchange under the correlation key. |
void |
remove(CamelContext camelContext,
String key,
Exchange exchange)
Removes the given Exchange when both the supplied key and Exchange are present in the repository.
|
add, confirm, get, getKeys
Exchange add(CamelContext camelContext, String key, Exchange oldExchange, Exchange newExchange) throws OptimisticLockingAggregationRepository.OptimisticLockingException
Exchange
under the correlation key.
Will perform optimistic locking to replace expected existing exchange with the new supplied exchange.
If the oldExchange
is null the underlying implementation is to assume this is the very first Exchange for the
supplied correlation key. When the implementation comes to store to the Exchange if there is already an existing
Exchange present for this correlation key the implementation should throw an OptimisticLockingException.
If the oldExchange
is not null the underlying implementation should use it to compare with the existing exchange
when doing an atomic compare-and-set/swap operation.
The implementation may achieve this by storing a version identifier in the Exchange as a parameter. Set before
returning from AggregationRepository.get(org.apache.camel.CamelContext, String)
} and retrieved from the
exchange when passed to AggregationRepository.add(org.apache.camel.CamelContext, String, org.apache.camel.Exchange)
.
Note: The MemoryAggregationRepository
is an exception to this recommendation.
It uses the oldExchange
's Object identify to perform it's compare-and-set/swap operation, instead of a version
parameter. This is not the recommended approach, and should be avoided.
The AggregateProcessor
will ensure that the exchange received from
AggregationRepository.get(org.apache.camel.CamelContext, String)
is passed as oldExchange
,
and that the aggregated exchange received from the AggregationStrategy
is passed as the newExchange
.camelContext
- the current CamelContextkey
- the correlation keyoldExchange
- the old exchange that is expected to exist when replacing with the new exchangenewExchange
- the new aggregated exchange, to replace old exchangeOptimisticLockingAggregationRepository.OptimisticLockingException
- This should be thrown when the currently stored exchange differs from the supplied oldExchange.void remove(CamelContext camelContext, String key, Exchange exchange) throws OptimisticLockingAggregationRepository.OptimisticLockingException
remove
in interface AggregationRepository
camelContext
- the current CamelContextkey
- the correlation keyexchange
- the exchange to removeOptimisticLockingAggregationRepository.OptimisticLockingException
- This should be thrown when the exchange has already been deleted, or otherwise modified.Apache Camel