User: slaboure
Date: 02/01/06 04:05:32
Modified: src/main/org/jboss/ha/httpsession/server
ClusteredHTTPSessionService.java
ClusteredHTTPSessionServiceMBean.java
Log:
Added local interfaces support and generation of session-id available cluster-wide
(simple implementation)
Revision Changes Path
1.2 +84 -13
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClusteredHTTPSessionService.java 2001/12/31 15:19:49 1.1
+++ ClusteredHTTPSessionService.java 2002/01/06 12:05:32 1.2
@@ -17,8 +17,10 @@
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.interfaces.SerializableHttpSession;
/**
@@ -27,7 +29,7 @@
* @see org.jboss.ha.httpsession.server.ClusteredHTTPSessionServiceMBean
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>.
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
* <p><b>Revisions:</b>
*
@@ -49,11 +51,15 @@
// Attributes ----------------------------------------------------
protected ClusteredHTTPSessionHome httpSessionHome = null;
+ protected LocalClusteredHTTPSessionHome localHttpSessionHome = null;
protected ClusteredHTTPSessionService.CleanupDaemon cleanup = null;
protected long sessionTimeout = 15*60*1000;
+ protected boolean useLocalBean = true;
// Static --------------------------------------------------------
+ protected static String NODE_ID = null;
+
// Constructors --------------------------------------------------
public ClusteredHTTPSessionService ()
@@ -73,8 +79,16 @@
{
try
{
- ClusteredHTTPSession sessionBean = httpSessionHome.findByPrimaryKey
(sessionId);
- sessionBean.setSession (session);
+ if (useLocalBean)
+ {
+ LocalClusteredHTTPSession sessionBean =
localHttpSessionHome.findByPrimaryKey (sessionId);
+ sessionBean.setSession (session);
+ }
+ else
+ {
+ ClusteredHTTPSession sessionBean = httpSessionHome.findByPrimaryKey
(sessionId);
+ sessionBean.setSession (session);
+ }
}
catch (Exception e)
{
@@ -86,8 +100,16 @@
{
try
{
- ClusteredHTTPSession sessionBean = httpSessionHome.findByPrimaryKey
(sessionId);
- return sessionBean.getSession ();
+ if (useLocalBean)
+ {
+ LocalClusteredHTTPSession sessionBean =
localHttpSessionHome.findByPrimaryKey (sessionId);
+ return sessionBean.getSession ();
+ }
+ else
+ {
+ ClusteredHTTPSession sessionBean = httpSessionHome.findByPrimaryKey
(sessionId);
+ return sessionBean.getSession ();
+ }
}
catch (Exception e)
{
@@ -99,7 +121,14 @@
{
try
{
- httpSessionHome.remove (sessionId);
+ if (useLocalBean)
+ {
+ localHttpSessionHome.remove (sessionId);
+ }
+ else
+ {
+ httpSessionHome.remove (sessionId);
+ }
}
catch (Exception e)
{
@@ -110,11 +139,35 @@
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 ());
+ }
+
+ public void setUseLocalBean (boolean useLocal)
+ {
+ int state = this.getState ();
+ if (state == this.STARTED || state == this.STARTING)
+ return;
+ else
+ this.useLocalBean = useLocal;
+ }
+
+ public boolean getUseLocalBean ()
+ {
+ return this.useLocalBean;
+ }
+
// ServiceMBeanSupport overrides
---------------------------------------------------
public void startService ()
throws Exception
{
+ // Dummy session id implementation: we generate our node id
+ //
+ 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 ();
@@ -133,11 +186,20 @@
// Protected -----------------------------------------------------
protected void initRefToBean () throws Exception
- {
+ {
InitialContext jndiContext = new InitialContext ();
- Object ref = jndiContext.lookup (ClusteredHTTPSessionHome.JNDI_NAME);
- httpSessionHome = (ClusteredHTTPSessionHome)
- PortableRemoteObject.narrow (ref, ClusteredHTTPSessionHome.class);
+ if (useLocalBean)
+ {
+ Object ref = jndiContext.lookup (LocalClusteredHTTPSessionHome.JNDI_NAME);
+ localHttpSessionHome = (LocalClusteredHTTPSessionHome)
+ PortableRemoteObject.narrow (ref, LocalClusteredHTTPSessionHome.class);
+ }
+ else
+ {
+ Object ref = jndiContext.lookup (ClusteredHTTPSessionHome.JNDI_NAME);
+ httpSessionHome = (ClusteredHTTPSessionHome)
+ PortableRemoteObject.narrow (ref, ClusteredHTTPSessionHome.class);
+ }
}
// Private -------------------------------------------------------
@@ -174,16 +236,25 @@
// don't ask for the HTTPSession content attribute, this will *not*
// deserialize their content!
//
- Collection allBeans = httpSessionHome.findAll ();
+ Collection allBeans = null;
+
+ if (useLocalBean)
+ allBeans = localHttpSessionHome.findAll ();
+ else
+ allBeans = httpSessionHome.findAll ();
+
Iterator iter = allBeans.iterator ();
long now = System.currentTimeMillis ();
while (iter.hasNext ())
{
- ClusteredHTTPSession sessionBean =
(ClusteredHTTPSession)iter.next ();
+ ClusteredHTTPSessionBusiness sessionBean =
(ClusteredHTTPSessionBusiness)iter.next ();
long lastAccess = sessionBean.getLastAccessedTime ();
if ( ( now - lastAccess) > sessionTimeout )
- sessionBean.remove ();
+ if (useLocalBean)
+ ((LocalClusteredHTTPSession)sessionBean).remove ();
+ else
+ ((ClusteredHTTPSession)sessionBean).remove ();
if (stopping)
return;
1.2 +14 -2
jbossmx/src/main/org/jboss/ha/httpsession/server/ClusteredHTTPSessionServiceMBean.java
Index: ClusteredHTTPSessionServiceMBean.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmx/src/main/org/jboss/ha/httpsession/server/ClusteredHTTPSessionServiceMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ClusteredHTTPSessionServiceMBean.java 2001/12/31 15:19:49 1.1
+++ ClusteredHTTPSessionServiceMBean.java 2002/01/06 12:05:32 1.2
@@ -18,7 +18,7 @@
* @see org.jboss.ha.httpsession.interfaces.ClusteredHTTPSessionHome
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>.
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
* <p><b>Revisions:</b>
*
@@ -53,7 +53,11 @@
/**
* Remove an HttpSession from the cluster (log off for example)
*/
- public void removeHttpSession (String sessionId) throws EJBException;
+ public void removeHttpSession (String sessionId) throws EJBException;
+ /**
+ * Generates a new session id available cluster-wide
+ */
+ public String getSessionId ();
/**
* Indicate the duration, in ms, after which the session can be cleaned if no
@@ -65,4 +69,12 @@
* access occurs.
*/
public void setSessionTimeout (long miliseconds);
+
+ /**
+ * Indicates whether the service should use the local and home interfaces of the
+ * entity bean or the remote and remote home interfaces (depending if they are in
+ * the same JVM).
+ */
+ public void setUseLocalBean (boolean useLocal);
+ public boolean getUseLocalBean ();
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development