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;
}
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;
}
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);
}
}
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;
}
Aggregations