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();
}
}
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);
}
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();
}
}
}
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;
}
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);
}
}
Aggregations