Search in sources :

Example 11 with Watcher

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

the class WatchManager method dumpWatches.

/**
     * String representation of watches. Warning, may be large!
     * @param byPath iff true output watches by paths, otw output
     * watches by connection
     * @return string representation of watches
     */
public synchronized void dumpWatches(PrintWriter pwriter, boolean byPath) {
    if (byPath) {
        for (Entry<String, HashSet<Watcher>> e : watchTable.entrySet()) {
            pwriter.println(e.getKey());
            for (Watcher w : e.getValue()) {
                pwriter.print("\t0x");
                pwriter.print(Long.toHexString(((ServerCnxn) w).getSessionId()));
                pwriter.print("\n");
            }
        }
    } else {
        for (Entry<Watcher, HashSet<String>> e : watch2Paths.entrySet()) {
            pwriter.print("0x");
            pwriter.println(Long.toHexString(((ServerCnxn) e.getKey()).getSessionId()));
            for (String path : e.getValue()) {
                pwriter.print("\t");
                pwriter.println(path);
            }
        }
    }
}
Also used : ServerCnxn(org.apache.zookeeper_voltpatches.server.ServerCnxn) Watcher(org.apache.zookeeper_voltpatches.Watcher) HashSet(java.util.HashSet)

Example 12 with Watcher

use of org.apache.zookeeper_voltpatches.Watcher 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

Watcher (org.apache.zookeeper_voltpatches.Watcher)12 WatchedEvent (org.apache.zookeeper_voltpatches.WatchedEvent)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 NoNodeException (org.apache.zookeeper_voltpatches.KeeperException.NoNodeException)3 NodeExistsException (org.apache.zookeeper_voltpatches.KeeperException.NodeExistsException)3 Stat (org.apache.zookeeper_voltpatches.data.Stat)3 JSONException (org.json_voltpatches.JSONException)3 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 BadVersionException (org.apache.zookeeper_voltpatches.KeeperException.BadVersionException)1 DataNode (org.apache.zookeeper_voltpatches.server.DataNode)1 ServerCnxn (org.apache.zookeeper_voltpatches.server.ServerCnxn)1