@Test public void testWaitForClusterComplete() throws Exception { ExecutorService executorService = Executors.newSingleThreadExecutor(); Future<Boolean> result; registryClient.register(SITE_1_HOST_3_CLUSTERS, new InetSocketAddress(1234), URI.create("http: registryClient.register(SITE_1_HOST_2_CLUSTERS, new InetSocketAddress(1235), URI.create("http: Callable<Boolean> awaitCall = () -> registryClient.waitForClusterComplete(1000); result = executorService.submit(awaitCall); assertEquals(result.get(), Boolean.FALSE); result = executorService.submit(awaitCall); registryClient.register(SITE_1_HOST_1_CLUSTER, new InetSocketAddress(1236), URI.create("http: assertEquals(result.get(), Boolean.TRUE); result = executorService.submit(awaitCall); assertEquals(result.get(), Boolean.TRUE); }
@Override public boolean waitForClusterComplete(int timeoutMs) throws IOException { boolean isSleepOnce = false, isComplete = false; long now = System.currentTimeMillis(); long t = now; while (now - t < timeoutMs && !isComplete) { isComplete = true; for (String hostId : getRelatedHostIds()) { Stat stat = checkFileExists(GONDOLA_HOSTS + "/" + hostId); if (stat == null) { if (!isSleepOnce) { isSleepOnce = true; isComplete = false; sleep(RETRY_DELAY_MS); break; } else { return false; } } } t = System.currentTimeMillis(); } return isComplete; }
ZookeeperRegistryClient implements RegistryClient { @Override public boolean waitForClusterComplete(int timeoutMs) throws IOException { boolean isSleepOnce = false, isComplete = false; long now = System.currentTimeMillis(); long t = now; while (now - t < timeoutMs && !isComplete) { isComplete = true; for (String hostId : getRelatedHostIds()) { Stat stat = checkFileExists(GONDOLA_HOSTS + "/" + hostId); if (stat == null) { if (!isSleepOnce) { isSleepOnce = true; isComplete = false; sleep(RETRY_DELAY_MS); break; } else { return false; } } } t = System.currentTimeMillis(); } return isComplete; } }
ZookeeperRegistryClient implements RegistryClient { @Override public boolean waitForClusterComplete(int timeoutMs) throws IOException { boolean isSleepOnce = false, isComplete = false; long now = System.currentTimeMillis(); long t = now; while (now - t < timeoutMs && !isComplete) { isComplete = true; for (String hostId : getRelatedHostIds()) { Stat stat = checkFileExists(GONDOLA_HOSTS + "/" + hostId); if (stat == null) { if (!isSleepOnce) { isSleepOnce = true; isComplete = false; sleep(RETRY_DELAY_MS); break; } else { return false; } } } t = System.currentTimeMillis(); } return isComplete; } protected  ZookeeperRegistryClient(CuratorFramework curatorFramework, ObjectMapper objectMapper, Config config); }
ZookeeperRegistryClient implements RegistryClient { @Override public boolean waitForClusterComplete(int timeoutMs) throws IOException { boolean isSleepOnce = false, isComplete = false; long now = System.currentTimeMillis(); long t = now; while (now - t < timeoutMs && !isComplete) { isComplete = true; for (String hostId : getRelatedHostIds()) { Stat stat = checkFileExists(GONDOLA_HOSTS + "/" + hostId); if (stat == null) { if (!isSleepOnce) { isSleepOnce = true; isComplete = false; sleep(RETRY_DELAY_MS); break; } else { return false; } } } t = System.currentTimeMillis(); } return isComplete; } protected  ZookeeperRegistryClient(CuratorFramework curatorFramework, ObjectMapper objectMapper, Config config); @Override String register(String siteId, InetSocketAddress gondolaAddress, URI serviceUri); @Override void addListener(Consumer<Entry> listener); @Override Map<String, Entry> getEntries(); @Override boolean waitForClusterComplete(int timeoutMs); }
ZookeeperRegistryClient implements RegistryClient { @Override public boolean waitForClusterComplete(int timeoutMs) throws IOException { boolean isSleepOnce = false, isComplete = false; long now = System.currentTimeMillis(); long t = now; while (now - t < timeoutMs && !isComplete) { isComplete = true; for (String hostId : getRelatedHostIds()) { Stat stat = checkFileExists(GONDOLA_HOSTS + "/" + hostId); if (stat == null) { if (!isSleepOnce) { isSleepOnce = true; isComplete = false; sleep(RETRY_DELAY_MS); break; } else { return false; } } } t = System.currentTimeMillis(); } return isComplete; } protected  ZookeeperRegistryClient(CuratorFramework curatorFramework, ObjectMapper objectMapper, Config config); @Override String register(String siteId, InetSocketAddress gondolaAddress, URI serviceUri); @Override void addListener(Consumer<Entry> listener); @Override Map<String, Entry> getEntries(); @Override boolean waitForClusterComplete(int timeoutMs); static final String GONDOLA_HOSTS; }