cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1408315 - /cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
Date Mon, 12 Nov 2012 15:17:47 GMT
Author: cschneider
Date: Mon Nov 12 15:17:46 2012
New Revision: 1408315

URL: http://svn.apache.org/viewvc?rev=1408315&view=rev
Log:
DOSGI-141 Applied patch with thanks to Alex Telesh

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

Modified: cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java?rev=1408315&r1=1408314&r2=1408315&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/zookeeper-server/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/server/ZookeeperStarter.java
Mon Nov 12 15:17:46 2012
@@ -31,6 +31,7 @@ import org.apache.zookeeper.server.Serve
 import org.apache.zookeeper.server.ZooKeeperServerMain;
 import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
 import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
+import org.apache.zookeeper.server.quorum.QuorumPeerMain;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.cm.ConfigurationException;
 
@@ -38,7 +39,7 @@ public class ZookeeperStarter implements
     private static final Logger LOG = Logger.getLogger(ZookeeperStarter.class);
 
     private final BundleContext bundleContext;
-    protected MyZooKeeperServerMain main;
+    protected ZookeeperServer main;
     private Thread zkMainThread;
 
     public ZookeeperStarter(BundleContext ctx) {
@@ -125,29 +126,64 @@ public class ZookeeperStarter implements
         return config;
     }
 
-    protected void startFromConfig(QuorumPeerConfig config) throws IOException, InterruptedException
{
-        final ServerConfig serverConfig = new ServerConfig();
-        serverConfig.readFrom(config);
-        
-        main = new MyZooKeeperServerMain();
+    protected void startFromConfig(final QuorumPeerConfig config) throws IOException, InterruptedException
{
+        int numServers = config.getServers().size();
+        if (numServers > 1) {
+            main = new MyQuorumPeerMain(config);
+        } else {
+            main = new MyZooKeeperServerMain(config);
+        }
         zkMainThread = new Thread(new Runnable() {
             public void run() {
                 try {
-                    main.runFromConfig(serverConfig);
+                    main.startup();
                 } catch (Throwable e) {
                     LOG.error("Problem running ZooKeeper server.", e);
-                }                    
-            }                
+                }
+            }
         });
         zkMainThread.start();
     }
+    
+    interface ZookeeperServer {
+            void startup() throws IOException;
+            void shutdown();
+    }
+
+    static class MyQuorumPeerMain extends QuorumPeerMain implements ZookeeperServer {
+        private QuorumPeerConfig config;
+
+        public MyQuorumPeerMain(QuorumPeerConfig config) {
+            this.config = config;
+        }
+
+        public void startup() throws IOException {
+            runFromConfig(config);
+        }
+
+        public void shutdown() {
+            if (null != quorumPeer) {
+                quorumPeer.shutdown();
+            }
+        }
+    }
+
+    static class MyZooKeeperServerMain extends ZooKeeperServerMain implements ZookeeperServer
{
+        private QuorumPeerConfig config;
 
-    // Make the shutdown accessible from here
-    static class MyZooKeeperServerMain extends ZooKeeperServerMain {
-        @Override
-        protected void shutdown() {
+        public MyZooKeeperServerMain(QuorumPeerConfig config) {
+            this.config = config;
+        }
+        
+        public void startup() throws IOException {
+            ServerConfig serverConfig = new ServerConfig();
+            serverConfig.readFrom(config);
+            runFromConfig(serverConfig );
+        }
+
+        public void shutdown() {
             super.shutdown();
-        }        
+        }
     }
 
 }



Mime
View raw message