import org.apache.helix.manager.zk.ZkClient; //导入方法依赖的package包/类
private static void zkCopy(ZkClient srcClient, String srcRootPath, ZkClient dstClient, String dstRootPath) {
// Strip off tailing "/"
if (!srcRootPath.equals("/") && srcRootPath.endsWith("/")) {
srcRootPath = srcRootPath.substring(0, srcRootPath.length() - 1);
}
if (!dstRootPath.equals("/") && dstRootPath.endsWith("/")) {
dstRootPath = dstRootPath.substring(0, dstRootPath.length() - 1);
}
// Validate paths
PathUtils.validatePath(srcRootPath);
PathUtils.validatePath(dstRootPath);
if (srcRootPath.equals(dstRootPath)) {
logger.info("srcPath == dstPath. Skip copying");
return;
}
if (srcRootPath.startsWith(dstRootPath) || dstRootPath.startsWith(srcRootPath)) {
throw new IllegalArgumentException(
"srcPath/dstPath can't be prefix of dstPath/srcPath, was srcPath: " + srcRootPath
+ ", dstPath: " + dstRootPath);
}
// Recursive copy using BFS
List queue = new LinkedList();
String root = "";
copy(srcClient, srcRootPath, dstClient, dstRootPath, Arrays.asList(root));
queue.add(root);
while (!queue.isEmpty()) {
String path = queue.remove(0);
String fromPath = concatenate(srcRootPath, path);
List children = srcClient.getChildren(fromPath);
List paths = new ArrayList();
if (children != null && children.size() > 0) {
for (String child : children) {
String childPath = concatenate(path, child);
paths.add(childPath);
}
copy(srcClient, srcRootPath, dstClient, dstRootPath, paths);
queue.addAll(paths);
}
}
}