| Method from org.jboss.ejb.plugins.StatefulSessionFilePersistenceManager Detail: |
public void activateSession(StatefulSessionEnterpriseContext ctx) throws RemoteException {
boolean trace = log.isTraceEnabled();
if (trace)
{
log.trace("Attempting to activate; ctx=" + ctx);
}
Object id = ctx.getId();
// Load state
File file = getFile(id);
if (trace)
{
log.trace("Reading session state from: " + file);
}
try
{
FileInputStream fis = FISAction.open(file);
SessionObjectInputStream in = new SessionObjectInputStream(ctx,
new BufferedInputStream(fis));
try
{
Object obj = in.readObject();
if (trace)
{
log.trace("Session state: " + obj);
}
ctx.setInstance(obj);
}
finally
{
in.close();
}
}
catch(Exception e)
{
throw new EJBException("Could not activate; failed to " +
"restore state", e);
}
removePassivated(id);
try
{
// Instruct the bean to perform activation logic
AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_ACTIVATE);
SessionBean bean = (SessionBean) ctx.getInstance();
bean.ejbActivate();
}
finally
{
AllowedOperationsAssociation.popInMethodFlag();
}
if (trace)
{
log.trace("Activation complete; ctx=" + ctx);
}
}
|
public Object createId(StatefulSessionEnterpriseContext ctx) throws Exception {
return new UID();
}
|
protected void createService() throws Exception {
// Initialize the dataStore
String ejbName = con.getBeanMetaData().getEjbName();
// Get the system data directory
File dir = ServerConfigLocator.locate().getServerTempDir();
// Setup the reference to the session data store directory
dir = new File(dir, storeDirName);
// ejbName is not unique across all deployments, so use a unique token
dir = new File(dir, ejbName + "-" + new UID().toString());
storeDir = dir;
log.debug("Storing sessions for '" + ejbName + "' in: " + storeDir);
// if the directory does not exist then try to create it
if( !storeDir.exists() )
{
if( MkdirsFileAction.mkdirs(storeDir) == false )
{
throw new IOException("Failed to create directory: " + storeDir);
}
}
// make sure we have a directory
if( !storeDir.isDirectory() )
{
throw new IOException("File exists where directory expected: " + storeDir);
}
// make sure we can read and write to it
if( !storeDir.canWrite() || !storeDir.canRead() )
{
throw new IOException("Directory must be readable and writable: " + storeDir);
}
// Purge state session state files, should be none, due to unique directory
purgeAllSessionData();
}
|
public void createdSession(StatefulSessionEnterpriseContext ctx) throws Exception {
// nothing
}
|
protected void destroyService() throws Exception {
// Purge data and attempt to delete directory
purgeAllSessionData();
// Nuke the directory too if purge is enabled
if( purgeEnabled && !storeDir.delete() )
{
log.warn("Failed to delete session state storage directory: " + storeDir);
}
}
Purge any data in the store, and then the store directory too. |
public boolean getPurgeEnabled() {
return purgeEnabled;
}
Get the stale session state purge enabled flag.
jmx:managed-attribute |
public File getStoreDirectory() {
return storeDir;
}
Returns the directory used to store session passivation state files.
jmx:managed-attribute |
public String getStoreDirectoryName() {
return storeDirName;
}
Get the sub-directory name under the server data directory
where session data is stored.
jmx:managed-attribute |
public void passivateSession(StatefulSessionEnterpriseContext ctx) throws RemoteException {
boolean trace = log.isTraceEnabled();
if (trace)
{
log.trace("Attempting to passivate; ctx=" + ctx);
}
try
{
// Instruct the bean to perform passivation logic
AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_PASSIVATE);
SessionBean bean = (SessionBean) ctx.getInstance();
bean.ejbPassivate();
}
finally
{
AllowedOperationsAssociation.popInMethodFlag();
}
// Store state
File file = getFile(ctx.getId());
if (trace)
{
log.trace("Saving session state to: " + file);
}
try
{
FileOutputStream fos = FOSAction.open(file);
SessionObjectOutputStream out = new SessionObjectOutputStream(
new BufferedOutputStream(fos));
Object obj = ctx.getInstance();
if (trace)
{
log.trace("Writing session state: " + obj);
}
try
{
out.writeObject(obj);
}
finally
{
out.close();
}
}
catch(Exception e)
{
throw new EJBException("Could not passivate; failed to save state", e);
}
if (trace)
{
log.trace("Passivation complete; ctx=" + ctx);
}
}
|
public void removePassivated(Object id) {
boolean trace = log.isTraceEnabled();
File file = getFile(id);
// only attempt to delete if the file exists
if( file.exists() )
{
if (trace)
{
log.trace("Removing passivated state file: " + file);
}
if( DeleteFileAction.delete(file) == false )
{
log.warn("Failed to delete passivated state file: " + file);
}
}
}
Removes the saved state file (if any) for the given session id. |
public void removeSession(StatefulSessionEnterpriseContext ctx) throws RemoveException, RemoteException {
boolean trace = log.isTraceEnabled();
if (trace)
{
log.trace("Attempting to remove; ctx=" + ctx);
}
// Instruct the bean to perform removal logic
SessionBean bean = (SessionBean) ctx.getInstance();
bean.ejbRemove();
if (trace)
{
log.trace("Removal complete; ctx=" + ctx);
}
}
|
public void setContainer(Container con) {
this.con = (StatefulSessionContainer) con;
}
|
public void setPurgeEnabled(boolean flag) {
this.purgeEnabled = flag;
}
Set the stale session state purge enabled flag.
jmx:managed-attribute |
public void setStoreDirectoryName(String dirName) {
this.storeDirName = dirName;
}
Set the sub-directory name under the server data directory
where session data will be stored.
This value will be appened to the value of
jboss-server-data-dir.
This value is only used during creation and will not dynamically
change the store directory when set after the create step has finished. |