public void update(final String path, final byte[] bytes) { synchronized (toAnnounce) { if (!started) { // removeParentsIfCreated is not relevant for updates; use dummy value "false". toUpdate.add(new Announceable(path, bytes, false)); return; } } final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); final String parentPath = pathAndNode.getPath(); final String nodePath = pathAndNode.getNode(); ConcurrentMap<String, byte[]> subPaths = announcements.get(parentPath); if (subPaths == null || subPaths.get(nodePath) == null) { throw new ISE("Cannot update a path[%s] that hasn't been announced!", path); } synchronized (toAnnounce) { try { byte[] oldBytes = subPaths.get(nodePath); if (!Arrays.equals(oldBytes, bytes)) { subPaths.put(nodePath, bytes); updateAnnouncement(path, bytes); } } catch (Exception e) { throw Throwables.propagate(e); } } }
synchronized (toAnnounce) { if (started) { byte[] oldBytes = subPaths.putIfAbsent(pathAndNode.getNode(), bytes);
public UsageListing(Exhibitor exhibitor, String startPath, int maxChildren) { if ( startPath.trim().length() == 0 ) { startPath = "/"; } ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(startPath); this.exhibitor = exhibitor; this.startPath = ZKPaths.makePath(pathAndNode.getPath(), pathAndNode.getNode()); this.maxChildren = maxChildren; }
synchronized (toAnnounce) { if (started) { byte[] oldBytes = subPaths.putIfAbsent(pathAndNode.getNode(), bytes);
synchronized (toAnnounce) { if (started) { byte[] oldBytes = subPaths.putIfAbsent(pathAndNode.getNode(), bytes);
synchronized (toAnnounce) { if (started) { byte[] oldBytes = subPaths.putIfAbsent(pathAndNode.getNode(), bytes);
final ChildData child = event.getData(); final ZKPaths.PathAndNode childPath = ZKPaths.getPathAndNode(child.getPath()); final byte[] value = finalSubPaths.get(childPath.getNode()); if (value != null) { log.info("Node[%s] dropped, reinstating.", child.getPath()); log.info("Reinstating [%s]", path); final ZKPaths.PathAndNode split = ZKPaths.getPathAndNode(path); createAnnouncement(path, announcements.get(split.getPath()).get(split.getNode()));
final ChildData child = event.getData(); final ZKPaths.PathAndNode childPath = ZKPaths.getPathAndNode(child.getPath()); final byte[] value = finalSubPaths.get(childPath.getNode()); if (value != null) { log.info("Node[%s] dropped, reinstating.", child.getPath()); log.info("Reinstating [%s]", path); final ZKPaths.PathAndNode split = ZKPaths.getPathAndNode(path); createAnnouncement(path, announcements.get(split.getPath()).get(split.getNode()));
final ChildData child = event.getData(); final ZKPaths.PathAndNode childPath = ZKPaths.getPathAndNode(child.getPath()); final byte[] value = finalSubPaths.get(childPath.getNode()); if (value != null) { log.info("Node[%s] dropped, reinstating.", child.getPath()); log.info("Reinstating [%s]", path); final ZKPaths.PathAndNode split = ZKPaths.getPathAndNode(path); createAnnouncement(path, announcements.get(split.getPath()).get(split.getNode()));
public void update(final String path, final byte[] bytes) { synchronized (toAnnounce) { if (!started) { // removeParentsIfCreated is not relevant for updates; use dummy value "false". toUpdate.add(new Announceable(path, bytes, false)); return; } } final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); final String parentPath = pathAndNode.getPath(); final String nodePath = pathAndNode.getNode(); ConcurrentMap<String, byte[]> subPaths = announcements.get(parentPath); if (subPaths == null || subPaths.get(nodePath) == null) { throw new ISE("Cannot update a path[%s] that hasn't been announced!", path); } synchronized (toAnnounce) { try { byte[] oldBytes = subPaths.get(nodePath); if (!Arrays.equals(oldBytes, bytes)) { subPaths.put(nodePath, bytes); updateAnnouncement(path, bytes); } } catch (Exception e) { throw Throwables.propagate(e); } } }
/** * Unannounces an announcement created at path. Note that if all announcements get removed, the Announcer * will continue to have ZK watches on paths because clearing them out is a source of ugly race conditions. * <p/> * If you need to completely clear all the state of what is being watched and announced, stop() the Announcer. * * @param path */ public void unannounce(String path) { log.info("unannouncing [%s]", path); final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); final String parentPath = pathAndNode.getPath(); final ConcurrentMap<String, byte[]> subPaths = announcements.get(parentPath); if (subPaths == null || subPaths.remove(pathAndNode.getNode()) == null) { log.error("Path[%s] not announced, cannot unannounce.", path); return; } try { curator.delete().guaranteed().forPath(path); } catch (KeeperException.NoNodeException e) { log.info("node[%s] didn't exist anyway...", path); } catch (Exception e) { throw Throwables.propagate(e); } }
/** * Unannounces an announcement created at path. Note that if all announcements get removed, the Announcer * will continue to have ZK watches on paths because clearing them out is a source of ugly race conditions. * <p/> * If you need to completely clear all the state of what is being watched and announced, stop() the Announcer. * * @param path the path to unannounce */ public void unannounce(String path) { log.info("unannouncing [%s]", path); final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); final String parentPath = pathAndNode.getPath(); final ConcurrentMap<String, byte[]> subPaths = announcements.get(parentPath); if (subPaths == null || subPaths.remove(pathAndNode.getNode()) == null) { log.error("Path[%s] not announced, cannot unannounce.", path); return; } try { curator.inTransaction().delete().forPath(path).and().commit(); } catch (KeeperException.NoNodeException e) { log.info("node[%s] didn't exist anyway...", path); } catch (Exception e) { throw Throwables.propagate(e); } }
public void update(final String path, final byte[] bytes) { synchronized (toAnnounce) { if (!started) { // removeParentsIfCreated is not relevant for updates; use dummy value "false". toUpdate.add(new Announceable(path, bytes, false)); return; } } final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); final String parentPath = pathAndNode.getPath(); final String nodePath = pathAndNode.getNode(); ConcurrentMap<String, byte[]> subPaths = announcements.get(parentPath); if (subPaths == null || subPaths.get(nodePath) == null) { throw new ISE("Cannot update a path[%s] that hasn't been announced!", path); } synchronized (toAnnounce) { try { byte[] oldBytes = subPaths.get(nodePath); if (!Arrays.equals(oldBytes, bytes)) { subPaths.put(nodePath, bytes); updateAnnouncement(path, bytes); } } catch (Exception e) { throw Throwables.propagate(e); } } }
public void update(final String path, final byte[] bytes) { synchronized (toAnnounce) { if (!started) { toUpdate.add(Pair.of(path, bytes)); return; } } final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); final String parentPath = pathAndNode.getPath(); final String nodePath = pathAndNode.getNode(); ConcurrentMap<String, byte[]> subPaths = announcements.get(parentPath); if (subPaths == null || subPaths.get(nodePath) == null) { throw new ISE("Cannot update a path[%s] that hasn't been announced!", path); } synchronized (toAnnounce) { try { byte[] oldBytes = subPaths.get(nodePath); if (!Arrays.equals(oldBytes, bytes)) { subPaths.put(nodePath, bytes); updateAnnouncement(path, bytes); } } catch (Exception e) { throw Throwables.propagate(e); } } }
/** * Unannounces an announcement created at path. Note that if all announcements get removed, the Announcer * will continue to have ZK watches on paths because clearing them out is a source of ugly race conditions. * <p/> * If you need to completely clear all the state of what is being watched and announced, stop() the Announcer. * * @param path the path to unannounce */ public void unannounce(String path) { log.info("unannouncing [%s]", path); final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); final String parentPath = pathAndNode.getPath(); final ConcurrentMap<String, byte[]> subPaths = announcements.get(parentPath); if (subPaths == null || subPaths.remove(pathAndNode.getNode()) == null) { log.error("Path[%s] not announced, cannot unannounce.", path); return; } try { curator.inTransaction().delete().forPath(path).and().commit(); } catch (KeeperException.NoNodeException e) { log.info("node[%s] didn't exist anyway...", path); } catch (Exception e) { throw Throwables.propagate(e); } }
@VisibleForTesting String adjustPath(String path) throws Exception { if ( doProtected ) { ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); String name = getProtectedPrefix(protectedId) + pathAndNode.getNode(); path = ZKPaths.makePath(pathAndNode.getPath(), name); } return path; }
public static String getRunIdFromRunPath(String path) { return ZKPaths.getPathAndNode(path).getNode(); }
@VisibleForTesting String adjustPath(String path) throws Exception { if ( doProtected ) { ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); String name = getProtectedPrefix(protectedId) + pathAndNode.getNode(); path = ZKPaths.makePath(pathAndNode.getPath(), name); } return path; }
final ChildData child = event.getData(); final ZKPaths.PathAndNode childPath = ZKPaths.getPathAndNode(child.getPath()); final byte[] value = finalSubPaths.get(childPath.getNode()); if (value != null) { log.info("Node[%s] dropped, reinstating.", child.getPath()); log.info("Reinstating [%s]", path); final ZKPaths.PathAndNode split = ZKPaths.getPathAndNode(path); createAnnouncement(path, announcements.get(split.getPath()).get(split.getNode()));
/** * Unannounces an announcement created at path. Note that if all announcements get removed, the Announcer * will continue to have ZK watches on paths because clearing them out is a source of ugly race conditions. * <p/> * If you need to completely clear all the state of what is being watched and announced, stop() the Announcer. * * @param path the path to unannounce */ public void unannounce(String path) { log.info("unannouncing [%s]", path); final ZKPaths.PathAndNode pathAndNode = ZKPaths.getPathAndNode(path); final String parentPath = pathAndNode.getPath(); final ConcurrentMap<String, byte[]> subPaths = announcements.get(parentPath); if (subPaths == null || subPaths.remove(pathAndNode.getNode()) == null) { log.error("Path[%s] not announced, cannot unannounce.", path); return; } try { curator.inTransaction().delete().forPath(path).and().commit(); } catch (KeeperException.NoNodeException e) { log.info("node[%s] didn't exist anyway...", path); } catch (Exception e) { throw Throwables.propagate(e); } }