/** * {@inheritDoc} */ public long getTransactionCommittedCount() { return this.cacheManager.getTransactionController().getTransactionCommittedCount(); }
/** * {@inheritDoc} */ public long getTransactionTimedOutCount() { return this.cacheManager.getTransactionController().getTransactionTimedOutCount(); }
/** * {@inheritDoc} */ public long getTransactionTimedOutCount() { return cacheManager.getTransactionController().getTransactionTimedOutCount(); }
/** * {@inheritDoc} */ public long getTransactionRolledBackCount() { return this.cacheManager.getTransactionController().getTransactionRolledBackCount(); }
/** * {@inheritDoc} */ public long getTransactionCommittedCount() { return cacheManager.getTransactionController().getTransactionCommittedCount(); }
/** * {@inheritDoc} */ public long getTransactionRolledBackCount() { return cacheManager.getTransactionController().getTransactionRolledBackCount(); }
/** * {@inheritDoc} */ public boolean setTransactionTimeout(int timeout) throws XAException { if (timeout < 0) { throw new EhcacheXAException("timeout must be >= 0, was: " + timeout, XAException.XAER_INVAL); } if (timeout == 0) { this.transactionTimeout = cache.getCacheManager().getTransactionController().getDefaultTransactionTimeout(); } else { this.transactionTimeout = timeout; } return true; }
/** * 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); } }
switch (cache.getCacheConfiguration().getTransactionalMode()) { case LOCAL: TransactionController ctrl = cache.getCacheManager().getTransactionController(); ctrl.commit(); break;
timeout = MILLISECONDS.convert(xaResourceTimeout, TimeUnit.SECONDS); } else { int defaultTransactionTimeout = cache.getCacheManager().getTransactionController().getDefaultTransactionTimeout(); timeout = MILLISECONDS.convert(defaultTransactionTimeout, TimeUnit.SECONDS);
/** * Constructor * @param cache the cache * @param underlyingStore the underlying store * @param txnManagerLookup the transaction manager lookup * @param softLockManager the soft lock manager * @param transactionIDFactory the transaction ID factory * @param comparator the element value comparator */ public EhcacheXAResourceImpl(Ehcache cache, Store underlyingStore, TransactionManagerLookup txnManagerLookup, SoftLockManager softLockManager, TransactionIDFactory transactionIDFactory, ElementValueComparator comparator, OperationObserver<XaCommitOutcome> commitObserver, OperationObserver<XaRollbackOutcome> rollbackObserver, OperationObserver<XaRecoveryOutcome> recoveryObserver) { this.cache = cache; this.underlyingStore = underlyingStore; this.transactionIDFactory = transactionIDFactory; this.txnManager = txnManagerLookup.getTransactionManager(); this.softLockManager = softLockManager; this.processor = new XARequestProcessor(this); this.transactionTimeout = cache.getCacheManager().getTransactionController().getDefaultTransactionTimeout(); this.comparator = comparator; this.commitObserver = commitObserver; this.rollbackObserver = rollbackObserver; this.recoveryObserver = recoveryObserver; }
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; }
} else if (configuration.isXaTransactional()) { SoftLockManager softLockManager = cacheManager.createSoftLockManager(this); LocalTransactionStore localTransactionStore = new LocalTransactionStore(getCacheManager().getTransactionController(), getCacheManager().getOrCreateTransactionIDFactory(), softLockManager, this, store, comparator); 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, comparator); } else {
/** * {@inheritDoc} */ public long getTransactionCommittedCount() { return this.cacheManager.getTransactionController().getTransactionCommittedCount(); }
/** * {@inheritDoc} */ public long getTransactionTimedOutCount() { return this.cacheManager.getTransactionController().getTransactionTimedOutCount(); }
/** * {@inheritDoc} */ public long getTransactionCommittedCount() { return cacheManager.getTransactionController().getTransactionCommittedCount(); }
/** * {@inheritDoc} */ public long getTransactionRolledBackCount() { return cacheManager.getTransactionController().getTransactionRolledBackCount(); }
/** * {@inheritDoc} */ public long getTransactionTimedOutCount() { return this.cacheManager.getTransactionController().getTransactionTimedOutCount(); }
/** * {@inheritDoc} */ public long getTransactionRolledBackCount() { return this.cacheManager.getTransactionController().getTransactionRolledBackCount(); }