Skip to content

Commit

Permalink
ZOOKEEPER-1871: Removed statement which was re-creating zookeeper adm…
Browse files Browse the repository at this point in the history
…in in ZooKeeperMain.java and added documentation for waitforconnection in zookeeperCLI.md and
  • Loading branch information
MuktiKrishnan committed Mar 10, 2021
1 parent c475d46 commit 2947514
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 2 additions & 0 deletions zookeeper-docs/src/main/resources/markdown/zookeeperCLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Enter into the ZooKeeper-cli
bin/zkCli.sh
# connect to the remote host with timeout:3s
bin/zkCli.sh -timeout 3000 -server remoteIP:2181
# connect to the remote host with -waitforconnection option to wait for connection success before executing commands
bin/zkCli.sh -waitforconnection -timeout 3000 -server remoteIP:2181
# connect with a custom client configuration properties file
bin/zkCli.sh -client-configuration /path/to/client.properties
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void process(WatchedEvent event) {
if (connectLatch != null) {
// connection success
if (event.getType() == Event.EventType.None
&& event.getState() == Event.KeeperState.SyncConnected) {
&& event.getState() == Event.KeeperState.SyncConnected) {
connectLatch.countDown();
}
}
Expand Down Expand Up @@ -261,17 +261,6 @@ protected void connectToZK(String newHost) throws InterruptedException, IOExcept
System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
System.out.println("Secure connection is enabled");
}
if (cl.getOption("waitforconnection") != null) {
connectLatch = new CountDownLatch(1);
}
int timeout = Integer.parseInt(cl.getOption("timeout"));
zk = new ZooKeeperAdmin(host, timeout, new MyWatcher(), readOnly);
if (connectLatch != null) {
if (!connectLatch.await(timeout, TimeUnit.MILLISECONDS)) {
zk.close();
throw new IOException(KeeperException.create(KeeperException.Code.CONNECTIONLOSS));
}
}

ZKClientConfig clientConfig = null;

Expand All @@ -284,7 +273,19 @@ protected void connectToZK(String newHost) throws InterruptedException, IOExcept
}
}

zk = new ZooKeeperAdmin(host, Integer.parseInt(cl.getOption("timeout")), new MyWatcher(), readOnly, clientConfig);
if (cl.getOption("waitforconnection") != null) {
connectLatch = new CountDownLatch(1);
}

int timeout = Integer.parseInt(cl.getOption("timeout"));
zk = new ZooKeeperAdmin(host, timeout, new MyWatcher(), readOnly, clientConfig);
if (connectLatch != null) {
if (!connectLatch.await(timeout, TimeUnit.MILLISECONDS)) {
zk.close();
throw new IOException(KeeperException.create(KeeperException.Code.CONNECTIONLOSS));
}
}

}

public static void main(String[] args) throws IOException, InterruptedException {
Expand Down

0 comments on commit 2947514

Please sign in to comment.