@VisibleForTesting void reset() throws Exception { setLeadership(false); setNode(null); BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { if (debugResetWaitLatch != null) { debugResetWaitLatch.await(); debugResetWaitLatch = null; } if (event.getResultCode() == KeeperException.Code.OK.intValue()) { setNode(event.getName()); getChildren(); } else { log.error("getChildren() failed. rc = " + event.getResultCode()); } } }; client .create() .creatingParentsIfNeeded() .withProtection() .withMode(CreateMode.EPHEMERAL_SEQUENTIAL) .inBackground(callback) .forPath(ZKPaths.makePath(latchPath, LOCK_NAME), LeaderSelector.getIdBytes(id)); }
private void internalStart() throws Exception { hasLeadership.set(false); if (ourPath != null) { client.delete().guaranteed().inBackground().forPath(ourPath); } ourPath = client .create() .withProtection() .withMode(CreateMode.EPHEMERAL_SEQUENTIAL) .forPath(ZKPaths.makePath(latchPath, LOCK_NAME), LeaderSelector.getIdBytes(id)); checkForLeadership(); }