hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r781914 - in /hadoop/zookeeper/trunk: ./ src/java/main/org/apache/zookeeper/server/ src/java/main/org/apache/zookeeper/server/quorum/
Date Fri, 05 Jun 2009 04:44:23 GMT
Author: breed
Date: Fri Jun  5 04:44:23 2009
New Revision: 781914

URL: http://svn.apache.org/viewvc?rev=781914&view=rev
Log:
ZOOKEEPER-431. Expose methods to ease ZK integration

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=781914&r1=781913&r2=781914&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Fri Jun  5 04:44:23 2009
@@ -185,6 +185,8 @@
   ZOOKEEPER-383. Asynchronous version of createLedger(). (flavio via mahadev)
 
   ZOOKEEPER-358. Throw exception when ledger does not exist. (flavio via breed)
+
+  ZOOKEEPER-431. Expose methods to ease ZK integration. (Jean-Daniel via breed)
  
 NEW FEATURES:
 

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java?rev=781914&r1=781913&r2=781914&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ServerConfig.java Fri
Jun  5 04:44:23 2009
@@ -67,10 +67,18 @@
 
         // let qpconfig parse the file and then pull the stuff we are
         // interested in
-        clientPort = config.getClientPort();
-        dataDir = config.getDataDir();
-        dataLogDir = config.getDataLogDir();
-        tickTime = config.getTickTime();
+        readFrom(config);
+    }
+
+    /**
+     * Read attributes from a QuorumPeerConfig.
+     * @param config
+     */
+    public void readFrom(QuorumPeerConfig config) {
+      clientPort = config.getClientPort();
+      dataDir = config.getDataDir();
+      dataLogDir = config.getDataLogDir();
+      tickTime = config.getTickTime();
     }
 
     public int getClientPort() { return clientPort; }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java?rev=781914&r1=781913&r2=781914&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/ZooKeeperServerMain.java
Fri Jun  5 04:44:23 2009
@@ -82,6 +82,15 @@
             config.parse(args);
         }
 
+        runFromConfig(config);
+    }
+
+    /**
+     * Run from a ServerConfig.
+     * @param config ServerConfig to use.
+     * @throws IOException
+     */
+    public void runFromConfig(ServerConfig config) throws IOException {
         LOG.info("Starting server");
         try {
             // Note that this thread isn't going to be doing anything else,

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java?rev=781914&r1=781913&r2=781914&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerConfig.java
Fri Jun  5 04:44:23 2009
@@ -100,7 +100,13 @@
         }
     }
 
-    protected void parseProperties(Properties zkProp)
+    /**
+     * Parse config from a Properties.
+     * @param zkProp Properties to parse from.
+     * @throws IOException
+     * @throws ConfigException
+     */
+    public void parseProperties(Properties zkProp)
     throws IOException, ConfigException {
         for (Entry<Object, Object> entry : zkProp.entrySet()) {
             String key = entry.getKey().toString().trim();
@@ -263,4 +269,6 @@
     }
 
     public long getServerId() { return serverId; }
+
+    public boolean isDistributed() { return servers.size() > 1; }
 }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java?rev=781914&r1=781913&r2=781914&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
(original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeerMain.java
Fri Jun  5 04:44:23 2009
@@ -99,37 +99,7 @@
         }
 
         if (args.length == 1 && config.servers.size() > 0) {
-            try {
-                ManagedUtil.registerLog4jMBeans();
-            } catch (JMException e) {
-                LOG.warn("Unable to register log4j JMX control", e);
-            }
-
-            LOG.info("Starting quorum peer");
-            try {
-                NIOServerCnxn.Factory cnxnFactory =
-                    new NIOServerCnxn.Factory(config.getClientPort());
-
-                quorumPeer = new QuorumPeer();
-                quorumPeer.setClientPort(config.getClientPort());
-                quorumPeer.setTxnFactory(new FileTxnSnapLog(
-                            new File(config.getDataLogDir()),
-                            new File(config.getDataDir())));
-                quorumPeer.setQuorumPeers(config.getServers());
-                quorumPeer.setElectionType(config.getElectionAlg());
-                quorumPeer.setMyid(config.getServerId());
-                quorumPeer.setTickTime(config.getTickTime());
-                quorumPeer.setInitLimit(config.getInitLimit());
-                quorumPeer.setSyncLimit(config.getSyncLimit());
-                quorumPeer.setQuorumVerifier(config.getQuorumVerifier());
-                quorumPeer.setCnxnFactory(cnxnFactory);
-
-                quorumPeer.start();
-                quorumPeer.join();
-            } catch (InterruptedException e) {
-                // warn, but generally this is ok
-                LOG.warn("Quorum Peer interrupted", e);
-            }
+            runFromConfig(config);
         } else {
             LOG.warn("Either no config or no quorum defined in config, running "
                     + " in standalone mode");
@@ -138,6 +108,40 @@
         }
     }
 
+    public void runFromConfig(QuorumPeerConfig config) throws IOException {
+      try {
+          ManagedUtil.registerLog4jMBeans();
+      } catch (JMException e) {
+          LOG.warn("Unable to register log4j JMX control", e);
+      }
+  
+      LOG.info("Starting quorum peer");
+      try {
+          NIOServerCnxn.Factory cnxnFactory =
+              new NIOServerCnxn.Factory(config.getClientPort());
+  
+          quorumPeer = new QuorumPeer();
+          quorumPeer.setClientPort(config.getClientPort());
+          quorumPeer.setTxnFactory(new FileTxnSnapLog(
+                      new File(config.getDataLogDir()),
+                      new File(config.getDataDir())));
+          quorumPeer.setQuorumPeers(config.getServers());
+          quorumPeer.setElectionType(config.getElectionAlg());
+          quorumPeer.setMyid(config.getServerId());
+          quorumPeer.setTickTime(config.getTickTime());
+          quorumPeer.setInitLimit(config.getInitLimit());
+          quorumPeer.setSyncLimit(config.getSyncLimit());
+          quorumPeer.setQuorumVerifier(config.getQuorumVerifier());
+          quorumPeer.setCnxnFactory(cnxnFactory);
+  
+          quorumPeer.start();
+          quorumPeer.join();
+      } catch (InterruptedException e) {
+          // warn, but generally this is ok
+          LOG.warn("Quorum Peer interrupted", e);
+      }
+    }
+
     protected void shutdown() {
         quorumPeer.shutdown();
     }



Mime
View raw message