Search in sources :

Example 6 with SimpleMetadata

use of org.glassfish.ha.store.util.SimpleMetadata 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 7 with SimpleMetadata

use of org.glassfish.ha.store.util.SimpleMetadata 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 8 with SimpleMetadata

use of org.glassfish.ha.store.util.SimpleMetadata in project Payara by payara.

the class ReplicationStore method doSave.

/**
 * Save the specified Session into this Store.  Any previously saved
 * information for the associated session identifier is replaced.
 *
 * @param session Session to be saved
 *
 * @exception IOException if an input/output error occurs
 */
public void doSave(Session session) throws IOException {
    if (!(session instanceof HASession)) {
        return;
    }
    byte[] sessionState = this.getByteArray(session, isReplicationCompressionEnabled());
    SimpleMetadata simpleMetadata = // version
    SimpleMetadataFactory.createSimpleMetadata(// version
    session.getVersion(), // lastaccesstime
    session.getLastAccessedTime(), // maxinactiveinterval
    session.getMaxInactiveInterval() * 1000L, // state
    sessionState);
    try {
        BackingStore<String, SimpleMetadata> backingStore = getSimpleMetadataBackingStore();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ReplicationStore>>save: backing store : " + backingStore);
        }
        // id
        backingStore.save(// id
        session.getIdInternal(), simpleMetadata, // TODO: Revist the last param
        !((HASession) session).isPersistent());
    } catch (BackingStoreException ex) {
        throw new IOException("Error during save: " + ex.getMessage(), ex);
    }
}
Also used : BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) SimpleMetadata(org.glassfish.ha.store.util.SimpleMetadata)

Example 9 with SimpleMetadata

use of org.glassfish.ha.store.util.SimpleMetadata in project Payara by payara.

the class ReplicationStore method loadFromBackingStore.

private Session loadFromBackingStore(String id, String version) throws IOException, ClassNotFoundException, BackingStoreException {
    SimpleMetadata metaData = getSimpleMetadataBackingStore().load(id, version);
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.finest("ReplicationStore>>loadFromBackingStore:id=" + id + ", metaData=" + metaData);
    }
    Session session = getSession(metaData);
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.finest("ReplicationStore->Session is " + session);
    }
    return session;
}
Also used : SimpleMetadata(org.glassfish.ha.store.util.SimpleMetadata) Session(org.apache.catalina.Session)

Aggregations

SimpleMetadata (org.glassfish.ha.store.util.SimpleMetadata)9 BackingStoreException (org.glassfish.ha.store.api.BackingStoreException)8 EjbInvocation (com.sun.ejb.EjbInvocation)2 IOException (java.io.IOException)2 NotSerializableException (java.io.NotSerializableException)2 Serializable (java.io.Serializable)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 RemoteException (java.rmi.RemoteException)2 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)2 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)2 CreateException (javax.ejb.CreateException)2 EJBException (javax.ejb.EJBException)2 EJBObject (javax.ejb.EJBObject)2 IllegalLoopbackException (javax.ejb.IllegalLoopbackException)2 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)2 RemoveException (javax.ejb.RemoveException)2 SystemException (javax.transaction.SystemException)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Session (org.apache.catalina.Session)1