/** * NOTE: this is a BLOCKING method. Rebuild the internal cache for the given node by querying * for all needed data WITHOUT generating any events to send to listeners. * * @param fullPath full path of the node to rebuild * @throws Exception errors */ public void rebuildNode(String fullPath) throws Exception { Preconditions.checkArgument(ZKPaths.getPathAndNode(fullPath).getPath().equals(path), "Node is not part of this cache: " + fullPath); Preconditions.checkState(!executorService.isShutdown(), "cache has been closed"); ensurePath.ensure(client.getZookeeperClient()); internalRebuildNode(fullPath); // this is necessary so that any updates that occurred while rebuilding are taken // have to rebuild entire tree in case this node got deleted in the interim offerOperation(new RefreshOperation(this, RefreshMode.FORCE_GET_DATA_AND_STAT)); }
/** * Given a full path, return the node name and its path. i.e. "/one/two/three" will return {"/one/two", "three"} * * @param path the path * @return the node */ public static PathAndNode getPathAndNode(String path) { PathUtils.validatePath(path); int i = path.lastIndexOf('/'); if ( i < 0 ) { return new PathAndNode(path, ""); } if ( (i + 1) >= path.length() ) { return new PathAndNode("/", ""); } String node = path.substring(i + 1); String parentPath = (i > 0) ? path.substring(0, i) : "/"; return new PathAndNode(parentPath, node); }