private void releaseLock() { try { if (zkClient.getState().equals(CuratorFrameworkState.STARTED)) { // client.setData().forPath(ZOOKEEPER_LOCK_PATH, null); if (zkClient.checkExists().forPath(schedulerId()) != null) { zkClient.delete().guaranteed().deletingChildrenIfNeeded().forPath(schedulerId()); } } } catch (Exception e) { logger.error("error release lock:" + schedulerId()); throw new RuntimeException(e); } }
@Test public void test() throws Exception { TestingServer testingServer = new TestingServer(); CuratorFrameworkFactoryBean fb = new CuratorFrameworkFactoryBean(testingServer.getConnectString()); CuratorFramework client = fb.getObject(); fb.start(); assertTrue(client.getState().equals(CuratorFrameworkState.STARTED)); fb.stop(); assertTrue(client.getState().equals(CuratorFrameworkState.STOPPED)); testingServer.close(); }
public ClusterZKImpl(CuratorFramework zkClient, String clusterName) { this.client = zkClient; this.clusterName = clusterName; if (client.getState().equals(CuratorFrameworkState.LATENT)) { client.start(); } }
public static void init(CuratorFramework curatorFramework) { if (!curatorFramework.getState().equals(CuratorFrameworkState.STARTED)) { curatorFramework.start(); log.info("Curator Framework Client Started. "); } }
@Override public void run() { LOGGER.info("Normal shutdown executing."); curatorManager.unregisterService(); if (curatorFramework != null && (curatorFramework.getState().equals(CuratorFrameworkState.STARTED) || curatorFramework.getState().equals(CuratorFrameworkState.LATENT))) { curatorFramework.close(); } } });
public static CuratorFramework getCuratorFrameworkInstance (String connectString) { CuratorFramework client = clients.get(connectString); if (client == null || !client.getState().equals(CuratorFrameworkState.STARTED)) { CuratorFramework newClient = CuratorFrameworkFactory.newClient(connectString, new RetryForever(1000)); newClient.start(); CuratorFramework origClient = clients.putIfAbsent(connectString, newClient); client = origClient != null ? origClient : newClient; if (origClient != null) { newClient.close(); } } return client; } public static String actionPath(String serviceName, int memberId) {
public void shutdown() { try { if (zookeeper != null) { if (!zookeeper.getState().equals(CuratorFrameworkState.STOPPED)) { zookeeper.close(); } } } catch (Throwable e) { e.printStackTrace(); } finally { try { if (server != null) { server.close(); } } catch (IOException e) { e.printStackTrace(); } finally { FileUtils.deleteQuietly(logDir); } } } }
private void releaseLock() { try { if (zkClient.getState().equals(CuratorFrameworkState.STARTED)) { // client.setData().forPath(ZOOKEEPER_LOCK_PATH, null); if (zkClient.checkExists().forPath(scheduleID) != null) { zkClient.delete().guaranteed().deletingChildrenIfNeeded().forPath(scheduleID); } } } catch (Exception e) { logger.error("error release lock:" + scheduleID); throw new RuntimeException(e); } }
public void destroy() { this.remoteNoticeListener.shutdown(); this.innerPool.destroy(); try { if (this.innerChannel != null && this.innerChannel.isOpen()) { this.innerChannel.close(); } if (this.connection != null && this.connection.isOpen()) { this.connection.close(); } if (zookeeper != null && zookeeper.getState().equals(CuratorFrameworkState.STARTED)) { this.zookeeper.close(); } } catch (IOException e) { logger.error(e); throw new RuntimeException(e); } catch (TimeoutException e) { logger.error(e); throw new RuntimeException(e); } catch (Exception e) { logger.error(e); throw new RuntimeException(e); } }
public synchronized void stop() throws Exception { if (started) { isLeader = false; server.stop(); serverThread.join(); if (gcTsTracker != null) { gcTsTracker.stop(); } started = false; currentLeader = null; if (curatorFramework.getState().equals(CuratorFrameworkState.STARTED)) { pathChildrenCache.getListenable().removeListener(this); pathChildrenCache.close(); leaderLatch.close(); execService.shutdown(); execService.awaitTermination(10, TimeUnit.SECONDS); curatorFramework.getConnectionStateListenable().removeListener(cnxnListener); // leaderLatch.close() schedules a background delete, give it a chance to process before // closing curator... this is done to avoid spurious exceptions, see CURATOR-467 Uninterruptibles.sleepUninterruptibly(250, TimeUnit.MILLISECONDS); curatorFramework.close(); } log.info("Oracle server has been stopped."); } }
public synchronized void stop() throws Exception { if (started) { server.stop(); serverThread.join(); if (gcTsTracker != null) { gcTsTracker.stop(); } started = false; currentLeader = null; if (curatorFramework.getState().equals(CuratorFrameworkState.STARTED)) { pathChildrenCache.getListenable().removeListener(this); pathChildrenCache.close(); leaderSelector.close(); curatorFramework.getConnectionStateListenable().removeListener(this); curatorFramework.close(); } log.info("Oracle server has been stopped."); } }
public synchronized void stop() throws Exception { if (started) { server.stop(); serverThread.join(); if (gcTsTracker != null) { gcTsTracker.stop(); } started = false; currentLeader = null; if (curatorFramework.getState().equals(CuratorFrameworkState.STARTED)) { pathChildrenCache.getListenable().removeListener(this); pathChildrenCache.close(); leaderSelector.close(); curatorFramework.getConnectionStateListenable().removeListener(this); curatorFramework.close(); } log.info("Oracle server has been stopped."); } }
public void registerForTreeNodeEvents(String path, Consumer<TreeCacheEvent> updater) { TreeCache cache = getOrCreateTreeCache(path); if (client.getState().equals(CuratorFrameworkState.STARTED)) { startTreeCache(cache); } cache .getListenable() .addListener( new TreeCacheListener() { @Override public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception { updater.accept(event); } }); }
public void registerUpdater(ConfigurationUpdater updater) { NodeCache cache = getOrCreateNodeCache(updater.getPath()); if (client.getState().equals(CuratorFrameworkState.STARTED)) { startNodeCache(cache); } cache .getListenable() .addListener( new NodeCacheListener() { @Override public void nodeChanged() { updater.update(cache.getCurrentData().getData()); } }); }