}
private static volatile int containerIndex = 1;
public static EmbeddedCacheManager createCacheContainer(boolean local, String passivationDir, boolean totalReplication, boolean purgeCacheLoader) throws Exception {
CacheMode mode = local ? CacheMode.LOCAL : (totalReplication ? CacheMode.REPL_SYNC : CacheMode.DIST_SYNC);
GlobalConfigurationBuilder globalBuilder = new GlobalConfigurationBuilder();
String name = "container" + containerIndex++;
globalBuilder.transport()
.transport(local ? null : new JGroupsTransport())
.addProperty(JGroupsTransport.CHANNEL_LOOKUP, ChannelLookup.class.getName())
.distributedSyncTimeout(60000)
.clusterName("test")
.globalJmxStatistics().enable().cacheManagerName(name).allowDuplicateDomains(true)
;
ConfigurationBuilder builder = new ConfigurationBuilder().read(CacheAdd.getDefaultConfiguration(mode));
builder.transaction()
.syncCommitPhase(true)
.syncRollbackPhase(true)
.transactionMode(TransactionMode.TRANSACTIONAL)
.transactionManagerLookup(new TransactionManagerProvider(BatchModeTransactionManager.getInstance()))
.invocationBatching().enable()
.jmxStatistics().enable()
;
if (passivationDir != null) {
builder.loaders()
.passivation(true)
.preload(false)
// .preload(!purgeCacheLoader)
.addFileCacheStore()
.location(passivationDir)
.fsyncMode(FsyncMode.PER_WRITE)
.fetchPersistentState(mode.isReplicated())
.purgeOnStartup(purgeCacheLoader)
.purgeSynchronously(true)
;
}