json.put("Disk Expiry Thread Interval Seconds", config.getDiskExpiryThreadIntervalSeconds()); json.put("Logging Enabled", config.getLogging()); json.put("Terracotta Configuration", config.getTerracottaConfiguration()); json.put("Cache Writer Configuration", config.getCacheWriterConfiguration()); json.put("Cache Loader Configurations", config.getCacheLoaderConfigurations());
setupHibernateTimeoutBehavior( config.getDefaultCacheConfiguration() .getTerracottaConfiguration() .getNonstopConfiguration() ); setupHibernateTimeoutBehavior( cacheConfig.getTerracottaConfiguration().getNonstopConfiguration() );
private boolean isImmediateNonStopTimeout() { if (cacheConfiguration.getTerracottaConfiguration() == null) { return false; } NonstopConfiguration nonstopConfig = cacheConfiguration.getTerracottaConfiguration().getNonstopConfiguration(); return nonstopConfig != null && nonstopConfig.isImmediateTimeout(); } }
private static void addTerracottaConfigurationElement(NodeElement element, CacheConfiguration cacheConfiguration) { TerracottaConfiguration terracottaConfiguration = cacheConfiguration.getTerracottaConfiguration(); if (terracottaConfiguration != null) { element.addChildElement(new TerracottaConfigurationElement(element, terracottaConfiguration)); } }
/** * {@inheritDoc} */ public int getRegionCacheOrphanEvictionPeriod(String region) { Cache cache = this.cacheManager.getCache(region); if (cache != null && cache.isTerracottaClustered()) { return cache.getCacheConfiguration().getTerracottaConfiguration().getOrphanEvictionPeriod(); } else { return -1; } }
/** * {@inheritDoc} */ public boolean isRegionCacheOrphanEvictionEnabled(String region) { Cache cache = this.cacheManager.getCache(region); if (cache != null && cache.isTerracottaClustered()) { return cache.getCacheConfiguration().getTerracottaConfiguration().getOrphanEviction(); } else { return false; } }
public synchronized CacheEventListener getOrCreateClusteredEventReplicator(Ehcache cache) { String fullyQualifiedCacheName = toolkitInstanceFactory.getFullyQualifiedCacheName(cache); CacheEventListener replicator = eventReplicators.get(fullyQualifiedCacheName); if (replicator == null) { NonstopConfiguration nonStopConfiguration = cache.getCacheConfiguration().getTerracottaConfiguration() .getNonstopConfiguration(); CacheEventListener clusteredEventReplicator = new ClusteredEventReplicator( cache, fullyQualifiedCacheName, toolkitInstanceFactory .getOrCreateCacheEventNotifier(cache), this); replicator = new NonStopEventReplicator(clusteredEventReplicator, toolkitInstanceFactory, nonStopConfiguration); eventReplicators.put(fullyQualifiedCacheName, replicator); } return replicator; }
private static void validateConfig(Ehcache ehcache) { CacheConfiguration cacheConfiguration = ehcache.getCacheConfiguration(); final TerracottaConfiguration terracottaConfiguration = cacheConfiguration.getTerracottaConfiguration(); List<ConfigError> errors = new ArrayList<ConfigError>(); if (terracottaConfiguration == null || !terracottaConfiguration.isClustered()) { throw new InvalidConfigurationException( "Cannot create clustered store for non-terracotta clustered caches"); } MemoryStoreEvictionPolicy policy = cacheConfiguration.getMemoryStoreEvictionPolicy(); if (policy == MemoryStoreEvictionPolicy.FIFO || policy == MemoryStoreEvictionPolicy.LFU) { errors.add(new ConfigError("Policy '" + policy + "' is not a supported memory store eviction policy.")); } if (cacheConfiguration.isOverflowToDisk()) { if (LOG.isWarnEnabled()) { LOG.warn("Persistence on disk on the local node is not supported with a Terracotta clustered ehcache store. Configure the Terracotta server array to be persistent instead."); } } boolean cachePinned = cacheConfiguration.getPinningConfiguration() != null && cacheConfiguration.getPinningConfiguration().getStore() == PinningConfiguration.Store.INCACHE; if (cachePinned && cacheConfiguration.getMaxEntriesInCache() != CacheConfiguration.DEFAULT_MAX_ENTRIES_IN_CACHE) { errors.add(new ConfigError("Cache pinning is not supported with maxEntriesInCache")); } if (errors.size() > 0) { throw new InvalidConfigurationException(errors); } }
protected void addNonStopConfigForCache(final CacheConfiguration ehcacheConfig, final String fullyQualifiedCacheName) { final TerracottaConfiguration terracottaConfiguration = ehcacheConfig.getTerracottaConfiguration(); ToolkitNonStopConfiguration nonstopConfiguration = new ToolkitNonStopConfiguration( terracottaConfiguration .getNonstopConfiguration()); toolkit.getFeature(ToolkitFeatureType.NONSTOP).getNonStopConfigurationRegistry() .registerForInstance(nonstopConfiguration, fullyQualifiedCacheName, ToolkitObjectType.CACHE); }
/** * Create a cache manager configuration from the supplied url, correcting it for Hibernate compatibility. * <p> * Currently correcting for Hibernate compatibility means simply switching any identity based value modes to serialization. */ static Configuration loadAndCorrectConfiguration(URL url) { Configuration config = ConfigurationFactory.parseConfiguration(url); if (config.getDefaultCacheConfiguration() != null && config.getDefaultCacheConfiguration().isTerracottaClustered()) { setupHibernateTimeoutBehavior(config.getDefaultCacheConfiguration().getTerracottaConfiguration().getNonstopConfiguration()); } for (CacheConfiguration cacheConfig : config.getCacheConfigurations().values()) { if (cacheConfig.isTerracottaClustered()) { setupHibernateTimeoutBehavior(cacheConfig.getTerracottaConfiguration().getNonstopConfiguration()); } } return config; }
private void checkClusteredConfig() { final Consistency consistency = getCacheConfiguration().getTerracottaConfiguration().getConsistency(); final boolean coherent = getCacheConfiguration().getTerracottaConfiguration().isCoherent(); 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."); } }
/** * Constructor accepting the cache to be decorated. * * @param underlyingCache a clustered cache configured with eventual consistency * * @throws IllegalArgumentException if the underlying cache is not clustered and has not * eventual consistency. */ public StronglyConsistentCacheAccessor(Ehcache underlyingCache) throws IllegalArgumentException { super(underlyingCache); TerracottaConfiguration terracottaConfiguration = underlyingCache.getCacheConfiguration().getTerracottaConfiguration(); if (terracottaConfiguration == null || terracottaConfiguration.getConsistency() != TerracottaConfiguration.Consistency.EVENTUAL) { throw new IllegalArgumentException("This decorator only accepts clustered cache with eventual consistency. " + underlyingCache.getName() + " is not such a cache."); } elementComparator = underlyingCache.getCacheConfiguration() .getElementValueComparatorConfiguration() .createElementComparatorInstance(underlyingCache.getCacheConfiguration(), underlyingCache.getCacheConfiguration().getClassLoader()); }
@Override public WriteBehind createWriteBehind(Ehcache cache) { final CacheWriterConfiguration config = cache.getCacheConfiguration().getCacheWriterConfiguration(); final AsyncConfig asyncConfig = new WriteBehindAsyncConfig(config.getMinWriteDelay() * 1000, config.getMaxWriteDelay() * 1000, config.getWriteBatching(), config.getWriteBatchSize(), cache.getCacheConfiguration() .getTerracottaConfiguration().isSynchronousWrites(), config.getRetryAttempts(), config.getRetryAttemptDelaySeconds() * 1000, config.getRateLimitPerSecond(), config.getWriteBehindMaxQueueSize()); final AsyncCoordinator asyncCoordinator = asyncCoordinatorFactory.getOrCreateAsyncCoordinator(cache, asyncConfig); return new AsyncWriteBehind(asyncCoordinator, config.getWriteBehindConcurrency()); }
final TerracottaConfiguration terracottaConfiguration = ehcacheConfig.getTerracottaConfiguration(); backend = toolkitInstanceFactory.getOrCreateToolkitCache(cache); configMap = toolkitInstanceFactory.getOrCreateClusteredStoreConfigMap(cache.getCacheManager().getName(),
public NonStopStoreWrapper(Callable<TerracottaStore> clusteredStoreCreator, ToolkitInstanceFactory toolkitInstanceFactory, Ehcache cache, TerracottaStoreInitializationService initializationService) { this.cache = cache; this.initializationService = initializationService; this.nonStop = toolkitInstanceFactory.getToolkit().getFeature(ToolkitFeatureType.NONSTOP); this.ehcacheNonStopConfiguration = cache.getCacheConfiguration().getTerracottaConfiguration() .getNonstopConfiguration(); this.toolkitNonStopConfiguration = new ToolkitNonStopExceptionOnTimeoutConfiguration(ehcacheNonStopConfiguration); this.bulkOpsToolkitNonStopConfiguration = new BulkOpsToolkitNonStopConfiguration(ehcacheNonStopConfiguration); Toolkit toolkit = toolkitInstanceFactory.getToolkit(); CacheLockProvider cacheLockProvider = createCacheLockProvider(toolkit, toolkitInstanceFactory); this.clusteredCacheInternalContext = new ClusteredCacheInternalContext(toolkit, cacheLockProvider); if (ehcacheNonStopConfiguration != null && ehcacheNonStopConfiguration.isEnabled()) { createStoreAsynchronously(toolkit, clusteredStoreCreator); } else { createStore(clusteredStoreCreator); } StatisticsManager.associate(this).withParent(cache); }
private AbstractTransactionStore makeTransactional(final Store store) { AbstractTransactionStore wrappedStore; if (configuration.isXaStrictTransactional()) { if (transactionManagerLookup.getTransactionManager() == null) { throw new CacheException("You've configured cache " + cacheManager.getName() + "." + configuration.getName() + " to be transactional, but no TransactionManager could be found!"); } // set xa enabled if (configuration.isTerracottaClustered()) { configuration.getTerracottaConfiguration().setCacheXA(true); } SoftLockManager softLockManager = cacheManager.createSoftLockManager(this); TransactionIDFactory transactionIDFactory = cacheManager.getOrCreateTransactionIDFactory(); wrappedStore = new XATransactionStore(transactionManagerLookup, softLockManager, transactionIDFactory, this, store, elementValueComparator); } else if (configuration.isXaTransactional()) { SoftLockManager softLockManager = cacheManager.createSoftLockManager(this); LocalTransactionStore localTransactionStore = new LocalTransactionStore(getCacheManager().getTransactionController(), getCacheManager().getOrCreateTransactionIDFactory(), softLockManager, this, store, elementValueComparator); wrappedStore = new JtaLocalTransactionStore(localTransactionStore, transactionManagerLookup, cacheManager.getTransactionController()); } else if (configuration.isLocalTransactional()) { SoftLockManager softLockManager = cacheManager.createSoftLockManager(this); wrappedStore = new LocalTransactionStore(getCacheManager().getTransactionController(), getCacheManager() .getOrCreateTransactionIDFactory(), softLockManager, this, store, elementValueComparator); } else { throw new IllegalStateException("Method should called only with a transactional configuration"); } return wrappedStore; }
configuration.getTerracottaConfiguration().setCacheXA(true);
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 NonstopConfiguration nonstopConfig = getCacheConfiguration().getTerracottaConfiguration().getNonstopConfiguration();
private static Configuration createClusteredCacheConfig(final CacheConfiguration ehcacheConfig, final String cacheManagerName) { ToolkitCacheConfigBuilder builder = new ToolkitCacheConfigBuilder(); final TerracottaConfiguration terracottaConfiguration = ehcacheConfig.getTerracottaConfiguration(); builder.maxTTISeconds((int) ehcacheConfig.getTimeToIdleSeconds()); builder.maxTTLSeconds((int) ehcacheConfig.getTimeToLiveSeconds());
private void validateTerracottaConfig(final Configuration configuration, final Collection<ConfigError> errors) { final TerracottaClientConfiguration clientConfiguration = configuration.getTerracottaConfiguration(); if (clientConfiguration != null && clientConfiguration.isRejoin() && !getTerracottaConfiguration().isNonstopEnabled()) { errors.add(new CacheConfigError("Terracotta clustered caches must be nonstop when rejoin is enabled.", getName())); } }