Search in sources :

Example 11 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.

the class WorkCoordinator method postInvoke.

/**
 * Post-invoke operation. This does the following after the work is executed.
 * <pre>
 * 1. Releases the transaction with JTS.
 * 2. Generates work completed event.
 * 3. Clear the thread context.
 * </pre>
 */
public void postInvoke() {
    boolean txImported = (getExecutionContext(ec, work) != null && getExecutionContext(ec, work).getXid() != null);
    try {
        JavaEETransactionManager tm = getTransactionManager();
        if (txImported) {
            tm.release(getExecutionContext(ec, work).getXid());
        }
    } catch (WorkException ex) {
        setException(ex);
    } finally {
        try {
            if (!isTimedOut()) {
                if (probeProvider != null) {
                    probeProvider.workProcessingCompleted(raName);
                    probeProvider.workProcessed(raName);
                }
                // If exception is not null, the work has already been rejected.
                if (listener != null) {
                    listener.workCompleted(new WorkEvent(this, WorkEvent.WORK_COMPLETED, work, getException()));
                }
            }
            // Also release the TX from the record of TX Optimizer
            if (txImported) {
                getTransactionManager().clearThreadTx();
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, e.getMessage());
        } finally {
            // reset the securityContext once the work has completed
            com.sun.enterprise.security.SecurityContext.setUnauthenticatedContext();
        }
    }
    setState(COMPLETED);
    if (waitMode == WAIT_UNTIL_FINISH) {
        unLock();
    }
}
Also used : JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) ResourceException(javax.resource.ResourceException)

Example 12 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.

the class TransactionManagerHelper method recreate.

public void recreate(Xid xid, long timeout) {
    final JavaEETransactionManager tm = transactionManager;
    try {
        tm.recreate(xid, timeout);
    } catch (javax.resource.spi.work.WorkException ex) {
        throw new IllegalStateException(ex);
    }
    preInvokeTx(true);
}
Also used : JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager)

Example 13 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.

the class TransactionManagerHelper method release.

public void release(Xid xid) {
    final JavaEETransactionManager tm = transactionManager;
    postInvokeTx(false, true);
    try {
        tm.release(xid);
    } catch (javax.resource.spi.work.WorkException ex) {
        throw new IllegalStateException(ex);
    } finally {
        if (tm instanceof JavaEETransactionManagerSimplified) {
            ((JavaEETransactionManagerSimplified) tm).clearThreadTx();
        }
    }
}
Also used : JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager)

Example 14 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.

the class J2EEInstanceListener method getJavaEETransactionManager.

private JavaEETransactionManager getJavaEETransactionManager(ServiceLocator services) {
    JavaEETransactionManager tm = null;
    ServiceHandle<JavaEETransactionManager> inhabitant = services.getServiceHandle(JavaEETransactionManager.class);
    if (inhabitant != null && inhabitant.isActive()) {
        tm = inhabitant.getService();
    }
    return tm;
}
Also used : JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager)

Example 15 with JavaEETransactionManager

use of com.sun.enterprise.transaction.api.JavaEETransactionManager in project Payara by payara.

the class EjbThreadPoolExecutor method afterExecute.

@Override
protected void afterExecute(Runnable r, Throwable t) {
    super.afterExecute(r, t);
    try {
        JavaEETransactionManager tm = EjbContainerUtilImpl.getInstance().getTransactionManager();
        if (tm.getTransaction() != null) {
            int st = tm.getStatus();
            Logger logger = EjbContainerUtilImpl.getLogger();
            logger.warning("NON-NULL TX IN AFTER_EXECUTE. TX STATUS: " + st);
            if (st == Status.STATUS_ROLLEDBACK || st == Status.STATUS_COMMITTED || st == Status.STATUS_UNKNOWN) {
                tm.clearThreadTx();
            } else {
                tm.rollback();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // clear our Context Classloader
        Thread.currentThread().setContextClassLoader(null);
    }
}
Also used : JavaEETransactionManager(com.sun.enterprise.transaction.api.JavaEETransactionManager) Logger(java.util.logging.Logger)

Aggregations

JavaEETransactionManager (com.sun.enterprise.transaction.api.JavaEETransactionManager)15 PoolingException (com.sun.appserv.connectors.internal.api.PoolingException)5 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)4 InvocationException (org.glassfish.api.invocation.InvocationException)4 ResourceException (javax.resource.ResourceException)3 SystemException (javax.transaction.SystemException)3 Transaction (javax.transaction.Transaction)3 InvocationManager (org.glassfish.api.invocation.InvocationManager)3 ResourceHandle (com.sun.enterprise.resource.ResourceHandle)2 ResourceSpec (com.sun.enterprise.resource.ResourceSpec)1 PoolManager (com.sun.enterprise.resource.pool.PoolManager)1 JavaEETransactionManagerSimplified (com.sun.enterprise.transaction.JavaEETransactionManagerSimplified)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Logger (java.util.logging.Logger)1 ManagedConnection (javax.resource.spi.ManagedConnection)1