private Transaction getCurrentTransaction() throws SystemException { Transaction transaction = transactionManagerLookup.getTransactionManager().getTransaction(); if (transaction == null) { throw new TransactionException("JTA transaction not started"); } return transaction; }
/** * Create a new JtaLocalTransactionStore instance * @param underlyingStore the underlying LocalTransactionStore * @param transactionManagerLookup the TransactionManagerLookup * @param transactionController the TransactionController */ public JtaLocalTransactionStore(LocalTransactionStore underlyingStore, TransactionManagerLookup transactionManagerLookup, TransactionController transactionController) { super(underlyingStore); this.transactionManagerLookup = transactionManagerLookup; this.transactionController = transactionController; this.transactionManager = transactionManagerLookup.getTransactionManager(); if (this.transactionManager == null) { throw new TransactionException("no JTA transaction manager could be located"); } this.cache = underlyingStore.getCache(); if (transactionManager.getClass().getName().contains("atomikos")) { System.setProperty(ALTERNATIVE_TERMINATION_MODE_SYS_PROPERTY_NAME, "true"); if (ATOMIKOS_WARNING_ISSUED.compareAndSet(false, true)) { LOG.warn("Atomikos transaction manager detected, make sure you configured com.atomikos.icatch.threaded_2pc=false"); } } }
/** * {@inheritDoc} */ public int getTerracottaClusteredSize() { try { Transaction transaction = transactionManagerLookup.getTransactionManager().getTransaction(); if (transaction == null) { return underlyingStore.getTerracottaClusteredSize(); } } catch (SystemException se) { throw new TransactionException("cannot get the current transaction", se); } LOG.debug("cache {} getTerracottaClusteredSize", cache.getName()); XATransactionContext context = getOrCreateTransactionContext(); int size = underlyingStore.getTerracottaClusteredSize(); return size + context.getSizeModifier(); }
/** * Constructor * @param transactionManagerLookup the transaction manager lookup implementation * @param softLockManager the soft lock manager * @param transactionIdFactory the transaction ID factory * @param cache the cache * @param store the underlying store */ public XATransactionStore(TransactionManagerLookup transactionManagerLookup, SoftLockManager softLockManager, TransactionIDFactory transactionIdFactory, Ehcache cache, Store store, ElementValueComparator comparator) { super(store); this.transactionManagerLookup = transactionManagerLookup; this.transactionIdFactory = transactionIdFactory; this.comparator = comparator; if (transactionManagerLookup.getTransactionManager() == null) { throw new TransactionException("no JTA transaction manager could be located, cannot bind twopc cache with JTA"); } this.softLockManager = softLockManager; this.cache = cache; // this xaresource is for initial registration and recovery this.recoveryResource = new EhcacheXAResourceImpl(cache, underlyingStore, transactionManagerLookup, softLockManager, transactionIdFactory, comparator, commitObserver, rollbackObserver, recoveryObserver); transactionManagerLookup.register(recoveryResource, 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); } }
Object tm = ((net.sf.ehcache.Cache) cache).getTransactionManagerLookup().getTransactionManager(); tm.getClass().getMethod("commit").invoke(tm); break;
/** * 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; }
/** * Constructor * @param explicitLockingContextThreadLocal */ public TransactionalExecutorServiceStore(final NonstopActiveDelegateHolder nonstopActiveDelegateHolder, final NonstopConfiguration nonstopConfiguration, final NonstopTimeoutBehaviorStoreResolver timeoutBehaviorResolver, CacheCluster cacheCluster, TransactionManagerLookup transactionManagerLookup, ExplicitLockingContextThreadLocal explicitLockingContextThreadLocal) { super(nonstopActiveDelegateHolder, nonstopConfiguration, timeoutBehaviorResolver, cacheCluster, explicitLockingContextThreadLocal); this.transactionManager = transactionManagerLookup.getTransactionManager(); }
private Transaction getCurrentTransaction() throws SystemException { Transaction transaction = transactionManagerLookup.getTransactionManager().getTransaction(); if (transaction == null) { throw new TransactionException("JTA transaction not started"); } return transaction; }
private Transaction getCurrentTransaction() throws SystemException { Transaction transaction = transactionManagerLookup.getTransactionManager().getTransaction(); if (transaction == null) { throw new TransactionException("JTA transaction not started"); } return transaction; }
private Transaction getCurrentTransaction() throws SystemException { Transaction transaction = transactionManagerLookup.getTransactionManager().getTransaction(); if (transaction == null) { throw new TransactionException("JTA transaction not started"); } return transaction; }
protected boolean hasTransaction() { TransactionManagerLookup transactionManagerLookup = cache.getTransactionManagerLookup(); if (transactionManagerLookup == null) { return false; } TransactionManager transactionManager = transactionManagerLookup.getTransactionManager(); if (transactionManager == null) { return false; } Transaction transaction; try { transaction = transactionManager.getTransaction(); } catch (SystemException e) { throw new RuntimeException(e); } return transaction != null; }
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; }
/** * Constructor * @param transactionManagerLookup the transaction manager lookup implementation * @param softLockManager the soft lock manager * @param transactionIdFactory the transaction ID factory * @param cache the cache * @param store the underlying store * @param copyStrategy the original copy strategy */ public XATransactionStore(TransactionManagerLookup transactionManagerLookup, SoftLockManager softLockManager, TransactionIDFactory transactionIdFactory, Ehcache cache, Store store, ReadWriteCopyStrategy<Element> copyStrategy) { super(store, copyStrategy); this.transactionManagerLookup = transactionManagerLookup; this.transactionIdFactory = transactionIdFactory; if (transactionManagerLookup.getTransactionManager() == null) { throw new TransactionException("no JTA transaction manager could be located, cannot bind twopc cache with JTA"); } this.softLockManager = softLockManager; this.cache = cache; }
if (transactionManagerLookup.getTransactionManager() == null) { throw new CacheException("You've configured cache " + cacheManager.getName() + "." + configuration.getName() + " to be transactional, but no TransactionManager could be found!");
/** * {@inheritDoc} */ public int getTerracottaClusteredSize() { try { Transaction transaction = transactionManagerLookup.getTransactionManager().getTransaction(); if (transaction == null) { return underlyingStore.getTerracottaClusteredSize(); } } catch (SystemException se) { throw new TransactionException("cannot get the current transaction", se); } LOG.debug("cache {} getTerracottaClusteredSize", cache.getName()); XATransactionContext context = getOrCreateTransactionContext(); int size = underlyingStore.getTerracottaClusteredSize(); return size + context.getSizeModifier(); }
/** * {@inheritDoc} */ public int getTerracottaClusteredSize() { try { Transaction transaction = transactionManagerLookup.getTransactionManager().getTransaction(); if (transaction == null) { return underlyingStore.getTerracottaClusteredSize(); } } catch (SystemException se) { throw new TransactionException("cannot get the current transaction", se); } LOG.debug("cache {} getTerracottaClusteredSize", cache.getName()); XATransactionContext context = getOrCreateTransactionContext(); int size = underlyingStore.getTerracottaClusteredSize(); return size + context.getSizeModifier(); }
/** * {@inheritDoc} */ public int getTerracottaClusteredSize() { try { Transaction transaction = transactionManagerLookup.getTransactionManager().getTransaction(); if (transaction == null) { return underlyingStore.getTerracottaClusteredSize(); } } catch (SystemException se) { throw new TransactionException("cannot get the current transaction", se); } LOG.debug("cache {} getTerracottaClusteredSize", cache.getName()); XATransactionContext context = getOrCreateTransactionContext(); int size = underlyingStore.getTerracottaClusteredSize(); return size + context.getSizeModifier(); }
/** * 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 */ public EhcacheXAResourceImpl(Ehcache cache, Store underlyingStore, TransactionManagerLookup txnManagerLookup, SoftLockManager softLockManager, TransactionIDFactory transactionIDFactory, ReadWriteCopyStrategy<Element> copyStrategy) { 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 = cache.getCacheConfiguration().getElementValueComparatorConfiguration() .createElementComparatorInstance(cache.getCacheConfiguration()); }