private Transaction getCurrentTransaction() throws SystemException { Transaction transaction = transactionManagerLookup.getTransactionManager().getTransaction(); if (transaction == null) { throw new TransactionException("JTA transaction not started"); } return transaction; }
/** * 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); }
.loadClass(lookupConfiguration.getFullyQualifiedClassPath()); this.transactionManagerLookup = transactionManagerLookupClass.newInstance(); this.transactionManagerLookup.setProperties(properties); } catch (Exception e) { LOG.error("could not instantiate transaction manager lookup class: {}", lookupConfiguration.getFullyQualifiedClassPath(), e);
public void afterCommitOrRollback(EhcacheXAResource xaResource) { transactionManagerLookup.unregister(xaResource, false); } }
private XATransactionContext getTransactionContext() { try { Transaction transaction = getCurrentTransaction(); EhcacheXAResourceImpl xaResource = (EhcacheXAResourceImpl) transactionToXAResourceMap.get(transaction); if (xaResource == null) { return null; } XATransactionContext transactionContext = xaResource.getCurrentTransactionContext(); if (transactionContext == null) { transactionManagerLookup.register(xaResource, false); LOG.debug("creating new XA context"); transactionContext = xaResource.createTransactionContext(); xaResource.addTwoPcExecutionListener(new UnregisterXAResource()); } else { transactionContext = xaResource.getCurrentTransactionContext(); } LOG.debug("using XA context {}", transactionContext); return transactionContext; } catch (SystemException e) { throw new TransactionException("cannot get the current transaction", e); } catch (RollbackException e) { throw new TransactionException("transaction rolled back", e); } }
transactionManagerLookup.init();
@Override public void dispose() { super.dispose(); transactionManagerLookup.unregister(recoveryResource, true); }
private XATransactionContext getOrCreateTransactionContext() { try { EhcacheXAResourceImpl xaResource = getOrCreateXAResource(); XATransactionContext transactionContext = xaResource.getCurrentTransactionContext(); if (transactionContext == null) { transactionManagerLookup.register(xaResource, false); LOG.debug("creating new XA context"); transactionContext = xaResource.createTransactionContext(); xaResource.addTwoPcExecutionListener(new UnregisterXAResource()); } else { transactionContext = xaResource.getCurrentTransactionContext(); } LOG.debug("using XA context {}", transactionContext); return transactionContext; } catch (SystemException e) { throw new TransactionException("cannot get the current transaction", e); } catch (RollbackException e) { throw new TransactionException("transaction rolled back", e); } }
transactionManagerLookup.init();
/** * 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"); } } }
/** * 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); }
public void commit(Xid xid, boolean onePhase) throws XAException { transactionController.commit(true); JtaLocalTransactionStore.BOUND_JTA_TRANSACTIONS.remove(); transactionManagerLookup.unregister(this, false); }
transactionManagerLookup.register(xaRes, false); tx.enlistResource(xaRes); } else {
.forName(lookupConfiguration.getFullyQualifiedClassPath()); this.transactionManagerLookup = transactionManagerLookupClass.newInstance(); this.transactionManagerLookup.setProperties(properties); } catch (Exception e) { LOG.error("could not instantiate transaction manager lookup class: {}", lookupConfiguration.getFullyQualifiedClassPath(), e);
transactionManagerLookup.init();
/** * {@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); }
public void rollback(Xid xid) throws XAException { transactionController.rollback(); JtaLocalTransactionStore.BOUND_JTA_TRANSACTIONS.remove(); transactionManagerLookup.unregister(this, false); }
private XATransactionContext getTransactionContext() { try { Transaction transaction = getCurrentTransaction(); EhcacheXAResourceImpl xaResource = (EhcacheXAResourceImpl) transactionToXAResourceMap.get(transaction); if (xaResource == null) { return null; } XATransactionContext transactionContext = xaResource.getCurrentTransactionContext(); if (transactionContext == null) { transactionManagerLookup.register(xaResource, false); LOG.debug("creating new XA context"); transactionContext = xaResource.createTransactionContext(); xaResource.addTwoPcExecutionListener(new UnregisterXAResource()); } else { transactionContext = xaResource.getCurrentTransactionContext(); } LOG.debug("using XA context {}", transactionContext); return transactionContext; } catch (SystemException e) { throw new TransactionException("cannot get the current transaction", e); } catch (RollbackException e) { throw new TransactionException("transaction rolled back", e); } }
.loadClass(lookupConfiguration.getFullyQualifiedClassPath()); this.transactionManagerLookup = transactionManagerLookupClass.newInstance(); this.transactionManagerLookup.setProperties(properties); } catch (Exception e) { LOG.error("could not instantiate transaction manager lookup class: {}", lookupConfiguration.getFullyQualifiedClassPath(), e);