Package org.apache.bookkeeper.net
Class NodeBase
- java.lang.Object
-
- org.apache.bookkeeper.net.NodeBase
-
- All Implemented Interfaces:
Node
- Direct Known Subclasses:
BookieNode,NetworkTopologyImpl.InnerNode
public class NodeBase extends java.lang.Object implements Node
A base class that implements interface Node.
-
-
Field Summary
Fields Modifier and Type Field Description protected intlevelprotected java.lang.Stringlocationprotected java.lang.Stringnameprotected Nodeparentstatic charPATH_SEPARATORPath separator 47.static java.lang.StringPATH_SEPARATOR_STRPath separator as a string "/".static java.lang.StringROOTString representation of root "".
-
Constructor Summary
Constructors Constructor Description NodeBase()Default constructor.NodeBase(java.lang.String path)Construct a node from its path.NodeBase(java.lang.String name, java.lang.String location)Construct a node from its name and its location.NodeBase(java.lang.String name, java.lang.String location, Node parent, int level)Construct a node from its name and its location.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetLevel()java.lang.StringgetName()java.lang.StringgetNetworkLocation()java.lang.StringgetNetworkLocation(int distanceFromLeaves)NodegetParent()static java.lang.StringgetPath(Node node)Get the path of a node.static intlocationToDepth(java.lang.String location)static java.lang.Stringnormalize(java.lang.String path)Normalize a path by stripping off any trailingPATH_SEPARATOR.voidsetLevel(int level)Set this node's level in the tree.voidsetNetworkLocation(java.lang.String location)Set this node's network location.voidsetParent(Node parent)Set this node's parent.java.lang.StringtoString()
-
-
-
Field Detail
-
PATH_SEPARATOR
public static final char PATH_SEPARATOR
Path separator 47.- See Also:
- Constant Field Values
-
PATH_SEPARATOR_STR
public static final java.lang.String PATH_SEPARATOR_STR
Path separator as a string "/".- See Also:
- Constant Field Values
-
ROOT
public static final java.lang.String ROOT
String representation of root "".- See Also:
- Constant Field Values
-
name
protected java.lang.String name
-
location
protected java.lang.String location
-
level
protected int level
-
parent
protected Node parent
-
-
Constructor Detail
-
NodeBase
public NodeBase()
Default constructor.
-
NodeBase
public NodeBase(java.lang.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(java.lang.String name, java.lang.String location)Construct a node from its name and its location.- Parameters:
name- this node's name (can be null, must not containPATH_SEPARATOR)location- this node's location
-
NodeBase
public NodeBase(java.lang.String name, java.lang.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 containPATH_SEPARATOR)location- this node's locationparent- this node's parent nodelevel- this node's level in the tree
-
-
Method Detail
-
getName
public java.lang.String getName()
-
getNetworkLocation
public java.lang.String getNetworkLocation()
- Specified by:
getNetworkLocationin interfaceNode- Returns:
- this node's network location
-
setNetworkLocation
public void setNetworkLocation(java.lang.String location)
Set this node's network location.- Specified by:
setNetworkLocationin interfaceNode- Parameters:
location- the location
-
getPath
public static java.lang.String getPath(Node node)
Get the path of a node.- Parameters:
node- a non-null node- Returns:
- the path of a node
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- this node's path as its string representation
-
normalize
public static java.lang.String normalize(java.lang.String path)
Normalize a path by stripping off any trailingPATH_SEPARATOR.- Parameters:
path- path to normalize.- Returns:
- the normalised path
If pathis null or empty
ROOTis returned - Throws:
java.lang.IllegalArgumentException- if the first character of a non empty path is notPATH_SEPARATOR
-
getParent
public Node getParent()
-
setParent
public void setParent(Node parent)
Set this node's parent.
-
getLevel
public int getLevel()
-
setLevel
public void setLevel(int level)
Set this node's level in the tree.
-
locationToDepth
public static int locationToDepth(java.lang.String location)
-
getNetworkLocation
public java.lang.String getNetworkLocation(int distanceFromLeaves)
- Specified by:
getNetworkLocationin interfaceNode- Returns:
- the string representation of this node's network location at the specified level in the hierarchy
-
-