public class MemoryAggregationRepository extends ServiceSupport implements OptimisticLockingAggregationRepository
AggregationRepository which stores Exchanges in memory only.
Supports both optimistic locking and non-optimistic locking modes. Defaults to non-optimistic locking mode.OptimisticLockingAggregationRepository.OptimisticLockingExceptionshutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending| Constructor and Description |
|---|
MemoryAggregationRepository() |
MemoryAggregationRepository(boolean optimisticLocking) |
| Modifier and Type | Method and Description |
|---|---|
Exchange |
add(CamelContext camelContext,
String key,
Exchange exchange)
Add the given
Exchange under the correlation key. |
Exchange |
add(CamelContext camelContext,
String key,
Exchange oldExchange,
Exchange newExchange)
Add the given
Exchange under the correlation key. |
void |
confirm(CamelContext camelContext,
String exchangeId)
Confirms the completion of the
Exchange. |
protected void |
doStart()
Implementations override this method to support customized start/stop.
|
protected void |
doStop()
Implementations override this method to support customized start/stop.
|
Exchange |
get(CamelContext camelContext,
String key)
Gets the given exchange with the correlation key
This method is always invoked for any incoming exchange in the aggregator.
|
Set<String> |
getKeys()
Gets the keys currently in the repository.
|
void |
remove(CamelContext camelContext,
String key,
Exchange exchange)
Removes the given Exchange when both the supplied key and Exchange are present in the repository.
|
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendpublic MemoryAggregationRepository()
public MemoryAggregationRepository(boolean optimisticLocking)
public Exchange add(CamelContext camelContext, String key, Exchange oldExchange, Exchange newExchange)
OptimisticLockingAggregationRepositoryExchange 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.add in interface OptimisticLockingAggregationRepositorycamelContext - 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 exchangepublic Exchange add(CamelContext camelContext, String key, Exchange exchange)
AggregationRepositoryExchange under the correlation key.
Will replace any existing exchange.
Important: This method is not invoked if only one exchange was completed, and therefore
the exchange does not need to be added to a repository, as its completed immediately.add in interface AggregationRepositorycamelContext - the current CamelContextkey - the correlation keyexchange - the aggregated exchangepublic Exchange get(CamelContext camelContext, String key)
AggregationRepositoryget in interface AggregationRepositorycamelContext - the current CamelContextkey - the correlation keypublic void remove(CamelContext camelContext, String key, Exchange exchange)
OptimisticLockingAggregationRepositoryremove in interface AggregationRepositoryremove in interface OptimisticLockingAggregationRepositorycamelContext - the current CamelContextkey - the correlation keyexchange - the exchange to removepublic void confirm(CamelContext camelContext, String exchangeId)
AggregationRepositoryExchange.
This method is always invoked.confirm in interface AggregationRepositorycamelContext - the current CamelContextexchangeId - exchange id to confirmpublic Set<String> getKeys()
AggregationRepositorygetKeys in interface AggregationRepositoryprotected void doStart()
throws Exception
ServiceSupportServiceSupport.doStop() for more details.doStart in class ServiceSupportExceptionServiceSupport.doStop()protected void doStop()
throws Exception
ServiceSupportServiceSupport.doStop() method when
the service is being stopped. This method will also be invoked
if the service is still in uninitialized state (eg has not
been started). The method is always called to allow the service
to do custom logic when the service is being stopped, such as when
CamelContext is shutting down.doStop in class ServiceSupportExceptionServiceSupport.doStart()Apache Camel