User: oberg
Date: 00/10/27 06:38:04
Modified: src/main/org/jboss/ejb/plugins
StatefulSessionFilePersistenceManager.java
Log:
All non-transient fields are stored now, not just public ones. Thanks to Tilmann
Ludwig for pointing it out.
Revision Changes Path
1.12 +176 -147
jboss/src/main/org/jboss/ejb/plugins/StatefulSessionFilePersistenceManager.java
Index: StatefulSessionFilePersistenceManager.java
===================================================================
RCS file:
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/StatefulSessionFilePersistenceManager.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- StatefulSessionFilePersistenceManager.java 2000/10/09 20:15:37 1.11
+++ StatefulSessionFilePersistenceManager.java 2000/10/27 13:38:04 1.12
@@ -61,115 +61,138 @@
* @see <related>
* @author Rickard �berg ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public class StatefulSessionFilePersistenceManager
implements StatefulSessionPersistenceManager
{
// Constants -----------------------------------------------------
-
+
// Attributes ----------------------------------------------------
StatefulSessionContainer con;
-
+
Method ejbActivate;
Method ejbPassivate;
Method ejbRemove;
-
+
File dir;
-
+
+ ArrayList fields;
+
// Static --------------------------------------------------------
private static long id = System.currentTimeMillis();
-
+
// Constructors --------------------------------------------------
-
+
// Public --------------------------------------------------------
public void setContainer(Container c)
{
con = (StatefulSessionContainer)c;
}
-
- public void init()
- throws Exception {
-
- // Find methods
- ejbActivate = SessionBean.class.getMethod("ejbActivate", new Class[0]);
-
- ejbPassivate = SessionBean.class.getMethod("ejbPassivate", new Class[0]);
-
- ejbRemove = SessionBean.class.getMethod("ejbRemove", new Class[0]);
-
- // Initialize the dataStore
- String ejbName = con.getBeanMetaData().getEjbName();
-
- // Base dir
- File databaseDir = new
File(getClass().getResource("/db.properties").getFile()).getParentFile();
-
- File database = new File(databaseDir, "sessions");
-
- dir = new File(database, ejbName);
-
- dir.mkdirs();
-
- Logger.debug("Storing sessions for "+ejbName+" in:"+dir);
-
- // Clear dir of old files
- File[] sessions = dir.listFiles();
- for (int i = 0; i < sessions.length; i++)
- {
+
+ public void init()
+ throws Exception
+ {
+
+ // Find methods
+ ejbActivate = SessionBean.class.getMethod("ejbActivate", new Class[0]);
+
+ ejbPassivate = SessionBean.class.getMethod("ejbPassivate", new Class[0]);
+
+ ejbRemove = SessionBean.class.getMethod("ejbRemove", new Class[0]);
+
+ // Initialize the dataStore
+ String ejbName = con.getBeanMetaData().getEjbName();
+
+ // Base dir
+ File databaseDir = new
File(getClass().getResource("/db.properties").getFile()).getParentFile();
+
+ File database = new File(databaseDir, "sessions");
+
+ dir = new File(database, ejbName);
+
+ dir.mkdirs();
+
+ Logger.debug("Storing sessions for "+ejbName+" in:"+dir);
+
+ // Clear dir of old files
+ File[] sessions = dir.listFiles();
+ for (int i = 0; i < sessions.length; i++)
+ {
sessions[i].delete();
- }
- Logger.debug(sessions.length + " old sessions removed");
+ }
+ Logger.debug(sessions.length + " old sessions removed");
+
+ // Get fields of class
+ Class beanClass = con.getBeanClass();
+ fields = new ArrayList();
+ while (!beanClass.equals(Object.class))
+ {
+ Field[] f = beanClass.getDeclaredFields();
+
+ // Skip transient fields
+ for (int i = 0; i < f.length; i++)
+ if (!Modifier.isTransient(f[i].getModifiers()))
+ {
+ fields.add(f[i]);
+ }
+
+ beanClass = beanClass.getSuperclass();
+ }
}
-
+
public void start()
- throws Exception
+ throws Exception
{
}
public void stop()
{
}
-
+
public void destroy()
{
}
-
+
public void createSession(Method m, Object[] args,
StatefulSessionEnterpriseContext ctx)
- throws Exception
+ throws Exception
{
// Get methods
try
{
Method createMethod = con.getBeanClass().getMethod("ejbCreate",
m.getParameterTypes());
-
+
// Call ejbCreate
createMethod.invoke(ctx.getInstance(), args);
-
+
} catch (IllegalAccessException e)
- {
+ {
// Throw this as a bean exception...(?)
throw new EJBException(e);
- } catch (InvocationTargetException ite)
- {
+ } catch (InvocationTargetException ite)
+ {
Throwable e = ite.getTargetException();
if (e instanceof EJBException)
{
- // Rethrow exception
- throw (EJBException)e;
- } else if (e instanceof RuntimeException)
- {
- // Wrap runtime exceptions
- throw new EJBException((Exception)e);
- } else if (e instanceof Exception)
+ // Rethrow exception
+ throw (EJBException)e;
+ }
+ else if (e instanceof RuntimeException)
{
+ // Wrap runtime exceptions
+ throw new EJBException((Exception)e);
+ }
+ else if (e instanceof Exception)
+ {
// Remote, Create, or custom app. exception
throw (Exception)e;
- } else
+ }
+ else
{
throw (Error)e;
}
- }
-
+ }
+
// Set id
ctx.setId(nextId());
@@ -181,149 +204,155 @@
}
public void activateSession(StatefulSessionEnterpriseContext ctx)
- throws RemoteException
+ throws RemoteException
{
- try
- {
-
- ObjectInputStream in;
-
-
- // Load state
- in = new SessionObjectInputStream(ctx, new FileInputStream(new
File(dir, ctx.getId()+".ser")));
- Field[] fields = ctx.getInstance().getClass().getFields();
-
- for (int i = 0; i < fields.length; i++)
- if (!Modifier.isTransient(fields[i].getModifiers()))
- fields[i].set(ctx.getInstance(), in.readObject());
-
- // Call bean
+ try
+ {
+
+ ObjectInputStream in;
+
+
+ // Load state
+ in = new SessionObjectInputStream(ctx, new FileInputStream(new File(dir,
ctx.getId()+".ser")));
+ for (int i = 0; i < fields.size(); i++)
+ ((Field)fields.get(i)).set(ctx.getInstance(), in.readObject());
+
+ // Call bean
ejbActivate.invoke(ctx.getInstance(), new Object[0]);
} catch (ClassNotFoundException e)
{
- throw new ServerException("Could not activate", e);
+ throw new ServerException("Could not activate", e);
} catch (IOException e)
{
- throw new ServerException("Could not activate", e);
+ throw new ServerException("Could not activate", e);
} catch (IllegalAccessException e)
- {
+ {
// Throw this as a bean exception...(?)
throw new EJBException(e);
- } catch (InvocationTargetException ite)
- {
+ } catch (InvocationTargetException ite)
+ {
Throwable e = ite.getTargetException();
if (e instanceof EJBException)
+ {
+ // Rethrow exception
+ throw (EJBException)e;
+ }
+ else if (e instanceof RuntimeException)
{
- // Rethrow exception
- throw (EJBException)e;
- } else if (e instanceof RuntimeException)
- {
- // Wrap runtime exceptions
- throw new EJBException((Exception)e);
- } else if (e instanceof RemoteException)
+ // Wrap runtime exceptions
+ throw new EJBException((Exception)e);
+ }
+ else if (e instanceof RemoteException)
{
// Remote, Create, or custom app. exception
throw (RemoteException)e;
- } else
+ }
+ else
{
throw (Error)e;
}
- }
+ }
}
-
+
public void passivateSession(StatefulSessionEnterpriseContext ctx)
- throws RemoteException
+ throws RemoteException
{
try
{
- // Call bean
+ // Call bean
ejbPassivate.invoke(ctx.getInstance(), new Object[0]);
-
- // Store state
- ObjectOutputStream out = new SessionObjectOutputStream(new
FileOutputStream(new File(dir, ctx.getId()+".ser")));
-
- Field[] fields = ctx.getInstance().getClass().getFields();
-
- for (int i = 0; i < fields.length; i++)
- if (!Modifier.isTransient(fields[i].getModifiers()))
- out.writeObject(fields[i].get(ctx.getInstance()));
-
+
+ // Store state
+ ObjectOutputStream out = new SessionObjectOutputStream(new
FileOutputStream(new File(dir, ctx.getId()+".ser")));
+
+ for (int i = 0; i < fields.size(); i++)
+ out.writeObject(((Field)fields.get(i)).get(ctx.getInstance()));
+
out.close();
- } catch (IOException e)
- {
+ } catch (IOException e)
+ {
throw new ServerException("Could not passivate", e);
- }catch (IllegalAccessException e)
- {
- // Throw this as a bean exception...(?)
- throw new EJBException(e);
- } catch (InvocationTargetException ite)
- {
- Throwable e = ite.getTargetException();
- if (e instanceof EJBException)
- {
- // Rethrow exception
- throw (EJBException)e;
- } else if (e instanceof RuntimeException)
- {
- // Wrap runtime exceptions
- throw new EJBException((Exception)e);
- } else if (e instanceof RemoteException)
- {
- // Remote, Create, or custom app. exception
- throw (RemoteException)e;
- } else
- {
- throw (Error)e;
- }
- }
+ }catch (IllegalAccessException e)
+ {
+ // Throw this as a bean exception...(?)
+ throw new EJBException(e);
+ } catch (InvocationTargetException ite)
+ {
+ Throwable e = ite.getTargetException();
+ if (e instanceof EJBException)
+ {
+ // Rethrow exception
+ throw (EJBException)e;
+ }
+ else if (e instanceof RuntimeException)
+ {
+ // Wrap runtime exceptions
+ throw new EJBException((Exception)e);
+ }
+ else if (e instanceof RemoteException)
+ {
+ // Remote, Create, or custom app. exception
+ throw (RemoteException)e;
+ }
+ else
+ {
+ throw (Error)e;
+ }
+ }
}
-
+
public void removeSession(StatefulSessionEnterpriseContext ctx)
- throws RemoteException, RemoveException
+ throws RemoteException, RemoveException
{
// Call bean
try
{
ejbRemove.invoke(ctx.getInstance(), new Object[0]);
} catch (IllegalAccessException e)
- {
+ {
// Throw this as a bean exception...(?)
throw new EJBException(e);
- } catch (InvocationTargetException ite)
- {
+ } catch (InvocationTargetException ite)
+ {
Throwable e = ite.getTargetException();
if (e instanceof EJBException)
{
- // Rethrow exception
- throw (EJBException)e;
- } else if (e instanceof RuntimeException)
- {
- // Wrap runtime exceptions
- throw new EJBException((Exception)e);
- } else if (e instanceof RemoveException)
+ // Rethrow exception
+ throw (EJBException)e;
+ }
+ else if (e instanceof RuntimeException)
{
+ // Wrap runtime exceptions
+ throw new EJBException((Exception)e);
+ }
+ else if (e instanceof RemoveException)
+ {
throw (RemoveException)e;
- } else if (e instanceof RemoteException)
+ }
+ else if (e instanceof RemoteException)
{
throw (RemoteException)e;
- } else
+ }
+ else
{
throw (Error)e;
}
- }
+ }
}
-
+
// Z implementation ----------------------------------------------
-
+
// Package protected ---------------------------------------------
-
+
// Protected -----------------------------------------------------
protected Long nextId()
{
return new Long(id++);
}
-
+
// Private -------------------------------------------------------
-
+
// Inner classes -------------------------------------------------
}
+
+