// Handle the case that null is passed in
if (config == null)
return null;
FluentConfiguration legacy = new Configuration().fluent();
legacy.clustering()
.mode(CacheMode.valueOf(config.clustering().cacheMode().name()));
if (!config.clustering().cacheMode().isSynchronous()) {
legacy.clustering()
.async()
.asyncMarshalling(config.clustering().async().asyncMarshalling())
.replQueueInterval(config.clustering().async().replQueueInterval())
.replQueueMaxElements(config.clustering().async().replQueueMaxElements())
.useReplQueue(config.clustering().async().useReplQueue());
ReplicationQueue replQueue = config.clustering().async().replQueue();
if (replQueue != null) {
legacy.clustering().async().replQueueClass(replQueue.getClass());
}
}
if (config.clustering().hash().hash() != null) {
legacy.clustering()
.hash()
.hashFunctionClass(config.clustering().hash().hash().getClass());
}
legacy.clustering()
.hash()
.numOwners(config.clustering().hash().numOwners())
.groups()
.enabled(config.clustering().hash().groups().enabled())
.groupers(config.clustering().hash().groups().groupers());
if (config.clustering().cacheMode().isDistributed()) {
legacy.clustering()
.hash()
.rehashEnabled(config.clustering().stateTransfer().fetchInMemoryState())
.rehashRpcTimeout(config.clustering().stateTransfer().timeout())
.rehashWait(config.clustering().stateTransfer().timeout());
} else if (config.clustering().cacheMode().isClustered()) { // REPL or DIST
legacy.clustering()
.stateRetrieval()
.fetchInMemoryState(config.clustering().stateTransfer().fetchInMemoryState())
.timeout(config.clustering().stateTransfer().timeout());
}
if (config.clustering().l1().enabled()) {
legacy.clustering()
.l1()
.invalidationThreshold(config.clustering().l1().invalidationThreshold())
.lifespan(config.clustering().l1().lifespan())
.onRehash(config.clustering().l1().onRehash())
.cleanupTaskFrequency(config.clustering().l1().cleanupTaskFrequency());
} else {
legacy.clustering()
.l1()
.disable()
.onRehash(config.clustering().l1().onRehash());
}
// We have only defined the chunkSize in the legacy stateRetrieval config, but we are using it in distributed mode as well
legacy.clustering()
.stateRetrieval()
.chunkSize(config.clustering().stateTransfer().chunkSize());
if (config.clustering().cacheMode().isSynchronous()) {
legacy.clustering()
.sync()
.replTimeout(config.clustering().sync().replTimeout());
}
for (InterceptorConfiguration interceptor : config.customInterceptors().interceptors()) {
CustomInterceptorPosition position = legacy.customInterceptors()
.add(interceptor.interceptor());
if (interceptor.after() != null)
position.after(interceptor.after());
if (interceptor.index() > -1)
position.atIndex(interceptor.index());
if (interceptor.before() != null)
position.before(interceptor.before());
if (interceptor.first())
position.first();
if (interceptor.last())
position.last();
}
legacy.dataContainer()
.dataContainer(config.dataContainer().dataContainer())
.withProperties(config.dataContainer().properties());
if (config.deadlockDetection().enabled()) {
legacy.deadlockDetection()
.spinDuration(config.deadlockDetection().spinDuration());
} else {
legacy.deadlockDetection()
.disable();
}
legacy.eviction()
.maxEntries(config.eviction().maxEntries())
.strategy(config.eviction().strategy())
.threadPolicy(config.eviction().threadPolicy());
legacy.expiration()
.lifespan(config.expiration().lifespan())
.maxIdle(config.expiration().maxIdle())
.reaperEnabled(config.expiration().reaperEnabled())
.wakeUpInterval(config.expiration().wakeUpInterval());
if (config.indexing().enabled()) {
IndexingConfig indexing = legacy.indexing();
indexing.indexLocalOnly(config.indexing().indexLocalOnly());
indexing.withProperties(config.indexing().properties());
}
else
legacy.indexing()
.disable();
if (config.invocationBatching().enabled())
legacy.invocationBatching();
else
legacy.invocationBatching().disable();
if (config.jmxStatistics().enabled())
legacy.jmxStatistics();
// TODO lazy deserialization?
legacy.loaders()
.passivation(config.loaders().passivation())
.preload(config.loaders().preload())
.shared(config.loaders().shared());
for (CacheLoaderConfiguration loader : config.loaders().cacheLoaders()) {
CacheLoaderConfig clc = adapt(loader);
legacy.loaders().addCacheLoader(clc);
}
legacy.locking()
.concurrencyLevel(config.locking().concurrencyLevel())
.isolationLevel(config.locking().isolationLevel())
.lockAcquisitionTimeout(config.locking().lockAcquisitionTimeout())
.useLockStriping(config.locking().useLockStriping())
.writeSkewCheck(config.locking().writeSkewCheck());
if (config.storeAsBinary().enabled())
legacy.storeAsBinary()
.storeKeysAsBinary(config.storeAsBinary().storeKeysAsBinary())
.storeValuesAsBinary(config.storeAsBinary().storeValuesAsBinary());
else
legacy.storeAsBinary()
.disable();
legacy.transaction()
.autoCommit(config.transaction().autoCommit())
.cacheStopTimeout((int) config.transaction().cacheStopTimeout())
.eagerLockSingleNode(config.transaction().eagerLockingSingleNode())
.lockingMode(config.transaction().lockingMode())
.syncCommitPhase(config.transaction().syncCommitPhase())
.syncRollbackPhase(config.transaction().syncRollbackPhase())
.transactionManagerLookup(config.transaction().transactionManagerLookup())
.transactionMode(config.transaction().transactionMode())
.transactionSynchronizationRegistryLookup(config.transaction().transactionSynchronizationRegistryLookup())
.useEagerLocking(config.transaction().useEagerLocking())
.useSynchronization(config.transaction().useSynchronization())
.use1PcForAutoCommitTransactions(config.transaction().use1PcForAutoCommitTransactions());
if (config.transaction().recovery().enabled()) {
legacy.transaction().recovery().recoveryInfoCacheName(config.transaction().recovery().recoveryInfoCacheName());
}
legacy.unsafe().unreliableReturnValues(config.unsafe().unreliableReturnValues());
if (config.versioning().enabled()) {
legacy.versioning()
.enable()
.versioningScheme(config.versioning().scheme());
}
return legacy.build();
}