/// <summary> /// Deletes a znode /// </summary> public void Delete() { _path = GetPath(_input1); try { IEnumerable <String> children = Zk.GetChildren(_path, false); foreach (var child in children) { Zk.Delete(_path + "/" + child, -1); } Zk.Delete(_path, -1); AppendLineShow(String.Format("Znode {0} was deleted successfully\n", _input1)); } catch (KeeperException.NoNodeException e) { AppendLineShow(String.Format("Znode {0} does not exist!", _input1)); } catch (InvalidOperationException e) { AppendLineShow(string.Format("Znode {0} isn't valid!", _input1)); } catch (Exception e) { AppendLineShow("Exception " + e); } }
public void WaitAtomicAction() { // 等待数据库等操作完成 while (true) { if (Zk.GetChildren(_root, false).Count() == 1) { break; } Thread.Sleep(1); } }
public List <string> GetChildren(string path, bool watch) { List <string> children = null; try { children = Zk.GetChildren(path, watch).ToList(); } catch (Exception e) { log.Error(String.Format("An error occured while trying to get children. Exception: {0}", e.ToString())); } return(children); }
public void Listen() { const string pdfPath = "/PDFConverter"; try { Zk.GetChildren(pdfPath, true); AppendLineShow(string.Format("A watch on {0}'s children has been placed.", pdfPath)); } catch (KeeperException.NoNodeException e) { AppendLineShow(String.Format("Znode {0} does not exist!", _input1)); } catch (InvalidOperationException e) { AppendLineShow(string.Format("Znode {0} isn't valid!", _input1)); } }
/// <summary> /// Lists the znodes /// </summary> public void List() { _path = GetPath(_input1); try { var children = Zk.GetChildren(_path, false); IEnumerable <string> enumerable = children as string[] ?? children.ToArray(); if (enumerable.IsEmpty()) { AppendLineShow("No members in znode: " + _input1); } else { AppendLineShow("\n======= Z ======="); foreach (var child in enumerable) { Output.Append(child + " "); } AppendLineShow("\n"); } } catch (KeeperException.NoNodeException e) { AppendLineShow("Znode does not exist!"); } catch (KeeperException.SessionExpiredException e) { AppendLineShow("The session expired!"); } catch (InvalidOperationException e) { AppendLineShow("Too many '/'!"); } }