json.put("Cache Loader Configurations", config.getCacheLoaderConfigurations()); json.put("Frozen", config.isFrozen()); json.put("Transactional Mode", config.getTransactionalMode()); json.put("Statistics Enabled", config.getStatistics());
/** * Helper method to compute whether the cache is XA transactional or not * * @return true if transactionalMode="xa_strict" */ public boolean isXaStrictTransactional() { validateTransactionalSettings(); return getTransactionalMode().equals(TransactionalMode.XA_STRICT); }
/** * Helper method to compute whether the cache is local transactional or not * * @return true if transactionalMode="local" */ public boolean isLocalTransactional() { validateTransactionalSettings(); return getTransactionalMode().equals(TransactionalMode.LOCAL); }
/** * Helper method to compute whether the cache is local_jta transactional or not * * @return true if transactionalMode="xa" */ public boolean isXaTransactional() { validateTransactionalSettings(); return getTransactionalMode().equals(TransactionalMode.XA); }
/** * {@inheritDoc} */ @Override public boolean getTransactional() { return cache.getCacheConfiguration().getTransactionalMode().isTransactional(); }
/** * {@inheritDoc} */ public boolean getTransactional() { for (String cacheName : getCacheNames()) { Ehcache cache = cacheManager.getEhcache(cacheName); if (cache != null && cache.getCacheConfiguration().getTransactionalMode().isTransactional()) { return true; } } return false; }
/** * Check if a transaction has begun on the current thread if the cache is configured as * transactional, otherwise always return false. * @param cache the cache to check if a transaction started for * @return true if the cache is transactional and a transaction started, false otherwise * @throws CacheException if anything wrong happens */ public static boolean isTransactionStarted(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); return ctrl.getCurrentTransactionContext() != null; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); return ((Integer) tm.getClass().getMethod("getStatus").invoke(tm)) != XA_STATUS_NO_TRANSACTION; case OFF: default: return false; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error checking if transaction started: " + e); } }
/** * Begin a transaction on the current thread if the cache is configured as transactional, * otherwise this method does nothing. * * @param cache the cache to begin a transaction for * @throws CacheException if anything wrong happens */ public static void beginTransactionIfNeeded(Ehcache cache) throws CacheException { try { switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); ctrl.begin(); break; case XA: case XA_STRICT: Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("begin").invoke(tm); break; case OFF: default: break; } } catch (Exception e) { e.printStackTrace(); throw new CacheException("error beginning transaction:" + e); } }
private void validateTransactionalSettings() { boolean transactional = getTransactionalMode().isTransactional(); if (copyOnRead == null) { if (terracottaConfiguration != null && terracottaConfiguration.isCopyOnReadSet()) { copyOnRead = terracottaConfiguration.isCopyOnRead(); } else { copyOnRead = transactional; } } if (copyOnWrite == null) { copyOnWrite = transactional; } if (transactional) { if (!copyOnRead || !copyOnWrite) { throw new InvalidConfigurationException("A transactional cache has to be copyOnRead and copyOnWrite!"); } } }
switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController();
String url = null; try { if (cache.getCacheConfiguration().getTransactionalMode().isTransactional()) { rmiCachePeer = new TransactionalRMICachePeer(cache, hostName, port, remoteObjectPort, socketTimeoutMillis); } else {
/** * Should be called on init because this is one of the last things that should happen on CacheManager startup. */ protected void populateListOfRemoteCachePeers() throws RemoteException { String[] names = cacheManager.getCacheNames(); for (int i = 0; i < names.length; i++) { String name = names[i]; Ehcache cache = cacheManager.getEhcache(name); synchronized (cachePeers) { if (cachePeers.get(name) == null) { if (isDistributed(cache)) { RMICachePeer peer; if (cache.getCacheConfiguration().getTransactionalMode().isTransactional()) { peer = new TransactionalRMICachePeer(cache, hostName, port, remoteObjectPort, socketTimeoutMillis); } else { peer = new RMICachePeer(cache, hostName, port, remoteObjectPort, socketTimeoutMillis); } cachePeers.put(name, peer); } } } } }
.getTransactionalMode(); if (clusteredTransactionalMode != null && !clusteredTransactionalMode.equals(getCacheConfiguration().getTransactionalMode())) { throw new InvalidConfigurationException("Transactional mode cannot be changed on clustered caches. " + "Please reconfigure cache '" + getName() + "' with transactionalMode = " + clusteredTransactionalMode);
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."); } }
private Store handleTransactionalAndCopy(Store store, ClassLoader loader) { Store wrappedStore; if (configuration.getTransactionalMode().isTransactional()) { elementValueComparator = TxCopyingCacheStore.wrap( configuration.getElementValueComparatorConfiguration().createElementComparatorInstance(configuration, loader), configuration); wrappedStore = TxCopyingCacheStore.wrapTxStore(makeTransactional(store), configuration); } else { elementValueComparator = CopyingCacheStore.wrapIfCopy( configuration.getElementValueComparatorConfiguration().createElementComparatorInstance(configuration, loader), configuration); wrappedStore = CopyingCacheStore.wrapIfCopy(store, configuration); } return wrappedStore; }
/** * Factory method to wrap the MemoryStore into a BruteForceSource, accounting for transactional and copy * configuration * * @param memoryStore the underlying store acting as source * @param cacheConfiguration the cache configuration * @return a BruteForceSource connected to underlying MemoryStore and matching configuration */ protected static BruteForceSource createBruteForceSource(MemoryStore memoryStore, CacheConfiguration cacheConfiguration) { BruteForceSource source = new MemoryStoreBruteForceSource(memoryStore, cacheConfiguration.getSearchable()); CopyStrategyHandler copyStrategyHandler = new CopyStrategyHandler(cacheConfiguration.isCopyOnRead(), cacheConfiguration.isCopyOnWrite(), cacheConfiguration.getCopyStrategy(), cacheConfiguration.getClassLoader()); if (cacheConfiguration.getTransactionalMode().isTransactional()) { source = new TransactionalBruteForceSource(source, copyStrategyHandler); } else if (cacheConfiguration.isCopyOnRead() || cacheConfiguration.isCopyOnWrite()) { source = new CopyingBruteForceSource(source, copyStrategyHandler); } return source; }
CacheConfiguration.TransactionalMode transactionalModeTemp = (TransactionalMode) configMap.get(TRANSACTIONAL_MODE); if (transactionalModeTemp == null) { configMap.putIfAbsent(TRANSACTIONAL_MODE, ehcacheConfig.getTransactionalMode()); transactionalModeTemp = (TransactionalMode) configMap.get(TRANSACTIONAL_MODE);
private TerracottaStore makeClusteredTransactionalIfNeeded(final TerracottaStore store, final ElementValueComparator comparator, ClassLoader loader) { TerracottaStore wrappedStore; if (configuration.getTransactionalMode().isTransactional()) { if (configuration.isXaStrictTransactional()) { if (transactionManagerLookup.getTransactionManager() == null) {
/** * {@inheritDoc} */ public boolean getTransactional() { for (String cacheName : getCacheNames()) { Ehcache cache = cacheManager.getEhcache(cacheName); if (cache != null && cache.getCacheConfiguration().getTransactionalMode().isTransactional()) { return true; } } return false; }
element.addAttribute(new SimpleNodeAttribute("transactionalMode", cacheConfiguration.getTransactionalMode()).optional(true) .defaultValue(CacheConfiguration.DEFAULT_TRANSACTIONAL_MODE)); element.addAttribute(new SimpleNodeAttribute("memoryStoreEvictionPolicy", cacheConfiguration.getMemoryStoreEvictionPolicy()