User: slaboure
Date: 02/02/09 07:27:35
Modified: src/main/org/jboss/ha/httpsession/server
ClusteredHTTPSessionService.java
Log:
- uses bean now in ./beanimpl
- state cleaner de-activated for now
- new session creation scheme: there was no creation until now!
Revision Changes Path
1.4 +114 -59
jbossmx/src/main/org/jboss/ha/httpsession/server/ClusteredHTTPSessionService.java
Index: ClusteredHTTPSessionService.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmx/src/main/org/jboss/ha/httpsession/server/ClusteredHTTPSessionService.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ClusteredHTTPSessionService.java 6 Jan 2002 16:05:19 -0000 1.3
+++ ClusteredHTTPSessionService.java 9 Feb 2002 15:27:35 -0000 1.4
@@ -16,11 +16,11 @@
import org.jboss.system.ServiceMBeanSupport;
-import org.jboss.ha.httpsession.interfaces.ClusteredHTTPSession;
-import org.jboss.ha.httpsession.interfaces.LocalClusteredHTTPSession;
-import org.jboss.ha.httpsession.interfaces.ClusteredHTTPSessionBusiness;
-import org.jboss.ha.httpsession.interfaces.ClusteredHTTPSessionHome;
-import org.jboss.ha.httpsession.interfaces.LocalClusteredHTTPSessionHome;
+import org.jboss.ha.httpsession.beanimpl.interfaces.ClusteredHTTPSession;
+import org.jboss.ha.httpsession.beanimpl.interfaces.LocalClusteredHTTPSession;
+import org.jboss.ha.httpsession.beanimpl.interfaces.ClusteredHTTPSessionBusiness;
+import org.jboss.ha.httpsession.beanimpl.interfaces.ClusteredHTTPSessionHome;
+import org.jboss.ha.httpsession.beanimpl.interfaces.LocalClusteredHTTPSessionHome;
import org.jboss.ha.httpsession.interfaces.SerializableHttpSession;
/**
@@ -29,11 +29,11 @@
* @see org.jboss.ha.httpsession.server.ClusteredHTTPSessionServiceMBean
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>.
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*
* <p><b>Revisions:</b>
*
- * <p><b>31. d�cembre 2001 Sacha Labourey:</b>
+ * <p><b>31. decembre 2001 Sacha Labourey:</b>
* <ul>
* <li> First implementation </li>
* </ul>
@@ -43,61 +43,90 @@
extends ServiceMBeanSupport
implements ClusteredHTTPSessionServiceMBean
{
-
+
// Constants -----------------------------------------------------
-
+
protected final static long CLEANUP_FREQUENCY = 30000; // every 30 seconds
-
+
// Attributes ----------------------------------------------------
-
+
protected ClusteredHTTPSessionHome httpSessionHome = null;
protected LocalClusteredHTTPSessionHome localHttpSessionHome = null;
protected ClusteredHTTPSessionService.CleanupDaemon cleanup = null;
protected long sessionTimeout = 15*60*1000;
protected boolean useLocalBean = false;
-
+
// Static --------------------------------------------------------
-
+
protected static String NODE_ID = null;
-
+
// Constructors --------------------------------------------------
-
+
public ClusteredHTTPSessionService ()
{
}
-
+
// Public --------------------------------------------------------
-
+
public String getName ()
{
return "Clustered HTTPSession";
}
-
+
// ClusteredHTTPSessionServiceMBean
----------------------------------------------
-
+
public void setHttpSession (String sessionId, SerializableHttpSession session)
throws EJBException
{
+ if (log.isDebugEnabled ())
+ log.debug ("setHttpSession called for session: "+ sessionId);
+
+ ClusteredHTTPSessionBusiness bean = null;
+
+ // We first try to find the bean or we create it if it does not yet exist
+ //
try
{
if (useLocalBean)
{
- LocalClusteredHTTPSession sessionBean =
localHttpSessionHome.findByPrimaryKey (sessionId);
- sessionBean.setSession (session);
+ bean = localHttpSessionHome.findByPrimaryKey (sessionId);
}
else
{
- ClusteredHTTPSession sessionBean = httpSessionHome.findByPrimaryKey
(sessionId);
- sessionBean.setSession (session);
+ bean = httpSessionHome.findByPrimaryKey (sessionId);
+ }
+ }
+ catch (javax.ejb.FinderException fe)
+ {
+ try
+ {
+ bean = createSession (sessionId);
+ }
+ catch (Exception e)
+ {
+ throw new EJBException ("Exception in setHttpSession while creating
unexisting session: " + e.toString ());
}
}
catch (Exception e)
{
throw new EJBException ("Exception in setHttpSession: " + e.toString ());
}
+
+ // We have one bean: we set its session
+ //
+ try
+ {
+ bean.setSession (session);
+ }
+ catch (Exception e)
+ {
+ throw new EJBException ("Exception in setHttpSession: " + e.toString ());
+ }
}
-
+
public SerializableHttpSession getHttpSession (String sessionId) throws
EJBException
{
+ if (log.isDebugEnabled ())
+ log.debug ("getHttpSession called for session: "+ sessionId);
try
{
if (useLocalBean)
@@ -106,7 +135,7 @@
return sessionBean.getSession ();
}
else
- {
+ {
ClusteredHTTPSession sessionBean = httpSessionHome.findByPrimaryKey
(sessionId);
return sessionBean.getSession ();
}
@@ -116,9 +145,11 @@
throw new EJBException ("Exception in setHttpSession: " + e.toString ());
}
}
-
+
public void removeHttpSession (String sessionId) throws EJBException
{
+ if (log.isDebugEnabled ())
+ log.debug ("removeHttpSession called for session: "+ sessionId);
try
{
if (useLocalBean)
@@ -126,7 +157,7 @@
localHttpSessionHome.remove (sessionId);
}
else
- {
+ {
httpSessionHome.remove (sessionId);
}
}
@@ -135,15 +166,18 @@
throw new EJBException ("Exception in removeHttpSession: " + e.toString
());
}
}
-
+
public long getSessionTimeout () { return this.sessionTimeout; }
public void setSessionTimeout (long miliseconds) { this.sessionTimeout =
miliseconds; }
-
+
public synchronized String getSessionId ()
{
- return NODE_ID + Long.toString (System.currentTimeMillis ());
+ String id = NODE_ID + Long.toString (System.currentTimeMillis ());
+ if (log.isDebugEnabled ())
+ log.debug ("getSessionId called: " + id);
+ return id;
}
-
+
public void setUseLocalBean (boolean useLocal)
{
int state = this.getState ();
@@ -152,14 +186,14 @@
else
this.useLocalBean = useLocal;
}
-
+
public boolean getUseLocalBean ()
{
return this.useLocalBean;
}
-
+
// ServiceMBeanSupport overrides
---------------------------------------------------
-
+
public void startService ()
throws Exception
{
@@ -167,26 +201,26 @@
//
if (NODE_ID == null)
NODE_ID = Long.toString (System.currentTimeMillis ()) + "-";
-
+
// we (try to) acquire a home reference to the entity bean that stores our
sessions
//
this.initRefToBean ();
cleanup = new ClusteredHTTPSessionService.CleanupDaemon ();
- cleanup.start ();
+ //cleanup.start ();
}
-
+
public void stopService ()
{
cleanup.stop ();
httpSessionHome = null;
}
-
+
// Package protected ---------------------------------------------
-
+
// Protected -----------------------------------------------------
-
+
protected void initRefToBean () throws Exception
- {
+ {
InitialContext jndiContext = new InitialContext ();
if (useLocalBean)
{
@@ -200,65 +234,86 @@
PortableRemoteObject.narrow (ref, ClusteredHTTPSessionHome.class);
}
}
+
+ protected ClusteredHTTPSessionBusiness createSession (String id) throws Exception
+ {
+ try
+ {
+ ClusteredHTTPSessionBusiness sessionBean = null;
+ if (useLocalBean)
+ {
+ sessionBean = localHttpSessionHome.create (id);
+ }
+ else
+ {
+ sessionBean = httpSessionHome.create (id);
+ }
+ return sessionBean;
+ }
+ catch (Exception e)
+ {
+ throw new EJBException ("Exception in createSession : " + e.toString ());
+ }
+ }
// Private -------------------------------------------------------
-
+
// Inner classes -------------------------------------------------
-
+
protected class CleanupDaemon implements Runnable
{
protected boolean stopping = false;
-
+
public CleanupDaemon () throws Exception
{
}
-
+
public void start ()
{
stopping = false;
Thread t = new Thread (this, "ClusteredHTTPSessionService -
CleanupDaemon");
t.start ();
}
-
+
public void stop ()
{
stopping = true;
}
-
+
public void run ()
{
while (!stopping)
{
try
{
- // we get all beans and only check if they have timeouted. If we
- // don't ask for the HTTPSession content attribute, this will *not*
+ // we get all beans and only check if they have timeouted. If we
+ // don't ask for the HTTPSession content attribute, this will *not*
// deserialize their content!
//
Collection allBeans = null;
-
+
if (useLocalBean)
allBeans = localHttpSessionHome.findAll ();
else
allBeans = httpSessionHome.findAll ();
-
+
Iterator iter = allBeans.iterator ();
long now = System.currentTimeMillis ();
while (iter.hasNext ())
{
ClusteredHTTPSessionBusiness sessionBean =
(ClusteredHTTPSessionBusiness)iter.next ();
long lastAccess = sessionBean.getLastAccessedTime ();
-
+
if ( ( now - lastAccess) > sessionTimeout )
if (useLocalBean)
((LocalClusteredHTTPSession)sessionBean).remove ();
else
((ClusteredHTTPSession)sessionBean).remove ();
-
+
if (stopping)
- return;
- }
-
+ return;
+ }
+
// and we sleep a while...
//
synchronized (this)
@@ -269,10 +324,10 @@
catch (Exception e)
{
e.printStackTrace ();
- }
-
+ }
+
}
}
}
-
+
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development