Class NodeBase

java.lang.Object
org.apache.bookkeeper.net.NodeBase
All Implemented Interfaces:
Node
Direct Known Subclasses:
BookieNode, NetworkTopologyImpl.InnerNode

public class NodeBase extends Object implements Node
A base class that implements interface Node.
  • Field Details

    • PATH_SEPARATOR

      public static final char PATH_SEPARATOR
      Path separator '/'.
      See Also:
    • PATH_SEPARATOR_STR

      public static final String PATH_SEPARATOR_STR
      Path separator as a string "/".
      See Also:
    • ROOT

      public static final String ROOT
      String representation of root "".
      See Also:
    • name

      protected String name
    • location

      protected String location
    • level

      protected int level
    • parent

      protected Node parent
  • Constructor Details

    • NodeBase

      public NodeBase()
      Default constructor.
    • NodeBase

      public NodeBase(String path)
      Construct a node from its path.
      Parameters:
      path - a concatenation of this node's location, the path separator, and its name
    • NodeBase

      public NodeBase(String name, String location)
      Construct a node from its name and its location.
      Parameters:
      name - this node's name (can be null, must not contain PATH_SEPARATOR)
      location - this node's location
    • NodeBase

      public NodeBase(String name, String location, Node parent, int level)
      Construct a node from its name and its location.
      Parameters:
      name - this node's name (can be null, must not contain PATH_SEPARATOR)
      location - this node's location
      parent - this node's parent node
      level - this node's level in the tree
  • Method Details

    • getName

      public String getName()
      Specified by:
      getName in interface Node
      Returns:
      this node's name
    • getNetworkLocation

      public String getNetworkLocation()
      Specified by:
      getNetworkLocation in interface Node
      Returns:
      this node's network location
    • setNetworkLocation

      public void setNetworkLocation(String location)
      Set this node's network location.
      Specified by:
      setNetworkLocation in interface Node
      Parameters:
      location - the location
    • getPath

      public static String getPath(Node node)
      Get the path of a node.
      Parameters:
      node - a non-null node
      Returns:
      the path of a node
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      this node's path as its string representation
    • normalize

      public static String normalize(String path)
      Normalize a path by stripping off any trailing PATH_SEPARATOR.
      Parameters:
      path - path to normalize.
      Returns:
      the normalised path If pathis null or empty ROOT is returned
      Throws:
      IllegalArgumentException - if the first character of a non empty path is not PATH_SEPARATOR
    • getParent

      public Node getParent()
      Specified by:
      getParent in interface Node
      Returns:
      this node's parent
    • setParent

      public void setParent(Node parent)
      Set this node's parent.
      Specified by:
      setParent in interface Node
      Parameters:
      parent - the parent
    • getLevel

      public int getLevel()
      Specified by:
      getLevel in interface Node
      Returns:
      this node's level in the tree. E.g. the root of a tree returns 0 and its children return 1
    • setLevel

      public void setLevel(int level)
      Set this node's level in the tree.
      Specified by:
      setLevel in interface Node
      Parameters:
      level - the level
    • locationToDepth

      public static int locationToDepth(String location)
    • getNetworkLocation

      public String getNetworkLocation(int distanceFromLeaves)
      Specified by:
      getNetworkLocation in interface Node
      Returns:
      the string representation of this node's network location at the specified level in the hierarchy