Search in sources :

Example 1 with UserTransactionImpl

use of org.apache.geode.internal.jta.UserTransactionImpl 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 2 with UserTransactionImpl

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

the class TransactionTimeOutDUnitTest method runTest4.

public static void runTest4() {
    boolean exceptionOccurred = true;
    try {
        Context ctx = cache.getJNDIContext();
        UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
        utx = new UserTransactionImpl();
        utx.setTransactionTimeout(2);
        utx.begin();
        Thread.sleep(4000);
        try {
            utx.commit();
        } catch (Exception e) {
            exceptionOccurred = false;
        }
        if (exceptionOccurred) {
            fail("TimeOut did not rollback the transaction");
        }
    } catch (Exception e) {
        fail("Exception in testExceptionOnCommitAfterTimeOut() due to ", e);
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) IOException(java.io.IOException)

Example 3 with UserTransactionImpl

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

the class TransactionTimeOutDUnitTest method runTest5.

public static void runTest5() {
    boolean exceptionOccurred = true;
    try {
        Context ctx = cache.getJNDIContext();
        UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
        utx = new UserTransactionImpl();
        utx.setTransactionTimeout(10);
        utx.begin();
        utx.setTransactionTimeout(8);
        utx.setTransactionTimeout(6);
        utx.setTransactionTimeout(2);
        Thread.sleep(6000);
        try {
            utx.commit();
        } catch (Exception e) {
            exceptionOccurred = false;
        }
        if (exceptionOccurred) {
            fail("TimeOut did not rollback the transaction");
        }
    } catch (Exception e) {
        fail("Exception in testExceptionOnCommitAfterTimeOut() due to ", e);
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) IOException(java.io.IOException)

Example 4 with UserTransactionImpl

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

the class JNDIInvoker method mapTransactions.

/**
   * Bind the transaction resources. Bind UserTransaction and TransactionManager.
   * <p>
   * If there is pre-existing JNDI tree in the system and TransactionManager / UserTransaction is
   * already bound, GemFire will make use of these resources, but if TransactionManager /
   * UserTransaction is not available, the GemFire TransactionManager / UserTransaction will be
   * bound to the JNDI tree.
   * </p>
   * 
   */
public static void mapTransactions(DistributedSystem distSystem) {
    try {
        TransactionUtils.setLogWriter(distSystem.getLogWriter().convertToLogWriterI18n());
        cleanup();
        if (IGNORE_JTA) {
            return;
        }
        ctx = new InitialContext();
        doTransactionLookup();
    } catch (NamingException ne) {
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (ne instanceof NoInitialContextException) {
            String exception = "JNDIInvoker::mapTransactions:: No application server context found, Starting GemFire JNDI Context Context ";
            if (writer.finerEnabled())
                writer.finer(exception);
            try {
                initializeGemFireContext();
                transactionManager = TransactionManagerImpl.getTransactionManager();
                ctx.rebind("java:/TransactionManager", transactionManager);
                if (writer.fineEnabled())
                    writer.fine("JNDIInvoker::mapTransactions::Bound TransactionManager to Context GemFire JNDI Tree");
                UserTransactionImpl utx = new UserTransactionImpl();
                ctx.rebind("java:/UserTransaction", utx);
                if (writer.fineEnabled())
                    writer.fine("JNDIInvoker::mapTransactions::Bound Transaction to Context GemFire JNDI Tree");
            } catch (NamingException ne1) {
                if (writer.infoEnabled())
                    writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKERMAPTRANSACTIONSNAMINGEXCEPTION_WHILE_BINDING_TRANSACTIONMANAGERUSERTRANSACTION_TO_GEMFIRE_JNDI_TREE);
            } catch (SystemException se1) {
                if (writer.infoEnabled())
                    writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKERMAPTRANSACTIONSSYSTEMEXCEPTION_WHILE_BINDING_USERTRANSACTION_TO_GEMFIRE_JNDI_TREE);
            }
        } else if (ne instanceof NameNotFoundException) {
            String exception = "JNDIInvoker::mapTransactions:: No TransactionManager associated to Application server context, trying to bind GemFire TransactionManager";
            if (writer.finerEnabled())
                writer.finer(exception);
            try {
                transactionManager = TransactionManagerImpl.getTransactionManager();
                ctx.rebind("java:/TransactionManager", transactionManager);
                if (writer.fineEnabled())
                    writer.fine("JNDIInvoker::mapTransactions::Bound TransactionManager to Application Server Context");
                UserTransactionImpl utx = new UserTransactionImpl();
                ctx.rebind("java:/UserTransaction", utx);
                if (writer.fineEnabled())
                    writer.fine("JNDIInvoker::mapTransactions::Bound UserTransaction to Application Server Context");
            } catch (NamingException ne1) {
                if (writer.infoEnabled())
                    writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKERMAPTRANSACTIONSNAMINGEXCEPTION_WHILE_BINDING_TRANSACTIONMANAGERUSERTRANSACTION_TO_APPLICATION_SERVER_JNDI_TREE);
            } catch (SystemException se1) {
                if (writer.infoEnabled())
                    writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKERMAPTRANSACTIONSSYSTEMEXCEPTION_WHILE_BINDING_TRANSACTIONMANAGERUSERTRANSACTION_TO_APPLICATION_SERVER_JNDI_TREE);
            }
        }
    }
}
Also used : SystemException(javax.transaction.SystemException) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n)

Example 5 with UserTransactionImpl

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

the class ContextImpl method lookup.

/**
   * Looks up object with binding name name in this context.
   * 
   * @param name name to look up
   * @return object reference bound to name name.
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is CompositeName that spans more than one naming system
   * @throws NameNotFoundException if name can not be found.
   * @throws NotContextException component of name is not bound to instance of ContextImpl, when
   *         name is not atomic name.
   * @throws NamingException if any other naming error occurs
   * 
   */
public Object lookup(Name name) throws NamingException {
    checkIsDestroyed();
    try {
        Name parsedName = getParsedName(name);
        String nameComponent = parsedName.get(0);
        Object res = ctxMaps.get(nameComponent);
        if (res instanceof UserTransactionImpl) {
            res = new UserTransactionImpl();
        }
        // if not found
        if (!ctxMaps.containsKey(nameComponent)) {
            throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(name));
        } else // if this is a compound name
        if (parsedName.size() > 1) {
            if (res instanceof ContextImpl) {
                res = ((ContextImpl) res).lookup(parsedName.getSuffix(1));
            } else {
                throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXTIMPL_BUT_FOUND_0.toLocalizedString(res));
            }
        }
        return res;
    } catch (NameNotFoundException e) {
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_LOOKING_UP_0, name, e);
        throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(new Object[] { name }));
    } catch (SystemException se) {
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (writer.severeEnabled())
            writer.info(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_CREATING_USERTRANSACTION_OBJECT, se);
        throw new NameNotFoundException(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_CREATING_USERTRANSACTION_OBJECT.toLocalizedString());
    }
}
Also used : NotContextException(javax.naming.NotContextException) SystemException(javax.transaction.SystemException) NameNotFoundException(javax.naming.NameNotFoundException) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Aggregations

UserTransactionImpl (org.apache.geode.internal.jta.UserTransactionImpl)6 UserTransaction (javax.transaction.UserTransaction)4 IOException (java.io.IOException)2 Context (javax.naming.Context)2 RollbackException (javax.transaction.RollbackException)2 SystemException (javax.transaction.SystemException)2 LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)2 TransactionManagerImpl (org.apache.geode.internal.jta.TransactionManagerImpl)2 CompositeName (javax.naming.CompositeName)1 Name (javax.naming.Name)1 NameNotFoundException (javax.naming.NameNotFoundException)1 NotContextException (javax.naming.NotContextException)1 Synchronization (javax.transaction.Synchronization)1 SyncImpl (org.apache.geode.internal.jta.SyncImpl)1 TransactionImpl (org.apache.geode.internal.jta.TransactionImpl)1