Methods Summary |
---|
public org.jboss.ejb3.stateful.StatefulBeanContext | activateSession(java.lang.Object id)Restores session state from the serialized file & invokes
{@link javax.ejb.SessionBean#ejbActivate} on the target bean.
boolean debug = log.isDebugEnabled();
if (debug)
{
log.debug("Attempting to activate; id=" + id);
}
// Load state
File file = getFile(id);
if (!file.exists()) return null;
if (debug)
{
log.debug("Reading session state from: " + file);
}
StatefulBeanContext bean = null;
try
{
FileInputStream fis = FISAction.open(file);
// todo need to rewrite SessionObjectInputStream to support EJB3 classes
ObjectInputStream in;
in = new JBossObjectInputStream(new BufferedInputStream(fis));
try
{
bean = (StatefulBeanContext) in.readObject();
}
finally
{
fis.close();
in.close();
}
}
catch (EJBException e)
{
throw e;
}
catch (Exception e)
{
throw new EJBException("Could not activate; failed to " +
"restore state", e);
}
removePassivated(id);
bean.postActivate();
return bean;
|
public void | destroy()Purge any data in the store, and then the store directory too.
// 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);
}
|
private java.io.File | getFile(java.lang.Object id)Make a session state file for the given instance id.
//
// jason: may have to translate id into a os-safe string, though
// the format of UID is safe on Unix and win32 already...
//
return new File(storeDir, String.valueOf(id) + ".ser");
|
public int | getNumPassivatedBeans()
return storeDir.listFiles().length;
|
public java.util.List | getPassivatedBeans()
List beans = new LinkedList();
File[] files = storeDir.listFiles();
for (File file : files)
{
try
{
ObjectInputStream in;
FileInputStream fis = FISAction.open(file);
in = new JBossObjectInputStream(new BufferedInputStream(fis));
try
{
StatefulBeanContext bean = (StatefulBeanContext) in.readObject();
beans.add(bean);
}
finally
{
fis.close();
in.close();
}
}
catch (Exception e)
{
log.warn("Could not read for timeout removal for file " + file.getName() + ". " + e.getMessage());
}
}
return beans;
|
public boolean | getPurgeEnabled()Get the stale session state purge enabled flag.
return purgeEnabled;
|
public java.io.File | getStoreDirectory()Returns the directory used to store session passivation state files.
return storeDir;
|
public java.lang.String | getStoreDirectoryName()Get the sub-directory name under the server data directory
where session data is stored.
return storeDirName;
|
public void | initialize(org.jboss.ejb3.Container con)Setup the session data storage directory.
Purges any existing session data found.
this.con = con;
boolean debug = log.isDebugEnabled();
// Initialize the dataStore
String ejbName = con.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;
if (debug)
{
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 | passivateSession(org.jboss.ejb3.stateful.StatefulBeanContext ctx)Invokes {@link javax.ejb.SessionBean#ejbPassivate} on the target bean and saves the
state of the session to a file.
boolean debug = log.isDebugEnabled();
if (debug)
{
log.debug("Attempting to passivate; id=" + ctx.getId());
}
ctx.prePassivate();
// Store state
File file = getFile(ctx.getId());
if (debug)
{
log.debug("Saving session state to: " + file);
}
try
{
FileOutputStream fos = FOSAction.open(file);
// todo need to rewrite SessionObjectOutputStream to support EJB3 classes
ObjectOutputStream out;
out = new JBossObjectOutputStream(fos, false);
try
{
out.writeObject(ctx);
out.flush();
fos.flush();
fos.close();
}
finally
{
out.close();
}
}
catch (EJBException e)
{
throw e;
}
catch (Exception e)
{
throw new EJBException("Could not passivate; failed to save state", e);
}
if (debug)
{
log.debug("Passivation complete; id=" + ctx.getId());
}
|
public void | purgeAllSessionData()Removes any state files left in the storgage directory.
if (!purgeEnabled) return;
log.debug("Purging all session data in: " + storeDir);
File[] sessions = storeDir.listFiles();
for (int i = 0; i < sessions.length; i++)
{
if (!sessions[i].delete())
{
log.warn("Failed to delete session state file: " + sessions[i]);
}
else
{
log.debug("Removed stale session state: " + sessions[i]);
}
}
|
public void | removePassivated(java.lang.Object id)Removes the saved state file (if any) for the given session id.
boolean debug = log.isDebugEnabled();
File file = getFile(id);
// only attempt to delete if the file exists
if (file.exists())
{
if (debug)
{
log.debug("Removing passivated state file: " + file);
}
if (DeleteFileAction.delete(file) == false)
{
log.warn("Failed to delete passivated state file: " + file);
}
}
|
public void | setContainer(org.jboss.ejb3.Container con)
this.con = con;
|
public void | setPurgeEnabled(boolean flag)Set the stale session state purge enabled flag.
this.purgeEnabled = flag;
|
public void | setStoreDirectoryName(java.lang.String 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.
this.storeDirName = dirName;
|