Search in sources :

Example 1 with SimpleMetadata

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

the class SFSBTxCheckpointCoordinator method doTxCheckpoint.

void doTxCheckpoint() {
    SessionContextImpl[] contexts = (SessionContextImpl[]) ctxList.toArray(new SessionContextImpl[ctxList.size()]);
    int size = contexts.length;
    ArrayList<StoreAndBeanState> states = new ArrayList<StoreAndBeanState>(size);
    for (int i = 0; i < size; i++) {
        SessionContextImpl ctx = contexts[i];
        StatefulSessionContainer container = (StatefulSessionContainer) ctx.getContainer();
        SimpleMetadata beanState = container.getSFSBBeanState(ctx);
        if (beanState != null) {
            states.add(new StoreAndBeanState((Serializable) ctx.getInstanceKey(), container.getBackingStore(), beanState, !ctx.existsInStore()));
        }
    }
    if (states.size() > 0) {
        StoreAndBeanState[] beanStates = states.toArray(new StoreAndBeanState[states.size()]);
        try {
            for (StoreAndBeanState st : states) {
                st.store.save(st.key, st.state, st.isNew);
            }
        } catch (BackingStoreException sfsbEx) {
            _logger.log(Level.WARNING, "Exception during checkpointSave", sfsbEx);
        } catch (Throwable th) {
            _logger.log(Level.WARNING, "Exception during checkpointSave", th);
        }
    }
    for (int i = 0; i < size; i++) {
        SessionContextImpl ctx = contexts[i];
        StatefulSessionContainer container = (StatefulSessionContainer) ctx.getContainer();
        container.txCheckpointCompleted(ctx);
    }
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) SimpleMetadata(org.glassfish.ha.store.util.SimpleMetadata)

Example 2 with SimpleMetadata

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

the class ExpiredSessionsRemovalTask method buildStoreManager.

private void buildStoreManager() throws BackingStoreException {
    String persistenceStoreType = "file";
    if (ejbAvailability != null) {
        persistenceStoreType = HAEnabled ? ejbAvailability.getSfsbHaPersistenceType() : ejbAvailability.getSfsbPersistenceType();
        if ("ha".equals(persistenceStoreType)) {
            persistenceStoreType = "replicated";
        } else if ("memory".equals(persistenceStoreType)) {
            persistenceStoreType = "file";
        }
    }
    BackingStoreConfiguration<Serializable, SimpleMetadata> conf = new BackingStoreConfiguration<Serializable, SimpleMetadata>();
    String storeName = ejbDescriptor.getName() + "-" + ejbDescriptor.getUniqueId() + "-BackingStore";
    _logger.log(Level.FINE, SFSB_BUILDER_STORE_NAME, storeName);
    String subDirName = "";
    /*        if (ejbDescriptor.getApplication().isVirtual()) {
            String archURI = ejbDescriptor.getEjbBundleDescriptor().
                    getModuleDescriptor().getArchiveUri();
            subDirName += FileUtils.makeFriendlyFilename(archURI);
            subDirName += "_" + FileUtils.makeFriendlyFilename(ejbDescriptor.getName());
        } else {
            subDirName += FileUtils.makeFriendlyFilename(ejbDescriptor.getApplication().getRegistrationName());
            subDirName += "_" + FileUtils.makeFriendlyFilename(ejbDescriptor.getEjbBundleDescriptor().getName());
            subDirName += "_" + FileUtils.makeFriendlyFilename(ejbDescriptor.getName());
        }*/
    subDirName += ejbDescriptor.getName() + "-" + ejbDescriptor.getUniqueId();
    conf.setShortUniqueName("" + ejbDescriptor.getUniqueId()).setStoreName(storeName).setStoreType(persistenceStoreType).setBaseDirectory(new File(ejbContainerConfig.getSessionStore(), subDirName)).setKeyClazz(Serializable.class).setValueClazz(SimpleMetadata.class).setClassLoader(StatefulContainerFactory.class.getClassLoader());
    Map<String, Object> vendorMap = conf.getVendorSpecificSettings();
    vendorMap.put("local.caching", true);
    vendorMap.put("start.gms", false);
    vendorMap.put("async.replication", asyncReplication);
    vendorMap.put("broadcast.remove.expired", false);
    vendorMap.put("value.class.is.thread.safe", true);
    vendorMap.put("key.transformer", keyGen);
    if (hazelcast != null) {
        if (hazelcast.isEnabled()) {
            conf.setClusterName(hazelcast.getMemberGroup());
            conf.setInstanceName(hazelcast.getMemberName());
        }
    }
    BackingStoreFactory factory = null;
    try {
        factory = services.getService(BackingStoreFactory.class, persistenceStoreType);
    } catch (Exception ex) {
        _logger.log(Level.WARNING, SFSB_BUILDER_INSTANTIATE_BACKING_STORE_EXCEPTION, new Object[] { persistenceStoreType, ex });
    }
    try {
        if (factory == null) {
            factory = services.getService(BackingStoreFactory.class, "noop");
        }
        this.backingStore = factory.createBackingStore(conf);
    } catch (Exception ex) {
        _logger.log(Level.WARNING, SFSB_BUILDER_INSTANTIATE_BACKING_STORE_EXCEPTION, new Object[] { persistenceStoreType, ex });
        throw new BackingStoreException("Could not instantiate backing store for type [" + persistenceStoreType + "]", ex);
    }
    _logger.log(Level.INFO, SFSB_BUILDER_INSTANTIATED_BACKING_STORE, new Object[] { backingStore, HAEnabled, conf });
}
Also used : BackingStoreFactory(org.glassfish.ha.store.api.BackingStoreFactory) Serializable(java.io.Serializable) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) SimpleMetadata(org.glassfish.ha.store.util.SimpleMetadata) File(java.io.File) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) BackingStoreConfiguration(org.glassfish.ha.store.api.BackingStoreConfiguration)

Example 3 with SimpleMetadata

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

the class LruSessionCache method saveStateToStore.

private boolean saveStateToStore(Serializable sessionKey, StatefulEJBContext ctx) throws java.io.NotSerializableException, java.io.IOException {
    byte[] data = container.serializeContext(ctx);
    // If we are here then we were able to serialize the object successfully
    boolean status = false;
    if (data != null) {
        SimpleMetadata beanState = new SimpleMetadata(ctx.getVersion(), ctx.getLastAccessTime(), removalTimeoutInSeconds * 1000L, data);
        // Note: Don't increment the version here because
        // this is called on an async thread and the client
        // already has the correct version
        beanState.setVersion(ctx.getVersion());
        try {
            if (backingStore != null) {
                backingStore.save(sessionKey, beanState, !ctx.existsInStore());
                // sfsbStoreMonitor.setPassivationSize(data.length);
                status = true;
            }
        } catch (BackingStoreException sfsbEx) {
            _logger.log(Level.WARNING, EXCEPTION_DURING_PASSIVATE_SAVE, new Object[] { cacheName, sessionKey, sfsbEx });
        }
    }
    return status;
}
Also used : BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) SimpleMetadata(org.glassfish.ha.store.util.SimpleMetadata)

Example 4 with SimpleMetadata

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

the class ReplicationStore method doValveSave.

/**
 * 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 doValveSave(Session session) throws IOException {
    if (_logger.isLoggable(Level.FINE)) {
        if (session instanceof HASession) {
            _logger.fine("ReplicationStore>>doValveSave:id =" + ((HASession) session).getIdInternal());
        }
        _logger.fine("ReplicationStore>>doValveSave:valid =" + session.getIsValid());
    }
    // begin 6470831 do not save if session is not valid
    if (!session.getIsValid()) {
        return;
    }
    if (!(session instanceof BaseHASession)) {
        return;
    }
    // end 6470831
    String userName = "";
    if (session.getPrincipal() != null) {
        userName = session.getPrincipal().getName();
        ((BaseHASession) session).setUserName(userName);
    }
    byte[] sessionState = this.getByteArray(session, isReplicationCompressionEnabled());
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.finest("ReplicationStore->Byte array to save");
        StringBuilder sb = new StringBuilder("Session data{");
        for (byte b : sessionState) {
            sb.append(b + "_");
        }
        sb.append("}");
        _logger.finest(sb.toString());
    }
    SimpleMetadata simpleMetadata = // version
    SimpleMetadataFactory.createSimpleMetadata(// version
    session.getVersion(), // lastaccesstime
    session.getLastAccessedTime(), // maxinactiveinterval
    session.getMaxInactiveInterval() * 1000L, // state
    sessionState);
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.finest("In doValveSave metadata is " + simpleMetadata);
    }
    try {
        BackingStore<String, SimpleMetadata> replicator = getSimpleMetadataBackingStore();
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("ReplicationStore>>doValveSave replicator: " + replicator);
            _logger.fine("ReplicationStore>>doValveSave version:" + session.getVersion());
        }
        HASession haSess = (HASession) session;
        // id
        replicator.save(// id
        session.getIdInternal(), simpleMetadata, haSess.isPersistent());
        if (_logger.isLoggable(Level.FINE)) {
            _logger.fine("Save succeeded.");
        }
    } 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 5 with SimpleMetadata

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

the class LruSessionCache method getStateFromStore.

// passivateEJB
private Object getStateFromStore(Serializable sessionKey, SFSBContainerCallback container) {
    Object object = null;
    try {
        SimpleMetadata beanState = null;
        if (backingStore != null) {
            beanState = backingStore.load(sessionKey, null);
        }
        byte[] data = (beanState != null) ? beanState.getState() : null;
        if (data == null) {
            if (_logger.isLoggable(Level.SEVERE)) {
                _logger.log(Level.SEVERE, CANNOT_LOAD_FROM_BACKUP_STORE, new Object[] { cacheName, sessionKey });
            }
        } else {
            // sfsbStoreMonitor.setActivationSize(data.length);
            incrementLoadFromBackupCount();
            object = container.deserializeData(data);
        }
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, EXCEPTION_LOADING_BACKUP_SESSION, new Object[] { cacheName, sessionKey, ex });
    } catch (Error ex) {
        _logger.log(Level.SEVERE, ERROR_LOADING_BACKUP_SESSION, new Object[] { cacheName, sessionKey, ex });
    }
    return object;
}
Also used : SimpleMetadata(org.glassfish.ha.store.util.SimpleMetadata) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException)

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