/** * 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(IZooKeeper client, String connectString, int maxMs) { System.Diagnostics.Debug.WriteLine("Kill Start"); long startTicks = (long)TimeSpan.FromTicks(System.DateTime.Now.Ticks).TotalMilliseconds; var sessionLostLatch = new AutoResetEvent(false); IWatcher sessionLostWatch = new CuratorWatcher((e) => { if (e.State == KeeperState.Expired) { sessionLostLatch.Set(); } }); client.Exists("/___CURATOR_KILL_SESSION___" + System.DateTime.Now.Ticks, sessionLostWatch); var connectionLatch = new AutoResetEvent(false); var connectionWatcher = new CuratorWatcher((e) => { if (e.State == KeeperState.SyncConnected) { connectionLatch.Set(); } }); IZooKeeper zk = new ZooKeeper(connectString, TimeSpan.FromMilliseconds(maxMs), connectionWatcher, client.SessionId, client.SesionPassword); try { if (!connectionLatch.WaitOne(maxMs)) { throw new Exception("KillSession could not establish duplicate session"); } try { zk.Dispose(); } finally { zk = null; } while (client.State.IsAlive() && !sessionLostLatch.WaitOne(100)) { long elapsed = (long)TimeSpan.FromTicks(System.DateTime.Now.Ticks).TotalMilliseconds - startTicks; if (elapsed > maxMs) { throw new Exception("KillSession timed out waiting for session to expire"); } } } finally { if (zk != null) { zk.Dispose(); } } System.Diagnostics.Debug.WriteLine("Kill End"); }
public void SessionTermination() { var latch = new AutoResetEvent(false); var sxl = new AutoResetEvent(false); var conlatch = new AutoResetEvent(false); var w1 = new CuratorWatcher((e) => { if (e.State == KeeperState.SyncConnected) { latch.Set(); } else if (e.State == KeeperState.Expired) { sxl.Set(); } }); var zookeeper = new ZooKeeper(connectionString, TimeSpan.FromMilliseconds(10000), w1); latch.WaitOne(5000); using (var zk = new ZooKeeper(connectionString, TimeSpan.FromMilliseconds(2000), new CuratorWatcher((e) => { if (e.State == KeeperState.SyncConnected) { conlatch.Set(); } }), zookeeper.SessionId, zookeeper.SesionPassword)) { if (!conlatch.WaitOne(5000)) { Assert.Fail(); } }; if (!sxl.WaitOne(20000)) { Assert.Fail(); } try{ var stat = zookeeper.Exists("/test", false); if (stat == null) { System.Diagnostics.Debug.WriteLine("Node does not exits"); } } catch (KeeperException e) { System.Diagnostics.Debug.WriteLine("Session Expired"); } }
public void TestExpiredSession() { var timing = new Timing(); var latch = new AutoResetEvent(false); var watcher = new CuratorWatcher((e) => { if (e.State == KeeperState.Expired) { latch.Set(); } }); using (var client = new CuratorZookeeperClient(server.GetConnectionString(), timing.session(), timing.connection(), watcher, new RetryOneTime(TimeSpan.FromMilliseconds(2)))) { client.Start(); bool firstTime = true; RetryLoop.CallWithRetry <bool>(client, () => { if (firstTime) { try { var stat = client.GetZooKeeper().Exists("/foo", false); if (stat == null) { client.GetZooKeeper().Create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.Persistent); } } catch (KeeperException.NodeExistsException ignore) { } KillSession.kill(client.GetZooKeeper(), server.GetConnectionString()); Assert.IsFalse(timing.awaitLatch(latch)); } IZooKeeper zooKeeper = client.GetZooKeeper(); client.BlockUntilConnectedOrTimedOut(); Assert.IsNotNull(zooKeeper.Exists("/foo", false)); return(true); }); } }
Watching(CuratorFrameworkImpl client, CuratorWatcher watcher) { this.watcher = (watcher != null) ? client.getNamespaceWatcherMap().getNamespaceWatcher(watcher) : null; this.watched = false; }
public IPathable <List <String> > usingWatcher(CuratorWatcher watcher) { _getChildrenBuilderImpl.usingWatcher(watcher); return(_getChildrenBuilderImpl); }
public IBackgroundPathable <List <String> > usingWatcher(CuratorWatcher watcher) { watching = new Watching(client, watcher); return(this); }
public IBackgroundPathable <byte[]> usingWatcher(CuratorWatcher watcher) { return(_getDataBuilderImpl.usingWatcher(watcher)); }
public IPathable <byte[]> usingWatcher(CuratorWatcher watcher) { _getDataBuilderImpl.usingWatcher(watcher); return(_getDataBuilderImpl); }
internal NamespaceWatcher getNamespaceWatcher(CuratorWatcher watcher) { return get(watcher, new NamespaceWatcher(client, watcher)); }
public void Dispose() { client = null; actualWatcher = null; curatorWatcher = null; }
internal NamespaceWatcher(CuratorFrameworkImpl client, CuratorWatcher curatorWatcher) { this.client = client; this.actualWatcher = null; this.curatorWatcher = curatorWatcher; }
internal NamespaceWatcher getNamespaceWatcher(CuratorWatcher watcher) { return(get(watcher, new NamespaceWatcher(client, watcher))); }