use of javax.transaction.Synchronization in project Payara by payara.
the class ContainerSynchronization method beforeCompletion.
public void beforeCompletion() {
// first call beforeCompletion for each bean instance
for (int i = 0; i < beans.size(); i++) {
EJBContextImpl context = (EJBContextImpl) beans.get(i);
BaseContainer container = (BaseContainer) context.getContainer();
try {
if (container != null) {
boolean allowTxCompletion = true;
if (container.isUndeployed()) {
if (context instanceof SessionContextImpl) {
allowTxCompletion = ((SessionContextImpl) context).getInLifeCycleCallback();
} else {
allowTxCompletion = false;
_logger.log(Level.WARNING, "Marking Tx for rollback " + " because container for " + container + " is undeployed");
}
}
if (!allowTxCompletion) {
try {
tx.setRollbackOnly();
} catch (SystemException sysEx) {
_logger.log(Level.FINE, "Error while trying to " + "mark for rollback", sysEx);
}
} else {
container.beforeCompletion(context);
}
} else {
// Might be null if bean was removed. Just skip it.
_logger.log(Level.FINE, "context with empty container in " + " ContainerSynchronization.beforeCompletion");
}
} catch (RuntimeException ex) {
logAndRollbackTransaction(ex);
throw ex;
} catch (Exception ex) {
logAndRollbackTransaction(ex);
// no need to call remaining beforeCompletions
throw new EJBException("Error during beforeCompletion.", ex);
}
}
// now call beforeCompletion for all pmSyncs
for (int i = 0; i < pmSyncs.size(); i++) {
Synchronization sync = (Synchronization) pmSyncs.elementAt(i);
try {
sync.beforeCompletion();
} catch (RuntimeException ex) {
logAndRollbackTransaction(ex);
throw ex;
} catch (Exception ex) {
logAndRollbackTransaction(ex);
// no need to call remaining beforeCompletions
throw new EJBException("Error during beforeCompletion.", ex);
}
}
}
use of javax.transaction.Synchronization in project Payara by payara.
the class EJBTimerService method cancelTimerSynchronization.
private void cancelTimerSynchronization(EJBContextImpl context_, TimerPrimaryKey timerId, long containerId, String ownerId, boolean persistent) throws Exception {
// is owned by the current server instance.
if (context_ == null || timerOwnedByThisServer(ownerId)) {
// Cancel existing timer task. Save time at which task would
// have executed in case cancellation is rolled back. The
// nextTimeout can be null if the timer is currently being
// delivered.
Date nextTimeout = cancelTask(timerId);
ContainerSynchronization containerSynch = getContainerSynch(context_, timerId.getTimerId(), persistent);
if (containerSynch == null) {
// null ContainerSynchronization for persistent timer would've
// caused exception in #getContainerSynch(). For non-persistent
// timer remove it right away
expungeTimer(timerId);
ejbContainerUtil.getContainer(containerId).incrementRemovedTimedObject();
} else {
Synchronization timerSynch = containerSynch.getTimerSynchronization(timerId);
if (timerSynch != null) {
// This timer was created and cancelled within the
// same transaction. No tx synchronization actions
// are needed, since whether tx commits or rolls back,
// timer will not exist.
containerSynch.removeTimerSynchronization(timerId);
expungeTimer(timerId);
} else {
// Set tx synchronization action to handle timer cancellation.
timerSynch = new TimerSynch(timerId, STATE_CANCELLED, nextTimeout, ejbContainerUtil.getContainer(containerId), this);
containerSynch.addTimerSynchronization(timerId, timerSynch);
}
}
}
}
Aggregations