public static int locationToDepth(String location) { String normalizedLocation = normalize(location); int length = normalizedLocation.length(); int depth = 0; for (int i = 0; i < length; i++) { if (normalizedLocation.charAt(i) == PATH_SEPARATOR) { depth++; } } return depth; } }
/** Construct a node from its name and its location * @param name this node's name (can be null, must not contain {@link #PATH_SEPARATOR}) * @param location this node's location */ public NodeBase(String name, String location) { set(name, normalize(location)); }
/** Construct a node from its name and its location * @param name this node's name (can be null, must not contain {@link #PATH_SEPARATOR}) * @param location this node's location * @param parent this node's parent node * @param level this node's level in the tree */ public NodeBase(String name, String location, Node parent, int level) { set(name, normalize(location)); this.parent = parent; this.level = level; }
/** Given a string representation of a node, return its reference * * @param loc * a path-like string representation of a node * @return a reference to the node; null if the node is not in the tree */ public Node getNode(String loc) { netlock.readLock().lock(); try { loc = NodeBase.normalize(loc); if (!NodeBase.ROOT.equals(loc)) loc = loc.substring(1); return clusterMap.getLoc(loc); } finally { netlock.readLock().unlock(); } }
/** Construct a node from its path * @param path * a concatenation of this node's location, the path separator, and its name */ public NodeBase(String path) { path = normalize(path); int index = path.lastIndexOf(PATH_SEPARATOR); if (index== -1) { set(ROOT, path); } else { set(path.substring(index+1), path.substring(0, index)); } }
/** * Given a string representation of a rack, return its children * @param loc a path-like string representation of a rack * @return a newly allocated list with all the node's children */ public List<Node> getDatanodesInRack(String loc) { netlock.readLock().lock(); try { loc = NodeBase.normalize(loc); if (!NodeBase.ROOT.equals(loc)) { loc = loc.substring(1); } InnerNode rack = (InnerNode) clusterMap.getLoc(loc); if (rack == null) { return null; } return new ArrayList<Node>(rack.getChildren()); } finally { netlock.readLock().unlock(); } }
@Override public String getRack(String loc) { netlock.readLock().lock(); try { loc = NodeBase.normalize(loc); Node locNode = getNode(loc); if (locNode instanceof InnerNodeWithNodeGroup) { InnerNodeWithNodeGroup node = (InnerNodeWithNodeGroup) locNode; if (node.isRack()) { return loc; } else if (node.isNodeGroup()) { return node.getNetworkLocation(); } else { // may be a data center return null; } } else { // not in cluster map, don't handle it return loc; } } finally { netlock.readLock().unlock(); } }
scope=scope.substring(1); scope = NodeBase.normalize(scope); int excludedCountInScope = 0; // the number of nodes in both scope & excludedNodes int excludedCountOffScope = 0; // the number of nodes outside scope & excludedNodes
netlock.readLock().lock(); try { loc = NodeBase.normalize(loc); Node locNode = getNode(loc); if (locNode instanceof InnerNodeWithNodeGroup) {
public static int locationToDepth(String location) { String normalizedLocation = normalize(location); int length = normalizedLocation.length(); int depth = 0; for (int i = 0; i < length; i++) { if (normalizedLocation.charAt(i) == PATH_SEPARATOR) { depth++; } } return depth; } }
public static int locationToDepth(String location) { String normalizedLocation = normalize(location); int length = normalizedLocation.length(); int depth = 0; for (int i = 0; i < length; i++) { if (normalizedLocation.charAt(i) == PATH_SEPARATOR) { depth++; } } return depth; } }
public static int locationToDepth(String location) { String normalizedLocation = normalize(location); int length = normalizedLocation.length(); int depth = 0; for (int i = 0; i < length; i++) { if (normalizedLocation.charAt(i) == PATH_SEPARATOR) { depth++; } } return depth; } }
public static int locationToDepth(String location) { String normalizedLocation = normalize(location); int length = normalizedLocation.length(); int depth = 0; for (int i = 0; i < length; i++) { if (normalizedLocation.charAt(i) == PATH_SEPARATOR) { depth++; } } return depth; } }
/** Construct a node from its name and its location * @param name this node's name (can be null, must not contain {@link #PATH_SEPARATOR}) * @param location this node's location */ public NodeBase(String name, String location) { set(name, normalize(location)); }
/** Construct a node from its name and its location * @param name this node's name (can be null, must not contain {@link #PATH_SEPARATOR}) * @param location this node's location * @param parent this node's parent node * @param level this node's level in the tree */ public NodeBase(String name, String location, Node parent, int level) { set(name, normalize(location)); this.parent = parent; this.level = level; }
/** Construct a node from its name and its location * @param name this node's name * @param location this node's location */ public NodeBase(String name, String location) { set(name, normalize(location)); }
/** Construct a node from its name and its location * @param name this node's name (can be null, must not contain {@link #PATH_SEPARATOR}) * @param location this node's location */ public NodeBase(String name, String location) { set(name, normalize(location)); }
/** Construct a node from its name and its location * @param name this node's name (can be null, must not contain {@link #PATH_SEPARATOR}) * @param location this node's location */ public NodeBase(String name, String location) { set(name, normalize(location)); }
/** Construct a node from its name and its location * @param name this node's name * @param location this node's location * @param parent this node's parent node * @param level this node's level in the tree */ public NodeBase(String name, String location, Node parent, int level) { set(name, normalize(location)); this.parent = parent; this.level = level; }
/** Construct a node from its name and its location * @param name this node's name (can be null, must not contain {@link #PATH_SEPARATOR}) * @param location this node's location * @param parent this node's parent node * @param level this node's level in the tree */ public NodeBase(String name, String location, Node parent, int level) { set(name, normalize(location)); this.parent = parent; this.level = level; }