&& configuration.isTerracottaClustered()
&& configuration.getTerracottaConfiguration().getValueMode() != TerracottaConfiguration.ValueMode.SERIALIZATION) {
throw new CacheException("To be transactional, a Terracotta clustered cache needs to be in Serialization value mode");
}
final Store store;
if (isTerracottaClustered()) {
final Consistency consistency = getCacheConfiguration().getTerracottaConfiguration().getConsistency();
final boolean coherent = getCacheConfiguration().getTerracottaConfiguration().isCoherent();
if (getCacheConfiguration().isOverflowToOffHeap()) {
throw new InvalidConfigurationException(
"Terracotta clustered caches with local overflow to offheap are not supported yet."
+ " You can fix this by disabling overflow to offheap for clustered caches.");
}
if (getCacheConfiguration().getTerracottaConfiguration().isSynchronousWrites() && consistency == Consistency.EVENTUAL) {
throw new InvalidConfigurationException(
"Terracotta clustered caches with eventual consistency and synchronous writes are not supported yet."
+ " You can fix this by either making the cache in 'strong' consistency mode "
+ "(<terracotta consistency=\"strong\"/>) or turning off synchronous writes.");
}
if (getCacheConfiguration().getTransactionalMode().isTransactional() && consistency == Consistency.EVENTUAL) {
throw new InvalidConfigurationException("Consistency should be " + Consistency.STRONG
+ " when cache is configured with transactions enabled. "
+ "You can fix this by either making the cache in 'strong' consistency mode "
+ "(<terracotta consistency=\"strong\"/>) or turning off transactions.");
}
if (getCacheConfiguration().getTransactionalMode().isTransactional()
&& !getCacheConfiguration().getTransactionalMode().equals(CacheConfiguration.TransactionalMode.XA_STRICT)
&& getCacheConfiguration().getTerracottaConfiguration().isNonstopEnabled()) {
LOG.warn("Cache: " + configuration.getName() + " configured both NonStop and transactional non xa_strict."
+ " NonStop features won't work for this cache!");
}
if ((coherent && consistency == Consistency.EVENTUAL) || (!coherent && consistency == Consistency.STRONG)) {
throw new InvalidConfigurationException("Coherent and consistency attribute values are conflicting. "
+ "Please remove the coherent attribute as its deprecated.");
}
int maxConcurrency = Integer.getInteger(EHCACHE_CLUSTERREDSTORE_MAX_CONCURRENCY_PROP,
DEFAULT_EHCACHE_CLUSTERREDSTORE_MAX_CONCURRENCY);
if (getCacheConfiguration().getTerracottaConfiguration().getConcurrency() > maxConcurrency) {
throw new InvalidConfigurationException("Maximum supported concurrency for Terracotta clustered caches is "
+ maxConcurrency + ". Please reconfigure cache '" + getName() + "' with concurrency value <= " + maxConcurrency
+ " or use system property '" + EHCACHE_CLUSTERREDSTORE_MAX_CONCURRENCY_PROP + "' to override the default");
}
if (getCacheConfiguration().getMaxElementsOnDisk() == 0) {
LOG.warn("Performance may degrade and server disks could run out of space!\nThe distributed cache {} does not have " +
"maxElementsOnDisk set. Failing to set maxElementsOnDisk could mean no eviction of its elements from the " +
"Terracotta Server Array disk store. To avoid this, set maxElementsOnDisk to a non-zero value.", getName());
}
if (!getCacheConfiguration().getTerracottaConfiguration().isStorageStrategySet()) {
getCacheConfiguration().getTerracottaConfiguration().storageStrategy(
TerracottaClient.getTerracottaDefaultStrategyForCurrentRuntime(getCacheConfiguration()));
}
Store tempStore = cacheManager.createTerracottaStore(this);
if (!(tempStore instanceof TerracottaStore)) {
throw new CacheException(
"CacheManager should create instances of TerracottaStore for Terracotta Clustered caches instead of - "
+ (tempStore == null ? "null" : tempStore.getClass().getName()));
}
TerracottaStore terracottaStore = (TerracottaStore) makeXaStrictTransactionalIfNeeded(tempStore, copyStrategy);
NonstopConfiguration nonstopConfig = getCacheConfiguration().getTerracottaConfiguration().getNonstopConfiguration();
// freeze the config whether nonstop is enabled or not
if (nonstopConfig != null) {
nonstopConfig.freezeConfig();
}
if (getCacheConfiguration().getTerracottaConfiguration().isNonstopEnabled()) {
nonstopActiveDelegateHolder.terracottaStoreInitialized(terracottaStore);
store = nonstopActiveDelegateHolder.getNonstopStore();
} else {
store = terracottaStore;
}
} else if (getCacheConfiguration().isOverflowToOffHeap()) {
try {
Class<Store> storeClass = ClassLoaderUtil.loadClass(OFF_HEAP_STORE_CLASSNAME);
try {
store = makeXaStrictTransactionalIfNeeded((Store) storeClass.getMethod("create", Ehcache.class, String.class)
.invoke(null, this, diskStorePath), copyStrategy);
} catch (NoSuchMethodException e) {
throw new CacheException("Cache: " + configuration.getName() + " cannot find static factory"
+ " method create(Ehcache, String)" + " in store class " + OFF_HEAP_STORE_CLASSNAME, e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof CacheException) {
throw (CacheException) cause;
} else {
throw new CacheException("Cache: " + configuration.getName() + " cannot instantiate store "
+ OFF_HEAP_STORE_CLASSNAME, cause);
}
} catch (IllegalAccessException e) {
throw new CacheException("Cache: " + configuration.getName() + " cannot instantiate store "
+ OFF_HEAP_STORE_CLASSNAME, e);
}
} catch (ClassNotFoundException e) {
throw new CacheException("Cache " + configuration.getName()
+ " cannot be configured because the off-heap store class could not be found. "
+ "You must use an enterprise version of Ehcache to successfully enable overflowToOffHeap.");
}
} else {
if (useClassicLru && configuration.getMemoryStoreEvictionPolicy().equals(MemoryStoreEvictionPolicy.LRU)) {
Store disk = createDiskStore();
store = makeXaStrictTransactionalIfNeeded(new LegacyStoreWrapper(
new LruMemoryStore(this, disk), disk, registeredEventListeners, configuration), copyStrategy);
} else {
if (configuration.isDiskPersistent()) {
store = makeXaStrictTransactionalIfNeeded(DiskPersistentStore.create(this, diskStorePath), copyStrategy);