You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2009/07/31 22:32:13 UTC
svn commit: r799742 - in /hadoop/zookeeper/branches/branch-3.2: CHANGES.txt
src/java/main/org/apache/zookeeper/ZooKeeperMain.java
Author: phunt
Date: Fri Jul 31 20:32:13 2009
New Revision: 799742
URL: http://svn.apache.org/viewvc?rev=799742&view=rev
Log:
ZOOKEEPER-457. Make ZookeeperMain public, support for HBase (and other) embedded clients
Modified:
hadoop/zookeeper/branches/branch-3.2/CHANGES.txt
hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
Modified: hadoop/zookeeper/branches/branch-3.2/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/CHANGES.txt?rev=799742&r1=799741&r2=799742&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/CHANGES.txt (original)
+++ hadoop/zookeeper/branches/branch-3.2/CHANGES.txt Fri Jul 31 20:32:13 2009
@@ -21,6 +21,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:
NEW FEATURES:
Modified: hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/ZooKeeperMain.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/ZooKeeperMain.java?rev=799742&r1=799741&r2=799742&view=diff
==============================================================================
--- hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/ZooKeeperMain.java (original)
+++ hadoop/zookeeper/branches/branch-3.2/src/java/main/org/apache/zookeeper/ZooKeeperMain.java Fri Jul 31 20:32:13 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,