Search in sources :

Example 11 with WatchedEvent

use of org.apache.zookeeper_voltpatches.WatchedEvent in project voltdb by VoltDB.

the class DataTree method setWatches.

public void setWatches(long relativeZxid, List<String> dataWatches, List<String> existWatches, List<String> childWatches, Watcher watcher) {
    for (String path : dataWatches) {
        DataNode node = getNode(path);
        WatchedEvent e = null;
        if (node == null) {
            e = new WatchedEvent(EventType.NodeDeleted, KeeperState.SyncConnected, path);
        } else if (node.stat.getCzxid() > relativeZxid) {
            e = new WatchedEvent(EventType.NodeCreated, KeeperState.SyncConnected, path);
        } else if (node.stat.getMzxid() > relativeZxid) {
            e = new WatchedEvent(EventType.NodeDataChanged, KeeperState.SyncConnected, path);
        }
        if (e != null) {
            watcher.process(e);
        } else {
            this.dataWatches.addWatch(path, watcher);
        }
    }
    for (String path : existWatches) {
        DataNode node = getNode(path);
        WatchedEvent e = null;
        if (node == null) {
        // This is the case when the watch was registered
        } else if (node.stat.getMzxid() > relativeZxid) {
            e = new WatchedEvent(EventType.NodeDataChanged, KeeperState.SyncConnected, path);
        } else {
            e = new WatchedEvent(EventType.NodeCreated, KeeperState.SyncConnected, path);
        }
        if (e != null) {
            watcher.process(e);
        } else {
            this.dataWatches.addWatch(path, watcher);
        }
    }
    for (String path : childWatches) {
        DataNode node = getNode(path);
        WatchedEvent e = null;
        if (node == null) {
            e = new WatchedEvent(EventType.NodeDeleted, KeeperState.SyncConnected, path);
        } else if (node.stat.getPzxid() > relativeZxid) {
            e = new WatchedEvent(EventType.NodeChildrenChanged, KeeperState.SyncConnected, path);
        }
        if (e != null) {
            watcher.process(e);
        } else {
            this.childWatches.addWatch(path, watcher);
        }
    }
}
Also used : WatchedEvent(org.apache.zookeeper_voltpatches.WatchedEvent) DataNode(org.apache.zookeeper_voltpatches.server.DataNode)

Example 12 with WatchedEvent

use of org.apache.zookeeper_voltpatches.WatchedEvent in project voltdb by VoltDB.

the class WatchManager method triggerWatch.

public Set<Watcher> triggerWatch(String path, EventType type, Set<Watcher> supress) {
    WatchedEvent e = new WatchedEvent(type, KeeperState.SyncConnected, path);
    HashSet<Watcher> watchers;
    synchronized (this) {
        watchers = watchTable.remove(path);
        if (watchers == null || watchers.isEmpty()) {
            if (LOG.isTraceEnabled()) {
                ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, "No watchers for " + path);
            }
            return null;
        }
        for (Watcher w : watchers) {
            HashSet<String> paths = watch2Paths.get(w);
            if (paths != null) {
                paths.remove(path);
            }
        }
    }
    for (Watcher w : watchers) {
        if (supress != null && supress.contains(w)) {
            continue;
        }
        w.process(e);
    }
    return watchers;
}
Also used : WatchedEvent(org.apache.zookeeper_voltpatches.WatchedEvent) Watcher(org.apache.zookeeper_voltpatches.Watcher)

Aggregations

WatchedEvent (org.apache.zookeeper_voltpatches.WatchedEvent)12 Watcher (org.apache.zookeeper_voltpatches.Watcher)10 Semaphore (java.util.concurrent.Semaphore)4 ZooKeeper (org.apache.zookeeper_voltpatches.ZooKeeper)4 ExecutionException (java.util.concurrent.ExecutionException)3 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)3 NodeExistsException (org.apache.zookeeper_voltpatches.KeeperException.NodeExistsException)3 Stat (org.apache.zookeeper_voltpatches.data.Stat)3 JSONException (org.json_voltpatches.JSONException)3 NoNodeException (org.apache.zookeeper_voltpatches.KeeperException.NoNodeException)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 TreeSet (java.util.TreeSet)1 BadVersionException (org.apache.zookeeper_voltpatches.KeeperException.BadVersionException)1 DataNode (org.apache.zookeeper_voltpatches.server.DataNode)1