[jboss-cvs] JBossAS SVN: r105337 - in trunk: testsuite/src/main/org/jboss/test/jmx/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 28 12:37:26 EDT 2010


Author: smarlow at redhat.com
Date: 2010-05-28 12:37:25 -0400 (Fri, 28 May 2010)
New Revision: 105337

Modified:
   trunk/system/src/main/java/org/jboss/system/server/jmx/JMXAdapter.java
   trunk/testsuite/src/main/org/jboss/test/jmx/test/RMIAdaptorUnitTestCase.java
Log:
JBAS-8049 JmxAdapter should have a closeAll method

Modified: trunk/system/src/main/java/org/jboss/system/server/jmx/JMXAdapter.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/jmx/JMXAdapter.java	2010-05-28 16:33:35 UTC (rev 105336)
+++ trunk/system/src/main/java/org/jboss/system/server/jmx/JMXAdapter.java	2010-05-28 16:37:25 UTC (rev 105337)
@@ -28,6 +28,7 @@
 import javax.naming.Reference;
 import javax.naming.spi.ObjectFactory;
 import java.io.IOException;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
@@ -62,13 +63,7 @@
                jmxc.getConnectionId();
             }
             catch(IOException e) {
-               try {
-                  jmxc.close();  // clean up any local resources associated with the connection (e.g. background threads)  
-               }
-               catch( IOException ignore)
-               {
-
-               }
+               close(jmxc);
                jmxc = null;  // ignore the broken connection and get a new one
             }
          }
@@ -81,4 +76,31 @@
       }
       return null;
    }
+
+   /**
+    * Can be called from the client side application to close all (JMXConnector) connections to the server.
+    * If new connections are obtained while current connections are being closed, the new connections will not
+    * be closed.   
+    */
+   public static void closeAll() {
+      Collection<String> keys = jmxConnectorMap.keySet();
+      Collection<javax.management.remote.JMXConnector> values = jmxConnectorMap.values();
+      for (javax.management.remote.JMXConnector c : values) {
+         close(c);
+      }
+      for (String key : keys) {
+         jmxConnectorMap.remove(key);
+      }
+
+   }
+
+   private static void close(javax.management.remote.JMXConnector jmxc) {
+      try {
+         jmxc.close();  // clean up any local resources associated with the connection (e.g. background threads)
+      }
+      catch( IOException ignore)
+      {
+      }
+   }
+   
 }

Modified: trunk/testsuite/src/main/org/jboss/test/jmx/test/RMIAdaptorUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jmx/test/RMIAdaptorUnitTestCase.java	2010-05-28 16:33:35 UTC (rev 105336)
+++ trunk/testsuite/src/main/org/jboss/test/jmx/test/RMIAdaptorUnitTestCase.java	2010-05-28 16:37:25 UTC (rev 105337)
@@ -75,6 +75,28 @@
       }      
    }
 
+   public void testCloseAll() throws Exception
+   {
+      getLog().debug("+++ testCloseAll");
+
+      InitialContext ctx = getInitialContext();
+      MBeanServerConnection rmiAdaptor = (MBeanServerConnection)ctx.lookup("jmx/invoker/RMIAdaptor");
+
+      // the following should close rmiAdaptor
+      org.jboss.system.server.jmx.JMXAdapter.closeAll();
+
+      // the following should fail due to closed connection being used
+      try {
+         rmiAdaptor.getMBeanCount();
+          super.fail("org.jboss.system.server.jmx.JMXAdapter.closeAll() didn't close the connection");
+      }
+      catch(Exception success) {
+         getLog().debug("+++ testCloseAll succeeded (connection was closed)");
+      }
+
+   }
+
+
    /**
     * This is need to setup the "resource" protocol handler, to cater
     * for the ConfigurationURL attribute with default value "resource:log4j.xml" 




More information about the jboss-cvs-commits mailing list