hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r799741 - in /hadoop/zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/ZooKeeperMain.java
Date Fri, 31 Jul 2009 20:32:03 GMT
Author: phunt
Date: Fri Jul 31 20:32:02 2009
New Revision: 799741

URL: http://svn.apache.org/viewvc?rev=799741&view=rev
Log:
ZOOKEEPER-457. Make ZookeeperMain public, support for HBase (and other) embedded clients

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=799741&r1=799740&r2=799741&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Fri Jul 31 20:32:02 2009
@@ -24,6 +24,9 @@
 
   ZOOKEEPER-487. setdata on root (/) crashes the servers (mahadev via phunt)
 
+  ZOOKEEPER-457. Make ZookeeperMain public, support for HBase (and other)
+  embedded clients (ryan rawson via phunt)
+
 IMPROVEMENTS:
   ZOOKEEPER-473. cleanup junit tests to eliminate false positives due to
   "socket reuse" and failure to close client (phunt via mahadev)

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java?rev=799741&r1=799740&r2=799741&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeperMain.java Fri Jul 31
20:32:02 2009
@@ -60,7 +60,7 @@
         return printWatches;
     }
 
-    static void populateCommandMap() {
+    static {
         commandMap.put("connect", "host:port");
         commandMap.put("close","");
         commandMap.put("create", "[-s] [-e] path data acl");
@@ -145,12 +145,13 @@
      */
     static private class MyCommandOptions {
 
-        private Map<String,String> options = null;
+        private Map<String,String> options = new HashMap<String,String>();
         private List<String> cmdArgs = null;
         private String command = null;
 
         public MyCommandOptions() {
-            options = null; command = null;
+          options.put("server", "localhost:2181");
+          options.put("timeout", "30000");
         }
 
         public String getOption(String opt) {
@@ -173,13 +174,6 @@
             return cmdArgs.toArray(new String[0]);
         }
 
-        private Map<String,String> buildDefaults( ) {
-            options = new HashMap<String,String>( );
-            options.put("server", "localhost:2181");
-            options.put("timeout", "30000");
-            return options;
-        }
-
         /**
          * Parses a command line that may contain one or more flags
          * before an optional command string
@@ -187,7 +181,6 @@
          * @return true if parsing succeeded, false otherwise.
          */
         public boolean parseOptions(String[] args) {
-            Map<String, String> ret = buildDefaults();
             List<String> argList = Arrays.asList(args);
             Iterator<String> it = argList.iterator();
 
@@ -195,9 +188,9 @@
                 String opt = it.next();
                 try {
                     if (opt.equals("-server")) {
-                        ret.put("server", it.next());
+                        options.put("server", it.next());
                     } else if (opt.equals("-timeout")) {
-                        ret.put("timeout", it.next());
+                        options.put("timeout", it.next());
                     }
                 } catch (NoSuchElementException e){
                     System.err.println("Error: no argument found for option "
@@ -271,7 +264,6 @@
     public static void main(String args[])
         throws KeeperException, IOException, InterruptedException
     {
-        populateCommandMap();
         ZooKeeperMain main = new ZooKeeperMain(args);
         main.run();
     }
@@ -284,6 +276,10 @@
 //                Integer.parseInt(cl.getOption("timeout")), new MyWatcher());
     }
 
+    public ZooKeeperMain(ZooKeeper zk) {
+      this.zk = zk;
+    }
+
     @SuppressWarnings("unchecked")
     void run() throws KeeperException, IOException, InterruptedException {
         if (cl.getCommand() == null) {
@@ -310,12 +306,7 @@
                 String line;
                 Method readLine = consoleC.getMethod("readLine", String.class);
                 while ((line = (String)readLine.invoke(console, getPrompt())) != null) {
-                    if (!line.equals("")) {
-                        cl.parseCommand(line);
-                        addToHistory(commandCount,line);
-                        processCmd(cl);
-                        commandCount++;
-                    }
+                    executeLine(line);
                 }
             } catch (ClassNotFoundException e) {
                 LOG.debug("Unable to start jline", e);
@@ -341,12 +332,7 @@
 
                 String line;
                 while ((line = br.readLine()) != null) {
-                    if (!line.equals("")) {
-                        cl.parseCommand(line);
-                        addToHistory(commandCount,line);
-                        processCmd(cl);
-                        commandCount++;
-                    }
+                    executeLine(line);
                 }
             }
         }
@@ -357,6 +343,16 @@
         }
     }
 
+    public void executeLine(String line)
+    throws InterruptedException, IOException, KeeperException {
+      if (!line.equals("")) {
+        cl.parseCommand(line);
+        addToHistory(commandCount,line);
+        processCmd(cl);
+        commandCount++;
+      }
+    }
+
     private static DataCallback dataCallback = new DataCallback() {
 
         public void processResult(int rc, String path, Object ctx, byte[] data,



Mime
View raw message