Class InnerNodeImpl

java.lang.Object
org.apache.hadoop.net.NodeBase
org.apache.hadoop.net.InnerNodeImpl
All Implemented Interfaces:
InnerNode, Node

public class InnerNodeImpl extends NodeBase implements InnerNode
InnerNode represents a switch/router of a data center or rack. Different from a leaf node, it has non-null children.
  • Field Details

    • children

      protected final List<Node> children
    • childrenMap

      protected final Map<String,Node> childrenMap
    • numOfLeaves

      protected int numOfLeaves
  • Constructor Details

    • InnerNodeImpl

      protected InnerNodeImpl(String path)
      Construct an InnerNode from a path-like string.
      Parameters:
      path - input path.
    • InnerNodeImpl

      protected InnerNodeImpl(String name, String location, InnerNode parent, int level)
      Construct an InnerNode from its name, its network location, its parent, and its level.
      Parameters:
      name - input name.
      location - input location.
      parent - input parent.
      level - input level.
  • Method Details

    • getChildren

      public List<Node> getChildren()
      Specified by:
      getChildren in interface InnerNode
      Returns:
      its children
    • getNumOfChildren

      public int getNumOfChildren()
      Specified by:
      getNumOfChildren in interface InnerNode
      Returns:
      the number of children this node has.
    • isRack

      public boolean isRack()
      Judge if this node represents a rack.
      Returns:
      true if it has no child or its children are not InnerNodes
    • isAncestor

      public boolean isAncestor(Node n)
      Judge if this node is an ancestor of node n.
      Parameters:
      n - a node
      Returns:
      true if this node is an ancestor of n
    • isParent

      public boolean isParent(Node n)
      Judge if this node is the parent of node n.
      Parameters:
      n - a node
      Returns:
      true if this node is the parent of n
    • getNextAncestorName

      public String getNextAncestorName(Node n)
    • add

      public boolean add(Node n)
      Description copied from interface: InnerNode
      Add node n to the subtree of this node
      Specified by:
      add in interface InnerNode
      Parameters:
      n - node to be added
      Returns:
      true if the node is added; false otherwise
    • remove

      public boolean remove(Node n)
      Description copied from interface: InnerNode
      Remove node n from the subtree of this node
      Specified by:
      remove in interface InnerNode
      Parameters:
      n - node to be deleted
      Returns:
      true if the node is deleted; false otherwise
    • getLoc

      public Node getLoc(String loc)
      Description copied from interface: InnerNode
      Given a node's string representation, return a reference to the node
      Specified by:
      getLoc in interface InnerNode
      Parameters:
      loc - string location of the form /rack/node
      Returns:
      null if the node is not found or the childnode is there but not an instance of InnerNodeImpl
    • getLeaf

      public Node getLeaf(int leafIndex, Node excludedNode)
      Description copied from interface: InnerNode
      get leafIndex leaf of this subtree if it is not in the excludedNode
      Specified by:
      getLeaf in interface InnerNode
      Parameters:
      leafIndex - an indexed leaf of the node
      excludedNode - an excluded node (can be null)
      Returns:
      the leaf node corresponding to the given index.
    • getNumOfLeaves

      public int getNumOfLeaves()
      Specified by:
      getNumOfLeaves in interface InnerNode
      Returns:
      the number of leave nodes.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class NodeBase
    • equals

      public boolean equals(Object to)
      Overrides:
      equals in class NodeBase