use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class EjbFutureTask method cancel.
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
if (!cancelCalled) {
cancelCalled = true;
// has visibility to the fact that the caller called Future.cancel().
if (mayInterruptIfRunning) {
EjbInvocation inv = ejbAsyncTask.getEjbInvocation();
inv.setWasCancelCalled(true);
}
}
// Just return false so the caller knows the task could not be cancelled.
return false;
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AsynchronousTask method getSFSBBeanState.
SimpleMetadata getSFSBBeanState(SessionContextImpl sc) {
// No need to synchronize
SimpleMetadata simpleMetadata = null;
try {
if ((containerState != CONTAINER_STARTED) && (containerState != CONTAINER_STOPPED)) {
_logger.log(Level.FINE, "getSFSBBeanState() returning because " + "containerState: " + containerState);
return null;
}
if (sc.getState() == BeanState.DESTROYED) {
return null;
}
Object ejb = sc.getEJB();
EjbInvocation ejbInv = createEjbInvocation(ejb, sc);
invocationManager.preInvoke(ejbInv);
boolean needToDoPostInvokeTx = false;
boolean destroyBean = false;
synchronized (sc) {
try {
needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, prePassivateInvInfo, CallbackType.PRE_PASSIVATE);
sc.setLastPersistedAt(System.currentTimeMillis());
long newCtxVersion = sc.incrementAndGetVersion();
byte[] serializedState = serializeContext(sc);
simpleMetadata = new SimpleMetadata(sc.getVersion(), System.currentTimeMillis(), removalGracePeriodInSeconds * 1000L, serializedState);
simpleMetadata.setVersion(newCtxVersion);
needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, postActivateInvInfo, CallbackType.POST_ACTIVATE);
// Do not set sc.setExistsInStore() here
} catch (java.io.NotSerializableException serEx) {
_logger.log(Level.WARNING, ERROR_DURING_CHECKPOINT_3PARAMs, new Object[] { ejbDescriptor.getName(), sc.getInstanceKey(), serEx });
_logger.log(Level.FINE, "sfsb checkpoint error. Key: " + sc.getInstanceKey(), serEx);
destroyBean = true;
} catch (Throwable ex) {
_logger.log(Level.WARNING, SFSB_CHECKPOINT_ERROR_NAME, new Object[] { ejbDescriptor.getName() });
_logger.log(Level.WARNING, SFSB_CHECKPOINT_ERROR_KEY, new Object[] { sc.getInstanceKey(), ex });
destroyBean = true;
} finally {
invocationManager.postInvoke(ejbInv);
completeLifecycleCallbackTxIfUsed(ejbInv, sc, needToDoPostInvokeTx);
if (destroyBean) {
try {
forceDestroyBean(sc);
} catch (Exception e) {
_logger.log(Level.FINE, "error destroying bean", e);
}
}
}
}
// synchronized
} catch (Throwable th) {
_logger.log(Level.WARNING, SFSB_CHECKPOINT_ERROR_NAME, new Object[] { ejbDescriptor.getName(), th });
}
return simpleMetadata;
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AsynchronousTask method checkpointEJB.
private boolean checkpointEJB(SessionContextImpl sc) {
boolean checkpointed = false;
try {
if ((containerState != CONTAINER_STARTED) && (containerState != CONTAINER_STOPPED)) {
_logger.log(Level.FINE, "passivateEJB() returning because " + "containerState: " + containerState);
return false;
}
if (sc.getState() == BeanState.DESTROYED) {
return false;
}
Object ejb = sc.getEJB();
long checkpointStartTime = -1;
if ((sfsbStoreMonitor != null) && sfsbStoreMonitor.isMonitoringOn()) {
checkpointStartTime = System.currentTimeMillis();
}
EjbInvocation ejbInv = createEjbInvocation(ejb, sc);
invocationManager.preInvoke(ejbInv);
boolean needToDoPostInvokeTx = false;
boolean destroyBean = false;
synchronized (sc) {
try {
// for this instance.
if (sc.getState() != BeanState.READY) {
return false;
}
// passivate the EJB
sc.setState(BeanState.PASSIVATED);
decrementMethodReadyStat();
needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, prePassivateInvInfo, CallbackType.PRE_PASSIVATE);
sc.setLastPersistedAt(System.currentTimeMillis());
byte[] serializedState = null;
try {
long newCtxVersion = sc.incrementAndGetVersion();
serializedState = serializeContext(sc);
SimpleMetadata beanState = new SimpleMetadata(sc.getVersion(), sc.getLastAccessTime(), removalGracePeriodInSeconds * 1000L, serializedState);
beanState.setVersion(newCtxVersion);
backingStore.save((Serializable) sc.getInstanceKey(), beanState, !sc.existsInStore());
// Now that we have successfully stored.....
sc.setLastPersistedAt(System.currentTimeMillis());
sc.setExistsInStore(true);
checkpointed = true;
} catch (EMNotSerializableException emNotSerEx) {
_logger.log(Level.WARNING, ERROR_DURING_CHECKPOINT_SESSION_ALIVE, emNotSerEx);
} catch (NotSerializableException notSerEx) {
throw notSerEx;
} catch (Exception ignorableEx) {
_logger.log(Level.WARNING, ERROR_DURING_CHECKPOINT, ignorableEx);
}
// TODO - add a flag to reactivate in the same tx
// Complete previous tx
completeLifecycleCallbackTxIfUsed(ejbInv, sc, needToDoPostInvokeTx);
needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, postActivateInvInfo, CallbackType.POST_ACTIVATE);
sc.setState(BeanState.READY);
incrementMethodReadyStat();
if (sfsbStoreMonitor != null) {
sfsbStoreMonitor.setCheckpointSize(serializedState.length);
sfsbStoreMonitor.incrementCheckpointCount(true);
}
} catch (Throwable ex) {
if (sfsbStoreMonitor != null) {
sfsbStoreMonitor.incrementCheckpointCount(false);
}
_logger.log(Level.WARNING, SFSB_CHECKPOINT_ERROR_NAME, new Object[] { ejbDescriptor.getName() });
_logger.log(Level.WARNING, SFSB_CHECKPOINT_ERROR_KEY, new Object[] { sc.getInstanceKey(), ex });
destroyBean = true;
} finally {
invocationManager.postInvoke(ejbInv);
completeLifecycleCallbackTxIfUsed(ejbInv, sc, needToDoPostInvokeTx);
if (destroyBean) {
try {
forceDestroyBean(sc);
} catch (Exception e) {
_logger.log(Level.FINE, "error destroying bean", e);
}
}
if (checkpointStartTime != -1) {
long timeSpent = System.currentTimeMillis() - checkpointStartTime;
if (sfsbStoreMonitor != null) {
sfsbStoreMonitor.setCheckpointTime(timeSpent);
}
}
}
}
// synchronized
} catch (Exception ex) {
_logger.log(Level.WARNING, PASSIVATION_ERROR_1PARAM, new Object[] { ejbDescriptor.getName(), ex });
}
return checkpointed;
}
use of com.sun.ejb.EjbInvocation in project Payara by payara.
the class AsynchronousTask method removeBean.
// Called from EJBObjectImpl.remove, EJBLocalObjectImpl.remove,
// EJBHomeImpl.remove(Handle).
protected void removeBean(EJBLocalRemoteObject ejbo, Method removeMethod, boolean local) throws RemoveException, EJBException {
EjbInvocation ejbInv = super.createEjbInvocation();
ejbInv.ejbObject = ejbo;
ejbInv.isLocal = local;
ejbInv.isRemote = !local;
ejbInv.method = removeMethod;
// Method must be a remove method defined on one of :
// javax.ejb.EJBHome, javax.ejb.EJBObject, javax.ejb.EJBLocalHome,
// javax.ejb.EJBLocalObject
Class declaringClass = removeMethod.getDeclaringClass();
ejbInv.isHome = ((declaringClass == javax.ejb.EJBHome.class) || (declaringClass == javax.ejb.EJBLocalHome.class));
try {
preInvoke(ejbInv);
removeBean(ejbInv);
} catch (Exception e) {
_logger.log(Level.FINE, "Exception while running pre-invoke : ejbName = [{0}]", e);
ejbInv.exception = e;
} finally {
/*TODO
if (AppVerification.doInstrument()) {
AppVerification.getInstrumentLogger().doInstrumentForEjb
(ejbDescriptor, removeMethod, i.exception);
}
*/
postInvoke(ejbInv);
}
if (ejbInv.exception != null) {
if (ejbInv.exception instanceof RemoveException) {
throw (RemoveException) ejbInv.exception;
} else if (ejbInv.exception instanceof RuntimeException) {
throw (RuntimeException) ejbInv.exception;
} else if (ejbInv.exception instanceof Exception) {
throw new EJBException((Exception) ejbInv.exception);
} else {
EJBException ejbEx = new EJBException();
ejbEx.initCause(ejbInv.exception);
throw ejbEx;
}
}
}
Aggregations