public synchronized MWStat setData(String path, byte[] data, int version, long time) throws MWZooKeeperException { StringTokenizer st = new StringTokenizer(path, "/"); MWTreeNode cur = root; String str = null; while (st.hasMoreTokens()) { str = st.nextToken(); if (!cur.children.containsKey(str)) { throw new MWZooKeeperException("Pfad " + path + " existiert nicht (" + str + ")!"); } cur = cur.children.get(str); } if (cur.stat.version == version) { cur.data = data; cur.stat.version++; cur.stat.time = time; } else { throw new MWZooKeeperException("Versionsnummern stimmen nicht ueberein!"); } return cur.stat; }
public synchronized String create(String path, byte[] data, long time, long ephemeralOwner) throws MWZooKeeperException { StringTokenizer st = new StringTokenizer(path, "/"); MWTreeNode cur = root; String str = null; while (st.hasMoreTokens()) { str = st.nextToken(); if (cur.children.containsKey(str)) { if (!st.hasMoreTokens()) { throw new MWZooKeeperException("Ordner " + str + " schon vorhanden (" + path + ")!"); } else { cur = cur.children.get(str); } } else if (st.hasMoreTokens()) { throw new MWZooKeeperException( "Ueberordner " + str + " existiert noch nicht (" + path + ")!"); } } MWTreeNode node = new MWTreeNode(data, time); node.ephemeralOwner = ephemeralOwner; cur.children.put(str, node); return path; }