/** * Kill the given ZK session * * @param client the client to kill * @param connectString server connection string * @param maxMs max time ms to wait for kill * @throws Exception errors */ public static void kill(ZooKeeper client, String connectString, int maxMs) { // long startTicks = DateTime.Now.Ticks / 1000; // Barrier sessionLostLatch = new Barrier(2); // Watcher sessionLostWatch = new BarrierWatcher(sessionLostLatch); // client.existsAsync("/___CURATOR_KILL_SESSION___" + DateTime.Now.Ticks, // sessionLostWatch) // .Wait(); Barrier connectionLatch = new Barrier(2); Watcher connectionWatcher = new SyncWatcher(connectionLatch); ZooKeeper zk = new ZooKeeper(connectString, maxMs, connectionWatcher, client.getSessionId(), client.getSessionPasswd()); try { if (!connectionLatch.SignalAndWait(maxMs)) { throw new Exception("KillSession could not establish duplicate session"); } try { zk.closeAsync().Wait(); } finally { zk = null; } // while ( client.getState() == ZooKeeper.States.CONNECTED // && !sessionLostLatch.SignalAndWait(100) ) // { // long elapsed = (DateTime.Now.Ticks / 1000) - startTicks; // if ( elapsed > maxMs ) // { // throw new Exception("KillSession timed out waiting for session to expire"); // } // } } finally { zk?.closeAsync().Wait(); } }
/** * Kill the given ZK session * * @param client the client to kill * @param connectString server connection string * @param maxMs max time ms to wait for kill * @throws Exception errors */ public static void kill(ZooKeeper client, String connectString, int maxMs) { // long startTicks = DateTime.Now.Ticks / 1000; // Barrier sessionLostLatch = new Barrier(2); // Watcher sessionLostWatch = new BarrierWatcher(sessionLostLatch); // client.existsAsync("/___CURATOR_KILL_SESSION___" + DateTime.Now.Ticks, // sessionLostWatch) // .Wait(); Barrier connectionLatch = new Barrier(2); Watcher connectionWatcher = new SyncWatcher(connectionLatch); ZooKeeper zk = new ZooKeeper(connectString, maxMs, connectionWatcher, client.getSessionId(), client.getSessionPasswd()); try { if ( !connectionLatch.SignalAndWait(maxMs) ) { throw new Exception("KillSession could not establish duplicate session"); } try { zk.closeAsync().Wait(); } finally { zk = null; } // while ( client.getState() == ZooKeeper.States.CONNECTED // && !sessionLostLatch.SignalAndWait(100) ) // { // long elapsed = (DateTime.Now.Ticks / 1000) - startTicks; // if ( elapsed > maxMs ) // { // throw new Exception("KillSession timed out waiting for session to expire"); // } // } } finally { zk?.closeAsync().Wait(); } }