Class HazelcastAggregationRepository
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.processor.aggregate.hazelcast.HazelcastAggregationRepository
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.AggregationRepository,org.apache.camel.spi.OptimisticLockingAggregationRepository,org.apache.camel.spi.RecoverableAggregationRepository,org.apache.camel.StatefulService,org.apache.camel.SuspendableService
- Direct Known Subclasses:
ReplicatedHazelcastAggregationRepository
@Metadata(label="bean",
description="Aggregation repository that uses Hazelcast Cache to store exchanges.",
annotations="interfaceName=org.apache.camel.spi.AggregationRepository")
@Configurer(metadataOnly=true)
public class HazelcastAggregationRepository
extends org.apache.camel.support.service.ServiceSupport
implements org.apache.camel.spi.RecoverableAggregationRepository, org.apache.camel.spi.OptimisticLockingAggregationRepository
A Hazelcast-based AggregationRepository implementing
RecoverableAggregationRepository and
OptimisticLockingAggregationRepository. Defaults to thread-safe (non-optimistic) locking and recoverable
strategy. Hazelcast settings are given to an end-user and can be controlled with repositoryName and
persistentRespositoryName, both are IMap <String, Exchange>. However
HazelcastAggregationRepository can run it's own Hazelcast instance, but obviously no benefits of Hazelcast clustering
are gained this way. If the HazelcastAggregationRepository uses it's own local HazelcastInstance it
will DESTROY this instance on doStop(). You should control HazelcastInstance lifecycle yourself
whenever you instantiate HazelcastAggregationRepository passing a reference to the instance.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.camel.spi.OptimisticLockingAggregationRepository
org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected com.hazelcast.map.IMap<String, org.apache.camel.support.DefaultExchangeHolder> protected static final Stringprotected Stringprotected com.hazelcast.core.HazelcastInstanceprotected Stringprotected intprotected booleanprotected com.hazelcast.map.IMap<String, org.apache.camel.support.DefaultExchangeHolder> protected Stringprotected longprotected booleanprotected booleanFields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING -
Constructor Summary
ConstructorsConstructorDescriptionHazelcastAggregationRepository(String repositoryName) Creates newHazelcastAggregationRepositorythat defaults to non-optimistic locking with recoverable behavior and a local Hazelcast instance.HazelcastAggregationRepository(String repositoryName, boolean optimistic) Creates newHazelcastAggregationRepositorywith recoverable behavior and a local Hazelcast instance.HazelcastAggregationRepository(String repositoryName, boolean optimistic, com.hazelcast.core.HazelcastInstance hzInstance) Creates newHazelcastAggregationRepositorywith recoverable behavior.HazelcastAggregationRepository(String repositoryName, com.hazelcast.core.HazelcastInstance hzInstanse) Creates newHazelcastAggregationRepositorythat defaults to non-optimistic locking with recoverable behavior.HazelcastAggregationRepository(String repositoryName, String persistentRepositoryName) Creates newHazelcastAggregationRepositorythat defaults to non-optimistic locking with recoverable behavior and a local Hazelcast instance.HazelcastAggregationRepository(String repositoryName, String persistentRepositoryName, boolean optimistic) Creates newHazelcastAggregationRepositorywith recoverable behavior and a local Hazelcast instance.HazelcastAggregationRepository(String repositoryName, String persistentRepositoryName, boolean optimistic, com.hazelcast.core.HazelcastInstance hzInstance) Creates newHazelcastAggregationRepositorywith recoverable behavior.HazelcastAggregationRepository(String repositoryName, String persistentRepositoryName, com.hazelcast.core.HazelcastInstance hzInstanse) Creates newHazelcastAggregationRepositorythat defaults to non-optimistic locking with recoverable behavior. -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.camel.Exchangeorg.apache.camel.Exchangeadd(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange) voidbooleancontainsKey(Object key) Checks if the key in question is in the repository.protected voiddoStart()protected voiddoStop()org.apache.camel.Exchangecom.hazelcast.core.HazelcastInstancegetKeys()intlongbooleanbooleanorg.apache.camel.ExchangevoidThis method performs transactional operation on removing theexchangefrom the operational storage and moving it into the persistent one if theHazelcastAggregationRepositoryruns in recoverable mode andoptimisticis false.scan(org.apache.camel.CamelContext camelContext) voidsetAllowSerializedHeaders(boolean allowSerializedHeaders) voidsetDeadLetterUri(String deadLetterUri) voidsetHazelcastInstance(com.hazelcast.core.HazelcastInstance hazelcastInstance) voidsetMaximumRedeliveries(int maximumRedeliveries) voidsetRecoveryInterval(long interval) voidsetRecoveryInterval(long interval, TimeUnit timeUnit) voidsetUseRecovery(boolean useRecovery) protected org.apache.camel.ExchangeunmarshallExchange(org.apache.camel.CamelContext camelContext, org.apache.camel.support.DefaultExchangeHolder holder) Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.spi.RecoverableAggregationRepository
confirmWithResult, getRecoveryIntervalInMillisMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Field Details
-
COMPLETED_SUFFIX
- See Also:
-
useLocalHzInstance
protected boolean useLocalHzInstance -
cache
-
persistedCache
protected com.hazelcast.map.IMap<String,org.apache.camel.support.DefaultExchangeHolder> persistedCache -
mapName
-
hazelcastInstance
@Metadata(description="To use an existing Hazelcast instance instead of local") protected com.hazelcast.core.HazelcastInstance hazelcastInstance -
persistenceMapName
@Metadata(label="advanced", description="Name of cache to use for completed exchanges") protected String persistenceMapName -
optimistic
@Metadata(description="Whether to use optimistic locking") protected boolean optimistic -
useRecovery
@Metadata(description="Whether or not recovery is enabled", defaultValue="true") protected boolean useRecovery -
recoveryInterval
@Metadata(description="Sets the interval between recovery scans", defaultValue="5000") protected long recoveryInterval -
deadLetterUri
@Metadata(description="Sets an optional dead letter channel which exhausted recovered Exchange should be send to.") protected String deadLetterUri -
maximumRedeliveries
@Metadata(description="Sets an optional limit of the number of redelivery attempt of recovered Exchange should be attempted, before its exhausted. When this limit is hit, then the Exchange is moved to the dead letter channel.", defaultValue="3") protected int maximumRedeliveries -
allowSerializedHeaders
@Metadata(label="advanced", description="Whether headers on the Exchange that are Java objects and Serializable should be included and saved to the repository") protected boolean allowSerializedHeaders
-
-
Constructor Details
-
HazelcastAggregationRepository
public HazelcastAggregationRepository() -
HazelcastAggregationRepository
Creates newHazelcastAggregationRepositorythat defaults to non-optimistic locking with recoverable behavior and a local Hazelcast instance. Recoverable repository name defaults torepositoryName+ "-compeleted".- Parameters:
repositoryName-IMaprepository name;
-
HazelcastAggregationRepository
Creates newHazelcastAggregationRepositorythat defaults to non-optimistic locking with recoverable behavior and a local Hazelcast instance.- Parameters:
repositoryName-IMaprepository name;persistentRepositoryName-IMaprecoverable repository name;
-
HazelcastAggregationRepository
Creates newHazelcastAggregationRepositorywith recoverable behavior and a local Hazelcast instance. Recoverable repository name defaults torepositoryName+ "-compeleted".- Parameters:
repositoryName-IMaprepository name;optimistic- whether to use optimistic locking manner.
-
HazelcastAggregationRepository
public HazelcastAggregationRepository(String repositoryName, String persistentRepositoryName, boolean optimistic) Creates newHazelcastAggregationRepositorywith recoverable behavior and a local Hazelcast instance.- Parameters:
repositoryName-IMaprepository name;persistentRepositoryName-IMaprecoverable repository name;optimistic- whether to use optimistic locking manner.
-
HazelcastAggregationRepository
public HazelcastAggregationRepository(String repositoryName, com.hazelcast.core.HazelcastInstance hzInstanse) Creates newHazelcastAggregationRepositorythat defaults to non-optimistic locking with recoverable behavior. Recoverable repository name defaults torepositoryName+ "-compeleted".- Parameters:
repositoryName-IMaprepository name;hzInstanse- externally configuredHazelcastInstance.
-
HazelcastAggregationRepository
public HazelcastAggregationRepository(String repositoryName, String persistentRepositoryName, com.hazelcast.core.HazelcastInstance hzInstanse) Creates newHazelcastAggregationRepositorythat defaults to non-optimistic locking with recoverable behavior.- Parameters:
repositoryName-IMaprepository name;persistentRepositoryName-IMaprecoverable repository name;hzInstanse- externally configuredHazelcastInstance.
-
HazelcastAggregationRepository
public HazelcastAggregationRepository(String repositoryName, boolean optimistic, com.hazelcast.core.HazelcastInstance hzInstance) Creates newHazelcastAggregationRepositorywith recoverable behavior. Recoverable repository name defaults torepositoryName+ "-compeleted".- Parameters:
repositoryName-IMaprepository name;optimistic- whether to use optimistic locking manner;hzInstance- externally configuredHazelcastInstance.
-
HazelcastAggregationRepository
public HazelcastAggregationRepository(String repositoryName, String persistentRepositoryName, boolean optimistic, com.hazelcast.core.HazelcastInstance hzInstance) Creates newHazelcastAggregationRepositorywith recoverable behavior.- Parameters:
repositoryName-IMaprepository name;persistentRepositoryName-IMaprecoverable repository name;optimistic- whether to use optimistic locking manner;hzInstance- externally configuredHazelcastInstance.
-
-
Method Details
-
add
public org.apache.camel.Exchange add(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange) throws org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException - Specified by:
addin interfaceorg.apache.camel.spi.OptimisticLockingAggregationRepository- Throws:
org.apache.camel.spi.OptimisticLockingAggregationRepository.OptimisticLockingException
-
add
public org.apache.camel.Exchange add(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange exchange) - Specified by:
addin interfaceorg.apache.camel.spi.AggregationRepository
-
scan
- Specified by:
scanin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
recover
public org.apache.camel.Exchange recover(org.apache.camel.CamelContext camelContext, String exchangeId) - Specified by:
recoverin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setRecoveryInterval
- Specified by:
setRecoveryIntervalin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setRecoveryInterval
public void setRecoveryInterval(long interval) - Specified by:
setRecoveryIntervalin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getRecoveryInterval
public long getRecoveryInterval()- Specified by:
getRecoveryIntervalin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setUseRecovery
public void setUseRecovery(boolean useRecovery) - Specified by:
setUseRecoveryin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
isUseRecovery
public boolean isUseRecovery()- Specified by:
isUseRecoveryin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setDeadLetterUri
- Specified by:
setDeadLetterUriin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getDeadLetterUri
- Specified by:
getDeadLetterUriin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
setMaximumRedeliveries
public void setMaximumRedeliveries(int maximumRedeliveries) - Specified by:
setMaximumRedeliveriesin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
getMaximumRedeliveries
public int getMaximumRedeliveries()- Specified by:
getMaximumRedeliveriesin interfaceorg.apache.camel.spi.RecoverableAggregationRepository
-
get
- Specified by:
getin interfaceorg.apache.camel.spi.AggregationRepository
-
containsKey
Checks if the key in question is in the repository.- Parameters:
key- Object - key in question
-
isAllowSerializedHeaders
public boolean isAllowSerializedHeaders() -
setAllowSerializedHeaders
public void setAllowSerializedHeaders(boolean allowSerializedHeaders) -
getHazelcastInstance
public com.hazelcast.core.HazelcastInstance getHazelcastInstance() -
setHazelcastInstance
public void setHazelcastInstance(com.hazelcast.core.HazelcastInstance hazelcastInstance) -
remove
public void remove(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange exchange) This method performs transactional operation on removing theexchangefrom the operational storage and moving it into the persistent one if theHazelcastAggregationRepositoryruns in recoverable mode andoptimisticis false. It will act at your own risk otherwise.- Specified by:
removein interfaceorg.apache.camel.spi.AggregationRepository- Specified by:
removein interfaceorg.apache.camel.spi.OptimisticLockingAggregationRepository- Parameters:
camelContext- the current CamelContextkey- the correlation keyexchange- the exchange to remove
-
confirm
- Specified by:
confirmin interfaceorg.apache.camel.spi.AggregationRepository
-
getKeys
- Specified by:
getKeysin interfaceorg.apache.camel.spi.AggregationRepository
-
getPersistentRepositoryName
- Returns:
- Persistent repository
IMapname;
-
doStart
- Overrides:
doStartin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doStop
- Overrides:
doStopin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
unmarshallExchange
protected org.apache.camel.Exchange unmarshallExchange(org.apache.camel.CamelContext camelContext, org.apache.camel.support.DefaultExchangeHolder holder)
-