19 package org.sleuthkit.autopsy.coordinationservice.utils;
21 import java.io.IOException;
22 import org.apache.zookeeper.WatchedEvent;
23 import org.apache.zookeeper.ZooKeeper;
43 public static boolean isZooKeeperAccessible(String hostName, String port)
throws InterruptedException, IOException {
44 boolean result =
false;
45 Object workerThreadWaitNotifyLock =
new Object();
46 String connectString = hostName +
":" + port;
47 ZooKeeper zooKeeper =
new ZooKeeper(connectString, ZOOKEEPER_SESSION_TIMEOUT_MILLIS,
48 (WatchedEvent event) -> {
49 synchronized (workerThreadWaitNotifyLock) {
50 workerThreadWaitNotifyLock.notify();
53 synchronized (workerThreadWaitNotifyLock) {
54 workerThreadWaitNotifyLock.wait(ZOOKEEPER_CONNECTION_TIMEOUT_MILLIS);
56 ZooKeeper.States state = zooKeeper.getState();
57 if (state == ZooKeeper.States.CONNECTED || state == ZooKeeper.States.CONNECTEDREADONLY) {
static final int ZOOKEEPER_SESSION_TIMEOUT_MILLIS
static final int ZOOKEEPER_CONNECTION_TIMEOUT_MILLIS
static boolean isZooKeeperAccessible(String hostName, String port)