[Jboss-cvs] JBossAS SVN: r55049 - trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 2 17:16:13 EDT 2006


Author: bstansberry at jboss.com
Date: 2006-08-02 17:16:12 -0400 (Wed, 02 Aug 2006)
New Revision: 55049

Modified:
   trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/IntervalSnapshotManager.java
Log:
[JBAS-3318] Replicate all sessions affected by a cross-context call
Get rid of protected fields

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/IntervalSnapshotManager.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/IntervalSnapshotManager.java	2006-08-02 21:15:58 UTC (rev 55048)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/tc6/session/IntervalSnapshotManager.java	2006-08-02 21:16:12 UTC (rev 55049)
@@ -21,10 +21,9 @@
 */
 package org.jboss.web.tomcat.tc6.session;
 
-import java.util.HashMap;
-import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
 
-import org.apache.catalina.Context;
 import org.apache.catalina.Session;
 import org.jboss.logging.Logger;
 
@@ -33,6 +32,7 @@
  * period of time and distributes them en bloc.
  *
  * @author Thomas Peuss <jboss at peuss.de>
+ * @author Brian Stansberry
  * @version $Revision$
  */
 public class IntervalSnapshotManager extends SnapshotManager implements Runnable
@@ -40,16 +40,16 @@
    static Logger log = Logger.getLogger(IntervalSnapshotManager.class);
 
    // the interval in ms
-   protected int interval = 1000;
+   private int interval = 1000;
 
    // the modified sessions
-   protected HashMap sessions = new HashMap();
+   private Set sessions = new LinkedHashSet();
 
    // the distribute thread
-   protected Thread thread = null;
+   private Thread thread = null;
 
    // has the thread finished?
-   protected boolean threadDone = false;
+   private boolean threadDone = false;
 
    public IntervalSnapshotManager(AbstractJBossManager manager, String path)
    {
@@ -68,11 +68,10 @@
    public void snapshot(String id)
    {
       try
-      {
-         Session session = (Session) manager.findSession(id);
+      {         
          synchronized (sessions)
          {
-            sessions.put(id, session);
+            sessions.add(id);
          }
       }
       catch (Exception e)
@@ -86,22 +85,28 @@
     */
    protected void processSessions()
    {
-      HashMap copy = new HashMap(sessions.size());
-
+      String[] ids = null;
       synchronized (sessions)
       {
-         copy.putAll(sessions);
+         ids = new String[sessions.size()];
+         ids = (String[]) sessions.toArray(ids);
          sessions.clear();
       }
-      Iterator iter = copy.values().iterator();
 
-      // distribute all modified sessions using default replication type
-      while (iter.hasNext())
+      AbstractJBossManager mgr = getManager();
+      for (int i = 0; i < ids.length; i++)
       {
-         Session session = (Session) iter.next();
-         manager.storeSession(session);
+         try
+         {
+            Session session = mgr.findSession(ids[i]);
+            if (session != null)
+               mgr.storeSession(session);
+         }
+         catch (Exception e)
+         {
+            getLog().error("Caught exception processing session " + ids[i], e);
+         }
       }
-      copy.clear();
    }
 
    /**
@@ -134,9 +139,9 @@
          return;
       }
 
-      thread = new Thread(this, "ClusteredSessionDistributor[" + contextPath + "]");
+      thread = new Thread(this, "ClusteredSessionDistributor[" + getContextPath() + "]");
       thread.setDaemon(true);
-      thread.setContextClassLoader(manager.getContainer().getLoader().getClassLoader());
+      thread.setContextClassLoader(getManager().getContainer().getLoader().getClassLoader());
       threadDone = false;
       thread.start();
    }
@@ -163,28 +168,26 @@
    }
 
    /**
-    * Little Thread - sleep awhile...
-    */
-   protected void threadSleep()
-   {
-      try
-      {
-         Thread.sleep(interval);
-      }
-      catch (InterruptedException e)
-      {
-      }
-   }
-
-   /**
     * Thread-loop
     */
    public void run()
    {
       while (!threadDone)
       {
-         threadSleep();
-         processSessions();
+         try
+         {
+            Thread.sleep(interval);
+            processSessions();
+         }
+         catch (InterruptedException ie)
+         {
+            if (!threadDone)
+               getLog().error("Caught exception processing sessions", ie);
+         }
+         catch (Exception e)
+         {
+            getLog().error("Caught exception processing sessions", e);
+         }
       }
    }
 }




More information about the jboss-cvs-commits mailing list