// 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())
.replQueueClass(config.clustering().async().replQueue().getClass())
.replQueueInterval(config.clustering().async().replQueueInterval())
.replQueueMaxElements(config.clustering().async().replQueueMaxElements())
.useReplQueue(config.clustering().async().useReplQueue());
}
if (config.clustering().hash().consistentHash() != null) {
legacy.clustering()
.hash()
.consistentHashClass(config.clustering().hash().consistentHash().getClass());
}
if (config.clustering().hash().activated) {
if (config.clustering().hash().hash() != null) {
legacy.clustering()
.hash()
.hashFunctionClass(config.clustering().hash().hash().getClass());
}
legacy.clustering()
.hash()
.numOwners(config.clustering().hash().numOwners())
.numVirtualNodes(config.clustering().hash().numVirtualNodes())
.rehashEnabled(config.clustering().hash().rehashEnabled())
.rehashRpcTimeout(config.clustering().hash().rehashRpcTimeout())
.rehashWait(config.clustering().hash().rehashWait())
.groups()
.enabled(config.clustering().hash().groups().enabled())
.groupers(config.clustering().hash().groups().groupers());
}
if (config.clustering().l1().activated && config.clustering().l1().enabled()) {
legacy.clustering()
.l1()
.invalidationThreshold(config.clustering().l1().invalidationThreshold())
.lifespan(config.clustering().l1().lifespan())
.onRehash(config.clustering().l1().onRehash());
} else {
legacy.clustering()
.l1()
.disable()
.onRehash(false);
}
legacy.clustering()
.stateRetrieval()
.fetchInMemoryState(config.clustering().stateTransfer().fetchInMemoryState())
.timeout(config.clustering().stateTransfer().timeout())
.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();
if (config.jmxStatistics().enabled())
legacy.jmxStatistics();
// TODO lazy deserialization?
legacy.loaders()
.passivation(config.loaders().passivation())
.preload(config.loaders().preload())
.shared(config.loaders().shared());
for (AbstractLoaderConfiguration loader : config.loaders().cacheLoaders()) {
CacheLoaderConfig clc = null;
if (loader instanceof LoaderConfiguration) {
CacheLoader cacheLoader = ((LoaderConfiguration) loader).cacheLoader();
if (cacheLoader.getClass().isAnnotationPresent(CacheLoaderMetadata.class)) {
clc = Util.getInstance(cacheLoader.getClass().getAnnotation(CacheLoaderMetadata.class).configurationClass());
} else {
AbstractCacheStoreConfig acsc = new AbstractCacheStoreConfig();
acsc.setCacheLoaderClassName(((LoaderConfiguration) loader).cacheLoader().getClass().getName());
clc = acsc;
}
} else if (loader instanceof FileCacheStoreConfiguration) {
FileCacheStoreConfig fcsc = new FileCacheStoreConfig();
clc = fcsc;
FileCacheStoreConfiguration store = (FileCacheStoreConfiguration) loader;
if (store.location() != null) {
fcsc.location(store.location());
}
if (store.fsyncMode() != null) {
fcsc.fsyncMode(FileCacheStoreConfig.FsyncMode.valueOf(store.fsyncMode().name()));
}
fcsc.fsyncInterval(store.fsyncInterval());
fcsc.streamBufferSize(store.streamBufferSize());
}
if (clc instanceof CacheStoreConfig) {
CacheStoreConfig csc = (CacheStoreConfig) clc;
csc.fetchPersistentState(loader.fetchPersistentState());
csc.ignoreModifications(loader.ignoreModifications());
csc.purgeOnStartup(loader.purgeOnStartup());
csc.setPurgeSynchronously(loader.purgeSynchronously());
csc.getAsyncStoreConfig().setEnabled(loader.async().enabled());
csc.getAsyncStoreConfig().flushLockTimeout(loader.async().flushLockTimeout());
csc.getAsyncStoreConfig().modificationQueueSize(loader.async().modificationQueueSize());
csc.getAsyncStoreConfig().shutdownTimeout(loader.async().shutdownTimeout());
csc.getAsyncStoreConfig().threadPoolSize(loader.async().threadPoolSize());
csc.getSingletonStoreConfig().enabled(loader.singletonStore().enabled());
csc.getSingletonStoreConfig().pushStateTimeout(loader.singletonStore().pushStateTimeout());
csc.getSingletonStoreConfig().pushStateWhenCoordinator(loader.singletonStore().pushStateWhenCoordinator());
}
if (clc instanceof AbstractCacheStoreConfig) {
AbstractCacheStoreConfig acsc = (AbstractCacheStoreConfig) clc;
Properties p = loader.properties();
acsc.setProperties(p);
if (p != null) XmlConfigHelper.setValues(clc, p, false, true);
if (loader instanceof LoaderConfiguration)
acsc.purgerThreads(((LoaderConfiguration) loader).purgerThreads());
}
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();
}