You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by se...@apache.org on 2010/06/23 15:14:44 UTC

svn commit: r957186 - in /jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client: ClientPool.java OnMessageSubscriber.java Publisher.java ReceiveSubscriber.java

Author: sebb
Date: Wed Jun 23 13:14:43 2010
New Revision: 957186

URL: http://svn.apache.org/viewvc?rev=957186&view=rev
Log:
Simplify ClientPool by using Closeable interface

Modified:
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ClientPool.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
    jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ClientPool.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ClientPool.java?rev=957186&r1=957185&r2=957186&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ClientPool.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ClientPool.java Wed Jun 23 13:14:43 2010
@@ -17,6 +17,8 @@
 
 package org.apache.jmeter.protocol.jms.client;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -34,8 +36,9 @@ import java.util.Map;
 public class ClientPool {
 
     //GuardedBy("this")
-    private static final ArrayList<Object> clients = new ArrayList<Object>();
+    private static final ArrayList<Closeable> clients = new ArrayList<Closeable>();
 
+    //GuardedBy("this")
     private static final Map<Object, Object> client_map = new HashMap<Object, Object>();
 
     /**
@@ -44,27 +47,7 @@ public class ClientPool {
      *
      * @param client
      */
-    public static synchronized void addClient(ReceiveSubscriber client) {
-        clients.add(client);
-    }
-
-    /**
-     * Add a OnMessageClient to the ClientPool. This is so that we can make sure
-     * to close all clients and make sure all threads are destroyed.
-     *
-     * @param client
-     */
-    public static synchronized void addClient(OnMessageSubscriber client) {
-        clients.add(client);
-    }
-
-    /**
-     * Add a Publisher to the ClientPool. This is so that we can make sure to
-     * close all clients and make sure all threads are destroyed.
-     *
-     * @param client
-     */
-    public static synchronized void addClient(Publisher client) {
+    public static synchronized void addClient(Closeable client) {
         clients.add(client);
     }
 
@@ -77,32 +60,21 @@ public class ClientPool {
      * bugs.
      */
     public static synchronized void clearClient() {
-        Iterator<Object> itr = clients.iterator();
+        Iterator<Closeable> itr = clients.iterator();
         while (itr.hasNext()) {
-            Object client = itr.next();
-            if (client instanceof ReceiveSubscriber) {
-                ReceiveSubscriber sub = (ReceiveSubscriber) client;
-                sub.close();
-                sub = null;
-            } else if (client instanceof Publisher) {
-                Publisher pub = (Publisher) client;
-                pub.close();
-                pub = null;
-            } else if (client instanceof OnMessageSubscriber) {
-                OnMessageSubscriber sub = (OnMessageSubscriber) client;
-                sub.close();
-                sub = null;
+            Closeable client = itr.next();
+            try {
+                client.close();
+            } catch (IOException e) {
+                // Ignored
             }
+            client = null;
         }
         clients.clear();
         client_map.clear();
     }
 
-    public static synchronized void put(Object key, OnMessageSubscriber client) {
-        client_map.put(key, client);
-    }
-
-    public static synchronized void put(Object key, Publisher client) {
+    public static synchronized void put(Object key, Object client) {
         client_map.put(key, client);
     }
 

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java?rev=957186&r1=957185&r2=957186&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/OnMessageSubscriber.java Wed Jun 23 13:14:43 2010
@@ -18,6 +18,8 @@
 
 package org.apache.jmeter.protocol.jms.client;
 
+import java.io.Closeable;
+
 import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.jms.Connection;
@@ -40,7 +42,7 @@ import org.apache.log.Logger;
  * end of a test. This is important to make sure there aren't any zombie threads
  * or odd memory leaks.
  */
-public class OnMessageSubscriber {
+public class OnMessageSubscriber implements Closeable {
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
@@ -72,7 +74,6 @@ public class OnMessageSubscriber {
         SESSION = CONN.createSession(false, Session.AUTO_ACKNOWLEDGE);
         Destination dest = Utils.lookupDestination(ctx, destinationName);
         SUBSCRIBER = SESSION.createConsumer(dest);
-        log.info("created the topic connection successfully");
     }
 
     /**

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java?rev=957186&r1=957185&r2=957186&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/Publisher.java Wed Jun 23 13:14:43 2010
@@ -18,6 +18,7 @@
 
 package org.apache.jmeter.protocol.jms.client;
 
+import java.io.Closeable;
 import java.io.Serializable;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -37,7 +38,7 @@ import org.apache.jmeter.protocol.jms.Ut
 import org.apache.jorphan.logging.LoggingManager;
 import org.apache.log.Logger;
 
-public class Publisher {
+public class Publisher implements Closeable {
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
@@ -70,7 +71,6 @@ public class Publisher {
         session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         Destination dest = Utils.lookupDestination(ctx, destinationName);
         producer = session.createProducer(dest);
-        log.info("created the topic connection successfully");
     }
 
     public TextMessage publish(String text) throws JMSException {

Modified: jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java?rev=957186&r1=957185&r2=957186&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java Wed Jun 23 13:14:43 2010
@@ -18,6 +18,7 @@
 
 package org.apache.jmeter.protocol.jms.client;
 
+import java.io.Closeable;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 import javax.jms.Connection;
@@ -48,7 +49,7 @@ import org.apache.log.Logger;
  * Also, messages are received in wait mode, so the RUN flag won't be checked until
  * at least one more message has been received.
 */
-public class ReceiveSubscriber implements Runnable {
+public class ReceiveSubscriber implements Runnable, Closeable {
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org