private bool TryTakeInternal(int wait, out byte[] data) { data = null; SortedDictionary <long, string> orderedChildren; while (true) { ResetChildWatcher childWatcher = new ResetChildWatcher(); try { orderedChildren = OrderedChildren(childWatcher); } catch (KeeperException.NoNodeException) { zookeeper.Create(dir, new byte[0], acl, CreateMode.Persistent); continue; } if (orderedChildren.Count == 0) { if (!childWatcher.WaitOne(wait)) { return(false); } continue; } foreach (string path in orderedChildren.Values.Select(headNode => dir.Combine(headNode))) { try { data = zookeeper.GetData(path, false, null); zookeeper.Delete(path, -1); return(true); } catch (KeeperException.NoNodeException) { // Another client deleted the node first. } } } }
private bool TryTakeInternal(int wait, out byte[] data) { data = null; SortedDictionary<long, string> orderedChildren; while (true) { ResetChildWatcher childWatcher = new ResetChildWatcher(); try { orderedChildren = OrderedChildren(childWatcher); } catch (KeeperException.NoNodeException e) { zookeeper.Create(dir, new byte[0], acl, CreateMode.Persistent); continue; } if (orderedChildren.Count == 0) { if (!childWatcher.WaitOne(wait)) return false; continue; } foreach (string path in orderedChildren.Values.Select(headNode => dir.Combine(headNode))) { try { data = zookeeper.GetData(path, false, null); zookeeper.Delete(path, -1); return true; } catch (KeeperException.NoNodeException e) { // Another client deleted the node first. } } } }