[Jboss-cvs] JBossAS SVN: r57042 - trunk/messaging/src/main/org/jboss/mq/server

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 21 01:06:00 EDT 2006


Author: adrian at jboss.org
Date: 2006-09-21 01:05:47 -0400 (Thu, 21 Sep 2006)
New Revision: 57042

Modified:
   trunk/messaging/src/main/org/jboss/mq/server/ClientMonitorInterceptor.java
Log:
[JBAS-3468] - Fix the ClientMonitorInterceptor to take into
account the change of client id.
Also removed the synchronization bottleneck.

Modified: trunk/messaging/src/main/org/jboss/mq/server/ClientMonitorInterceptor.java
===================================================================
--- trunk/messaging/src/main/org/jboss/mq/server/ClientMonitorInterceptor.java	2006-09-21 05:03:58 UTC (rev 57041)
+++ trunk/messaging/src/main/org/jboss/mq/server/ClientMonitorInterceptor.java	2006-09-21 05:05:47 UTC (rev 57042)
@@ -21,7 +21,6 @@
  */
 package org.jboss.mq.server;
 
-import java.util.HashMap;
 import java.util.Iterator;
 
 import javax.jms.Destination;
@@ -40,17 +39,22 @@
 import org.jboss.mq.TransactionRequest;
 import org.jboss.mq.il.jvm.JVMClientIL;
 
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+
 /**
  * A pass through Interceptor, which keeps track of when a
  * client was last active.  If a client is inactive for too long,
- * then it is disconnected from the server.
+ * then it is disconnected from the server.<p>
  *
+ * This is only necessary for stateless transports like HTTP
+ *
  * @author <a href="mailto:hchirino at jboss.org">Hiram Chirino</a>
+ * @author adrian at jboss.org
  */
 public class ClientMonitorInterceptor extends JMSServerInterceptorSupport
 {
-   //The list of ClientConsumers hased by ConnectionTokens
-   HashMap clients = new HashMap();
+   //The list of Clients by ConnectionTokens
+   ConcurrentReaderHashMap clients = new ConcurrentReaderHashMap();
 
    private static class ClientStats
    {
@@ -81,24 +85,37 @@
       }
    }
 
+   /**
+    * Peek the stats. For testing.
+    * 
+    * @param dc the connection token
+    * @return the stats
+    */
+   public ClientStats peekClientStats(ConnectionToken dc)
+   {
+      return (ClientStats) clients.get(dc);
+   }
+
    public ClientStats getClientStats(ConnectionToken dc) throws JMSException
    {
       ClientStats cq = (ClientStats) clients.get(dc);
-      if (cq == null)
+      if (cq != null)
+         return cq;
+
+      // Remove any previous token with a null client id and remove it
+      if (dc.getClientID() != null)
       {
-         cq = new ClientStats();
+         ConnectionToken withoutID = new ConnectionToken(null, dc.clientIL, dc.getSessionId());
+         clients.remove(withoutID);
+      }
 
-         // The JVM clientil does not ping.
-         if (dc.clientIL instanceof JVMClientIL)
-            cq.disconnectIfInactive = false;
+      cq = new ClientStats();
 
-         synchronized (clients)
-         {
-            HashMap m = new HashMap(clients);
-            m.put(dc, cq);
-            clients = m;
-         }
-      }
+      // The JVM clientil does not ping.
+      if (dc.clientIL instanceof JVMClientIL)
+         cq.disconnectIfInactive = false;
+
+      clients.put(dc, cq);
       return cq;
    }
 
@@ -116,12 +133,7 @@
 
    public void connectionClosing(ConnectionToken dc) throws JMSException
    {
-      synchronized (clients)
-      {
-         HashMap m = new HashMap(clients);
-         m.remove(dc);
-         clients = m;
-      }
+      clients.remove(dc);
       getNext().connectionClosing(dc);
    }
 




More information about the jboss-cvs-commits mailing list