Search in sources :

Example 1 with TransactionManagerImpl

use of org.apache.geode.internal.jta.TransactionManagerImpl in project geode by apache.

the class FacetsJCAConnectionManagerImpl method connectionErrorOccurred.

/**
   * CallBack for Connection Error.
   * 
   * @param event ConnectionEvent
   */
public void connectionErrorOccurred(ConnectionEvent event) {
    if (isActive) {
        // If its an XAConnection
        ManagedConnection conn = (ManagedConnection) event.getSource();
        // XAResource xar = (XAResource) xaResourcesMap.get(conn);
        ((List) xalistThreadLocal.get()).remove(conn);
        TransactionManagerImpl transManager = TransactionManagerImpl.getTransactionManager();
        try {
            Transaction txn = transManager.getTransaction();
            if (txn == null) {
                mannPoolCache.returnPooledConnectionToPool(conn);
            } else {
            // do nothing.
            }
        } catch (Exception se) {
            se.printStackTrace();
        }
        try {
            mannPoolCache.expirePooledConnection(conn);
        // mannPoolCache.destroyPooledConnection(conn);
        } catch (Exception ex) {
            String exception = "FacetsJCAConnectionManagerImpl::connectionErrorOccurred: Exception occurred due to " + ex.getMessage();
            if (logger.isDebugEnabled()) {
                logger.debug(exception, ex);
            }
        }
    }
}
Also used : Transaction(javax.transaction.Transaction) TransactionManagerImpl(org.apache.geode.internal.jta.TransactionManagerImpl) ManagedConnection(javax.resource.spi.ManagedConnection) ArrayList(java.util.ArrayList) List(java.util.List) ResourceException(javax.resource.ResourceException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 2 with TransactionManagerImpl

use of org.apache.geode.internal.jta.TransactionManagerImpl in project geode by apache.

the class ClientServerTransactionDUnitTest method doJTATx2.

private void doJTATx2(String regionName, CountDownLatch latch1, CountDownLatch latch2) {
    try {
        TransactionManagerImpl tm = TransactionManagerImpl.getTransactionManager();
        UserTransaction utx = new UserTransactionImpl();
        Region r = getClientRegion(regionName);
        utx.begin();
        r.put(key1, "value3");
        TransactionImpl txn = (TransactionImpl) tm.getTransaction();
        Synchronization sync = new SyncImpl();
        txn.registerSynchronization(sync);
        txn.notifyBeforeCompletionForTest();
        latch1.countDown();
        latch2.await();
        utx.rollback();
    } catch (Exception e) {
        latch1.countDown();
        Assert.fail("Unexpected exception while doing JTA Transaction2 ", e);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) SyncImpl(org.apache.geode.internal.jta.SyncImpl) TransactionManagerImpl(org.apache.geode.internal.jta.TransactionManagerImpl) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) TransactionImpl(org.apache.geode.internal.jta.TransactionImpl) Synchronization(javax.transaction.Synchronization) RollbackException(javax.transaction.RollbackException)

Example 3 with TransactionManagerImpl

use of org.apache.geode.internal.jta.TransactionManagerImpl in project geode by apache.

the class JCAConnectionManagerImpl method connectionErrorOccurred.

/**
   * CallBack for Connection Error.
   * 
   * @param event ConnectionEvent
   */
public void connectionErrorOccurred(ConnectionEvent event) {
    if (isActive) {
        // If its an XAConnection
        ManagedConnection conn = (ManagedConnection) event.getSource();
        XAResource xar = (XAResource) xaResourcesMap.get(conn);
        xaResourcesMap.remove(conn);
        TransactionManagerImpl transManager = TransactionManagerImpl.getTransactionManager();
        try {
            Transaction txn = transManager.getTransaction();
            if (txn != null && xar != null)
                txn.delistResource(xar, XAResource.TMSUCCESS);
        } catch (SystemException se) {
            se.printStackTrace();
        }
        try {
            mannPoolCache.expirePooledConnection(conn);
        // mannPoolCache.destroyPooledConnection(conn);
        } catch (Exception ex) {
            String exception = "JCAConnectionManagerImpl::connectionErrorOccurred: Exception occurred due to " + ex;
            if (logger.isDebugEnabled()) {
                logger.debug(exception, ex);
            }
        }
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) TransactionManagerImpl(org.apache.geode.internal.jta.TransactionManagerImpl) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 4 with TransactionManagerImpl

use of org.apache.geode.internal.jta.TransactionManagerImpl in project geode by apache.

the class FacetsJCAConnectionManagerImpl method connectionClosed.

/**
   * Callback for Connection Closed.
   * 
   * @param event ConnectionEvent Object.
   */
public void connectionClosed(ConnectionEvent event) {
    if (isActive) {
        ManagedConnection conn = (ManagedConnection) event.getSource();
        TransactionManagerImpl transManager = TransactionManagerImpl.getTransactionManager();
        try {
            Transaction txn = transManager.getTransaction();
            if (txn == null) {
                mannPoolCache.returnPooledConnectionToPool(conn);
            }
        } catch (Exception se) {
            String exception = "FacetsJCAConnectionManagerImpl::connectionClosed: Exception occurred due to " + se.getMessage();
            if (logger.isDebugEnabled()) {
                logger.debug(exception, se);
            }
        }
    }
}
Also used : Transaction(javax.transaction.Transaction) TransactionManagerImpl(org.apache.geode.internal.jta.TransactionManagerImpl) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 5 with TransactionManagerImpl

use of org.apache.geode.internal.jta.TransactionManagerImpl in project geode by apache.

the class ClientServerTransactionDUnitTest method doJTATx1.

private void doJTATx1(String regionName, CountDownLatch latch1, CountDownLatch latch2) {
    TransactionManagerImpl tm = TransactionManagerImpl.getTransactionManager();
    Region r = getClientRegion(regionName);
    try {
        UserTransaction utx = new UserTransactionImpl();
        utx.begin();
        latch1.await();
        r.put(key1, "value2");
        utx.commit();
        fail("Do not get expected RollbackException");
    } catch (Exception e) {
        if (e instanceof RollbackException) {
        // expected exception.
        } else {
            Assert.fail("Unexpected exception while doing JTA Transaction1 ", e);
        }
    } finally {
        latch2.countDown();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) TransactionManagerImpl(org.apache.geode.internal.jta.TransactionManagerImpl) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) RollbackException(javax.transaction.RollbackException) RollbackException(javax.transaction.RollbackException)

Aggregations

RollbackException (javax.transaction.RollbackException)5 TransactionManagerImpl (org.apache.geode.internal.jta.TransactionManagerImpl)5 ResourceException (javax.resource.ResourceException)3 ManagedConnection (javax.resource.spi.ManagedConnection)3 SystemException (javax.transaction.SystemException)3 Transaction (javax.transaction.Transaction)3 UserTransaction (javax.transaction.UserTransaction)2 UserTransactionImpl (org.apache.geode.internal.jta.UserTransactionImpl)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Synchronization (javax.transaction.Synchronization)1 XAResource (javax.transaction.xa.XAResource)1 SyncImpl (org.apache.geode.internal.jta.SyncImpl)1 TransactionImpl (org.apache.geode.internal.jta.TransactionImpl)1