public void createNode(final String path, byte[] data, List<ACL> acl, long ephemeralOwner, int parentCVersion, long zxid, long time, Stat outputStat) throws NoNodeException, NodeExistsException {
int lastSlash = path.lastIndexOf('/');
String parentName = path.substring(0, lastSlash);
String childName = path.substring(lastSlash + 1);
StatPersisted stat = createStat(zxid, time, ephemeralOwner);
This class manages watches. It allows watches to be associated with a string and removes watchers and their watches in addition to managing triggers.
核心字段:
// path -> Watcher集
private final Map<String, Set<Watcher>> watchTable = new HashMap<>();
private final Map<Watcher, Map<String, WatchStats>> watch2Paths = new HashMap<>();
复制代码
WatchStats类
[code]public final class WatchStats { private static final WatchStats[] WATCH_STATS = new WatchStats[] { new WatchStats(0), // NONE new WatchStats(1), // STANDARD new WatchStats(2), // PERSISTENT new WatchStats(3), // STANDARD + PERSISTENT new WatchStats(4), // PERSISTENT_RECURSIVE new WatchStats(5), // STANDARD + PERSISTENT_RECURSIVE new WatchStats(6), // PERSISTENT + PERSISTENT_RECURSIVE new WatchStats(7), // STANDARD + PERSISTENT + PERSISTENT_RECURSIVE }; public static final WatchStats NONE = WATCH_STATS[0]; private final int flags; private WatchStats(int flags) { this.flags = flags; } private static int modeToFlag(WatcherMode mode) { // mode = STANDARD; return 1