cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r933297 - /cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
Date Mon, 12 Apr 2010 16:12:26 GMT
Author: davidb
Date: Mon Apr 12 16:12:26 2010
New Revision: 933297

URL: http://svn.apache.org/viewvc?rev=933297&view=rev
Log:
Change the auto-configure bundle that's used with the TCK to take a currently free port for
the zookeeper server.

Modified:
    cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java

Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java?rev=933297&r1=933296&r2=933297&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server-config/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/config/Activator.java
Mon Apr 12 16:12:26 2010
@@ -18,6 +18,7 @@
 package org.apache.cxf.dosgi.discovery.zookeeper.server.config;
 
 import java.io.IOException;
+import java.net.ServerSocket;
 import java.util.Hashtable;
 
 import org.osgi.framework.BundleActivator;
@@ -29,10 +30,21 @@ import org.osgi.service.cm.ManagedServic
 import org.osgi.util.tracker.ServiceTracker;
 
 public class Activator implements BundleActivator {
+    private static final String ZOOKEEPER_PORT = "org.apache.cxf.dosgi.discovery.zookeeper.pport";
     private static final String PID = "org.apache.cxf.dosgi.discovery.zookeeper.server";
     private ServiceTracker st;
 
     public void start(BundleContext context) throws Exception {
+        synchronized("hi") {
+            // String literals are interned, so this makes sure that only one thread gets
to set the port number
+            if (System.getProperty(ZOOKEEPER_PORT) == null) {
+                String port = getFreePort();
+                System.setProperty(ZOOKEEPER_PORT, port);
+                System.out.println("Set global zookeeper port to: " + port);
+            }
+                
+        }
+        
         st = new ServiceTracker(context, ConfigurationAdmin.class.getName(), null) {
             @Override
             public Object addingService(ServiceReference reference) {
@@ -42,9 +54,10 @@ public class Activator implements Bundle
                         ConfigurationAdmin cadmin = (ConfigurationAdmin) svc;
                         Configuration cfg = cadmin.getConfiguration(PID, null);
                         Hashtable<String, Object> props = new Hashtable<String,
Object>();
-                        props.put("clientPort", 2181);
+                        String zp = System.getProperty(ZOOKEEPER_PORT);
+                        props.put("clientPort", zp);
                         cfg.update(props);
-                        System.out.println("Set zookeeper client port to 2181");
+                        System.out.println("Set zookeeper client port to " + zp);
                     } catch (IOException e) {
                         e.printStackTrace();
                     }
@@ -64,10 +77,23 @@ public class Activator implements Bundle
         ManagedService ms = (ManagedService) svc;
         Hashtable<String, Object> props = new Hashtable<String, Object>();
         props.put("zookeeper.host", "127.0.0.1");
+        props.put("zookeeper.port", System.getProperty(ZOOKEEPER_PORT));
         ms.updated(props);
         System.out.println("Set the zookeeper.host on the Zookeeper Client managed service.");
 	}
     
+    private String getFreePort() {
+        try {
+            ServerSocket ss = new ServerSocket(0);
+            String port = "" + ss.getLocalPort();
+            ss.close();
+            return port;
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }    
+    
 	public void stop(BundleContext context) throws Exception {
 	    st.close();
 	}



Mime
View raw message