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 int
level
protected java.lang.String
location
protected java.lang.String
name
protected Node
parent
static char
PATH_SEPARATOR
Path separator 47.static java.lang.String
PATH_SEPARATOR_STR
Path separator as a string "/".static java.lang.String
ROOT
String 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 int
getLevel()
java.lang.String
getName()
java.lang.String
getNetworkLocation()
java.lang.String
getNetworkLocation(int distanceFromLeaves)
Node
getParent()
static java.lang.String
getPath(Node node)
Get the path of a node.static int
locationToDepth(java.lang.String location)
static java.lang.String
normalize(java.lang.String path)
Normalize a path by stripping off any trailingPATH_SEPARATOR
.void
setLevel(int level)
Set this node's level in the tree.void
setNetworkLocation(java.lang.String location)
Set this node's network location.void
setParent(Node parent)
Set this node's parent.java.lang.String
toString()
-
-
-
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:
getNetworkLocation
in interfaceNode
- Returns:
- this node's network location
-
setNetworkLocation
public void setNetworkLocation(java.lang.String location)
Set this node's network location.- Specified by:
setNetworkLocation
in 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:
toString
in 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
ROOT
is 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:
getNetworkLocation
in interfaceNode
- Returns:
- the string representation of this node's network location at the specified level in the hierarchy
-
-