@Test public void buildZkTest() { ZkClient client = service.buildZkClient("127.0.0.1:2181", 5000, 5000); Assertions.assertTrue(client.exists("/zookeeper")); }
ZkClient buildZkClient(String address, int sessionTimeout, int connectTimeout) { ZkClient zkClient = new ZkClient(address, sessionTimeout, connectTimeout); if (!zkClient.exists(ROOT_PATH_WITHOUT_SUFFIX)) { zkClient.createPersistent(ROOT_PATH_WITHOUT_SUFFIX, true); } zkClient.subscribeStateChanges(new IZkStateListener() { @Override public void handleStateChanged(Watcher.Event.KeeperState keeperState) throws Exception { } @Override public void handleNewSession() throws Exception { recover(); } @Override public void handleSessionEstablishmentError(Throwable throwable) throws Exception { } }); return zkClient; }
ZookeeperRegisterServiceImpl implements RegistryService<IZkChildListener> { ZkClient buildZkClient(String address, int sessionTimeout, int connectTimeout) { ZkClient zkClient = new ZkClient(address, sessionTimeout, connectTimeout); if (!zkClient.exists(ROOT_PATH_WITHOUT_SUFFIX)) { zkClient.createPersistent(ROOT_PATH_WITHOUT_SUFFIX, true); } zkClient.subscribeStateChanges(new IZkStateListener() { @Override public void handleStateChanged(Watcher.Event.KeeperState keeperState) throws Exception { } @Override public void handleNewSession() throws Exception { recover(); } @Override public void handleSessionEstablishmentError(Throwable throwable) throws Exception { } }); return zkClient; } }
ZookeeperRegisterServiceImpl implements RegistryService<IZkChildListener> { ZkClient buildZkClient(String address, int sessionTimeout, int connectTimeout) { ZkClient zkClient = new ZkClient(address, sessionTimeout, connectTimeout); if (!zkClient.exists(ROOT_PATH_WITHOUT_SUFFIX)) { zkClient.createPersistent(ROOT_PATH_WITHOUT_SUFFIX, true); } zkClient.subscribeStateChanges(new IZkStateListener() { @Override public void handleStateChanged(Watcher.Event.KeeperState keeperState) throws Exception { } @Override public void handleNewSession() throws Exception { recover(); } @Override public void handleSessionEstablishmentError(Throwable throwable) throws Exception { } }); return zkClient; } private  ZookeeperRegisterServiceImpl(); }
ZookeeperRegisterServiceImpl implements RegistryService<IZkChildListener> { ZkClient buildZkClient(String address, int sessionTimeout, int connectTimeout) { ZkClient zkClient = new ZkClient(address, sessionTimeout, connectTimeout); if (!zkClient.exists(ROOT_PATH_WITHOUT_SUFFIX)) { zkClient.createPersistent(ROOT_PATH_WITHOUT_SUFFIX, true); } zkClient.subscribeStateChanges(new IZkStateListener() { @Override public void handleStateChanged(Watcher.Event.KeeperState keeperState) throws Exception { } @Override public void handleNewSession() throws Exception { recover(); } @Override public void handleSessionEstablishmentError(Throwable throwable) throws Exception { } }); return zkClient; } private  ZookeeperRegisterServiceImpl(); @Override void register(InetSocketAddress address); @Override void unregister(InetSocketAddress address); @Override void subscribe(String cluster, IZkChildListener listener); @Override void unsubscribe(String cluster, IZkChildListener listener); @Override List<InetSocketAddress> lookup(String key); @Override void close(); }
ZookeeperRegisterServiceImpl implements RegistryService<IZkChildListener> { ZkClient buildZkClient(String address, int sessionTimeout, int connectTimeout) { ZkClient zkClient = new ZkClient(address, sessionTimeout, connectTimeout); if (!zkClient.exists(ROOT_PATH_WITHOUT_SUFFIX)) { zkClient.createPersistent(ROOT_PATH_WITHOUT_SUFFIX, true); } zkClient.subscribeStateChanges(new IZkStateListener() { @Override public void handleStateChanged(Watcher.Event.KeeperState keeperState) throws Exception { } @Override public void handleNewSession() throws Exception { recover(); } @Override public void handleSessionEstablishmentError(Throwable throwable) throws Exception { } }); return zkClient; } private  ZookeeperRegisterServiceImpl(); @Override void register(InetSocketAddress address); @Override void unregister(InetSocketAddress address); @Override void subscribe(String cluster, IZkChildListener listener); @Override void unsubscribe(String cluster, IZkChildListener listener); @Override List<InetSocketAddress> lookup(String key); @Override void close();  }