FELIX-1188
----------
Applied a correcting patch when stopping rmiconnections. 

1. Call stop()
2. If there were pending connections, stop() closes all of them but throws an IOException
3. Catch the exception and call stop() again
4. This time, it should not throw anything and stop successfully




git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@784671 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/mosgi/jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/RmiConnectorActivator.java b/mosgi/jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/RmiConnectorActivator.java
index f053dbd..98e2a23 100644
--- a/mosgi/jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/RmiConnectorActivator.java
+++ b/mosgi/jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/RmiConnectorActivator.java
@@ -37,6 +37,7 @@
 
 import org.apache.felix.mosgi.jmx.registry.mx4j.tools.naming.NamingServiceIfc;  
 
+import java.io.IOException;
 import java.net.InetAddress;
 
 public class RmiConnectorActivator implements BundleActivator, ServiceListener{
@@ -96,7 +97,7 @@
           try{
             this.startRmiConnector();
           }catch (Exception e){
-            e.printStackTrace();
+            this.log(LogService.LOG_ERROR, "cannot start rmi connector", e);
           }
         }
         break;
@@ -104,7 +105,7 @@
         try{
           this.stopRmiConnector();
         }catch (Exception e){
-          e.printStackTrace();
+          this.log(LogService.LOG_ERROR, "cannot stop rmi connector", e);
         }
         break;
     }
@@ -177,7 +178,16 @@
   private void stopRmiConnector() throws Exception {
     RmiConnectorActivator.log(LogService.LOG_INFO, "Stopping JMX Rmi connector "+version,null);
     if (this.connectorServer!=null){
-      this.connectorServer.stop();
+      try {
+        // The first call to stop() will close any open connections, but will
+        // throw an exception if there were open connections.
+        this.connectorServer.stop();
+      }catch(IOException e){
+        // Exception probably thrown because there were open connections. When
+        // this exception is thrown, the server has already attempted to close
+        // all client connections, try stopping again.
+        this.connectorServer.stop();
+      }
       this.connectorServer=null;
     }