public void Connect(IWatcher watcher) { _watcher = watcher; if (failOnConnect) { // As as example: throw new Exception("Testing connection failure"); } Task.Factory.StartNew(() => { _watcher.Process(new WatchedEvent(KeeperState.SyncConnected, EventType.None, null)); }); }
private void Run() { try { while (!tokenSource.IsCancellationRequested) { _watcher.Process(_blockingQueue.Take()); } } catch { // stop event thread } }
public void Process(WatchedEvent watchedEvent) { String path = watchedEvent.Path; if (watchedEvent.Type == EventType.None) { // We are are being told that the state of the // connection has changed switch (watchedEvent.State) { case KeeperState.SyncConnected: // In this particular example we don't need to do anything // here - watches are automatically re-registered with // server and any watches triggered while the client was // disconnected will be delivered (in order of course) break; case KeeperState.Expired: // It's all over dead = true; listener.Closing((int)KeeperException.Code.SESSIONEXPIRED); break; } } else { if (path != null && path == znode) { // Something has changed on the node, let's find out zk.Exists(znode, true); } } if (chainedWatcher != null) { chainedWatcher.Process(watchedEvent); } }