Search in sources :

Example 41 with EjbInvocation

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;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation)

Example 42 with EjbInvocation

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;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) SimpleMetadata(org.glassfish.ha.store.util.SimpleMetadata) EJBObject(javax.ejb.EJBObject) NotSerializableException(java.io.NotSerializableException) IllegalLoopbackException(javax.ejb.IllegalLoopbackException) ConcurrentAccessException(javax.ejb.ConcurrentAccessException) RemoveException(javax.ejb.RemoveException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 43 with EjbInvocation

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;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) NotSerializableException(java.io.NotSerializableException) EJBObject(javax.ejb.EJBObject) SimpleMetadata(org.glassfish.ha.store.util.SimpleMetadata) IllegalLoopbackException(javax.ejb.IllegalLoopbackException) ConcurrentAccessException(javax.ejb.ConcurrentAccessException) RemoveException(javax.ejb.RemoveException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 44 with EjbInvocation

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;
        }
    }
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) RemoveException(javax.ejb.RemoveException) EJBException(javax.ejb.EJBException) IllegalLoopbackException(javax.ejb.IllegalLoopbackException) ConcurrentAccessException(javax.ejb.ConcurrentAccessException) RemoveException(javax.ejb.RemoveException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Aggregations

EjbInvocation (com.sun.ejb.EjbInvocation)44 EJBException (javax.ejb.EJBException)22 RemoteException (java.rmi.RemoteException)18 CreateException (javax.ejb.CreateException)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)16 RemoveException (javax.ejb.RemoveException)16 SystemException (javax.transaction.SystemException)15 EJBObject (javax.ejb.EJBObject)11 IOException (java.io.IOException)9 NotSerializableException (java.io.NotSerializableException)9 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)9 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)9 IllegalLoopbackException (javax.ejb.IllegalLoopbackException)9 BackingStoreException (org.glassfish.ha.store.api.BackingStoreException)9 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)7 EJBLocalRemoteObject (com.sun.ejb.containers.EJBLocalRemoteObject)6 FinderException (javax.ejb.FinderException)6 NoSuchEntityException (javax.ejb.NoSuchEntityException)6 InvocationInfo (com.sun.ejb.InvocationInfo)4