org.apache.camel.processor.aggregate
Class MemoryAggregationRepository

java.lang.Object
  extended by org.apache.camel.support.ServiceSupport
      extended by org.apache.camel.processor.aggregate.MemoryAggregationRepository
All Implemented Interfaces:
Service, ShutdownableService, AggregationRepository, OptimisticLockingAggregationRepository, StatefulService, SuspendableService

public class MemoryAggregationRepository
extends ServiceSupport
implements OptimisticLockingAggregationRepository

A memory based AggregationRepository which stores Exchanges in memory only. Supports both optimistic locking and non-optimistic locking modes. Defaults to non-optimistic locking mode.

Version:

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.camel.spi.OptimisticLockingAggregationRepository
OptimisticLockingAggregationRepository.OptimisticLockingException
 
Field Summary
 
Fields inherited from class org.apache.camel.support.ServiceSupport
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
 
Constructor Summary
MemoryAggregationRepository()
           
MemoryAggregationRepository(boolean optimisticLocking)
           
 
Method Summary
 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.
 
Methods inherited from class org.apache.camel.support.ServiceSupport
doResume, doShutdown, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, resume, shutdown, start, stop, suspend
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryAggregationRepository

public MemoryAggregationRepository()

MemoryAggregationRepository

public MemoryAggregationRepository(boolean optimisticLocking)
Method Detail

add

public Exchange add(CamelContext camelContext,
                    String key,
                    Exchange oldExchange,
                    Exchange newExchange)
Description copied from interface: OptimisticLockingAggregationRepository
Add the given 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.

Specified by:
add in interface OptimisticLockingAggregationRepository
Parameters:
camelContext - the current CamelContext
key - the correlation key
oldExchange - the old exchange that is expected to exist when replacing with the new exchange
newExchange - the new aggregated exchange, to replace old exchange
Returns:
the old exchange if any existed

add

public Exchange add(CamelContext camelContext,
                    String key,
                    Exchange exchange)
Description copied from interface: AggregationRepository
Add the given Exchange 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.

Specified by:
add in interface AggregationRepository
Parameters:
camelContext - the current CamelContext
key - the correlation key
exchange - the aggregated exchange
Returns:
the old exchange if any existed

get

public Exchange get(CamelContext camelContext,
                    String key)
Description copied from interface: AggregationRepository
Gets the given exchange with the correlation key

This method is always invoked for any incoming exchange in the aggregator.

Specified by:
get in interface AggregationRepository
Parameters:
camelContext - the current CamelContext
key - the correlation key
Returns:
the exchange, or null if no exchange was previously added

remove

public void remove(CamelContext camelContext,
                   String key,
                   Exchange exchange)
Description copied from interface: OptimisticLockingAggregationRepository
Removes the given Exchange when both the supplied key and Exchange are present in the repository. If the supplied Exchange does not match the Exchange actually stored against the key this method should throw an OptimisticLockingException to indicate that the value of the correlation key has changed from the expected value.

Specified by:
remove in interface AggregationRepository
Specified by:
remove in interface OptimisticLockingAggregationRepository
Parameters:
camelContext - the current CamelContext
key - the correlation key
exchange - the exchange to remove

confirm

public void confirm(CamelContext camelContext,
                    String exchangeId)
Description copied from interface: AggregationRepository
Confirms the completion of the Exchange.

This method is always invoked.

Specified by:
confirm in interface AggregationRepository
Parameters:
camelContext - the current CamelContext
exchangeId - exchange id to confirm

getKeys

public Set<String> getKeys()
Description copied from interface: AggregationRepository
Gets the keys currently in the repository.

Specified by:
getKeys in interface AggregationRepository
Returns:
the keys

doStart

protected void doStart()
                throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: See ServiceSupport.doStop() for more details.

Specified by:
doStart in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStop()

doStop

protected void doStop()
               throws Exception
Description copied from class: ServiceSupport
Implementations override this method to support customized start/stop.

Important: Camel will invoke this ServiceSupport.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.

Specified by:
doStop in class ServiceSupport
Throws:
Exception
See Also:
ServiceSupport.doStart()


Apache Camel