protected ZooLock(ZooCache zc, IZooReaderWriter zrw, String path) { getLockDataZooCache = zc; this.path = path; zooKeeper = zrw; try { zooKeeper.getStatus(path, this); watchingParent = true; } catch (Exception ex) { log.warn("Error getting setting initial watch on ZooLock", ex); throw new RuntimeException(ex); } }
@Override public synchronized void process(WatchedEvent event) { log.debug("event {} {} {}", event.getPath(), event.getType(), event.getState()); watchingParent = false; if (event.getState() == KeeperState.Expired && lock != null) { lostLock(LockLossReason.SESSION_EXPIRED); } else { try { // set the watch on the parent node again zooKeeper.getStatus(path, this); watchingParent = true; } catch (KeeperException.ConnectionLossException ex) { // we can't look at the lock because we aren't connected, but our session is still good log.warn("lost connection to zookeeper"); } catch (Exception ex) { if (lock != null || asyncLock != null) { lockWatcher.unableToMonitorLockNode(ex); log.error( "Error resetting watch on ZooLock " + lock == null ? asyncLock : lock + " " + event, ex); } } } }
@Override public void process(WatchedEvent event) { synchronized (ZooLock.this) { if (lock != null && event.getType() == EventType.NodeDeleted && event.getPath().equals(path + "/" + lock)) { lostLock(LockLossReason.LOCK_DELETED); } else if (asyncLock != null && event.getType() == EventType.NodeDeleted && event.getPath().equals(path + "/" + asyncLock)) { failedToAcquireLock(); } else if (event.getState() != KeeperState.Disconnected && event.getState() != KeeperState.Expired && (lock != null || asyncLock != null)) { log.debug("Unexpected event watching lock node {} {}", event, asyncLockPath); try { Stat stat2 = zooKeeper.getStatus(asyncLockPath, this); if (stat2 == null) { if (lock != null) lostLock(LockLossReason.LOCK_DELETED); else if (asyncLock != null) failedToAcquireLock(); } } catch (Throwable e) { lockWatcher.unableToMonitorLockNode(e); log.error("Failed to stat lock node " + asyncLockPath, e); } } } } });
log.trace("Renewing watch on {}", lockToWatch); try { Stat restat = zooKeeper.getStatus(lockToWatch, this); if (restat == null) { lockAsync(myLock, lw);
Stat stat = zooKeeper.getStatus(lockToWatch, new Watcher() {
final String asyncLockPath = zooKeeper.putEphemeralSequential(path + "/" + LOCK_PREFIX, data); log.trace("Ephemeral node {} created", asyncLockPath); Stat stat = zooKeeper.getStatus(asyncLockPath, new Watcher() {
private static void childHumanReadable(PrintStream out, String root, String child, int indent) throws KeeperException, InterruptedException { String path = root + "/" + child; if (root.endsWith("/")) path = root + child; Stat stat = zk.getStatus(path); if (stat == null) return; String node = child; if (stat.getEphemeralOwner() != 0) { node = "*" + child + "*"; } if (stat.getDataLength() == 0) { write(out, indent, "%s:", node); } else { write(out, indent, "%s: %s", node, value(path).value); } if (stat.getNumChildren() > 0) { for (String c : zk.getChildren(path, null)) { childHumanReadable(out, path, c, indent + 1); } } } }
if (root.endsWith("/")) path = root + child; Stat stat = zk.getStatus(path); if (stat == null) return;
protected ZooLock(ZooCache zc, IZooReaderWriter zrw, String path) { getLockDataZooCache = zc; this.path = path; zooKeeper = zrw; try { zooKeeper.getStatus(path, this); watchingParent = true; } catch (Exception ex) { log.warn("Error getting setting initial watch on ZooLock", ex); throw new RuntimeException(ex); } }
@Override public synchronized void process(WatchedEvent event) { log.debug("event " + event.getPath() + " " + event.getType() + " " + event.getState()); watchingParent = false; if (event.getState() == KeeperState.Expired && lock != null) { lostLock(LockLossReason.SESSION_EXPIRED); } else { try { // set the watch on the parent node again zooKeeper.getStatus(path, this); watchingParent = true; } catch (KeeperException.ConnectionLossException ex) { // we can't look at the lock because we aren't connected, but our session is still good log.warn("lost connection to zookeeper"); } catch (Exception ex) { if (lock != null || asyncLock != null) { lockWatcher.unableToMonitorLockNode(ex); log.error( "Error resetting watch on ZooLock " + lock == null ? asyncLock : lock + " " + event, ex); } } } }
@Override public void process(WatchedEvent event) { synchronized (ZooLock.this) { if (lock != null && event.getType() == EventType.NodeDeleted && event.getPath().equals(path + "/" + lock)) { lostLock(LockLossReason.LOCK_DELETED); } else if (asyncLock != null && event.getType() == EventType.NodeDeleted && event.getPath().equals(path + "/" + asyncLock)) { failedToAcquireLock(); } else if (event.getState() != KeeperState.Disconnected && event.getState() != KeeperState.Expired && (lock != null || asyncLock != null)) { log.debug("Unexpected event watching lock node " + event + " " + asyncLockPath); try { Stat stat2 = zooKeeper.getStatus(asyncLockPath, this); if (stat2 == null) { if (lock != null) lostLock(LockLossReason.LOCK_DELETED); else if (asyncLock != null) failedToAcquireLock(); } } catch (Throwable e) { lockWatcher.unableToMonitorLockNode(e); log.error("Failed to stat lock node " + asyncLockPath, e); } } } } });
log.trace("Renewing watch on " + lockToWatch); try { Stat restat = zooKeeper.getStatus(lockToWatch, this); if (restat == null) { lockAsync(myLock, lw);
Stat stat = zooKeeper.getStatus(lockToWatch, new Watcher() {
final String asyncLockPath = zooKeeper.putEphemeralSequential(path + "/" + LOCK_PREFIX, data); log.trace("Ephemeral node " + asyncLockPath + " created"); Stat stat = zooKeeper.getStatus(asyncLockPath, new Watcher() {
if (root.endsWith("/")) path = root + child; Stat stat = zk.getStatus(path); if (stat == null) return;
if (root.endsWith("/")) path = root + child; Stat stat = zk.getStatus(path); if (stat == null) return;