Package com.yahoo.messagebus
Class TraceNode
java.lang.Object
com.yahoo.messagebus.TraceNode
- All Implemented Interfaces:
Comparable<TraceNode>
This class contains the actual trace information of a
Trace
object. A trace node can be encoded to, and
decoded from a string representation to allow transport across the network. Each node contains a list of children, a
strictness flag and an optional note. The child list is what forms the trace tree, the strictness flag dictates
whether or not the ordering of the children is important, and the note is the actual traced data.
The most important feature to notice is the normalize()
method that will compact, sort and 'rootify' the
trace tree so that trees become well-formed (and can be compared for equality).- Author:
- Simon Thoresen Hult
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds a child node to this.Convenience method to add a child node containing a note to this.addChildren
(List<TraceNode> children) Adds a list of child nodes to this.clear()
Remove all trace information from this tree.compact()
Compact this tree.int
static TraceNode
Build a trace tree from the given string representation (possibly encoded usingencode()
).encode()
Returns a parseable (usingdecode(String)
) string representation of this trace node.getChild
(int i) Returns the child trace node at the given index.getNote()
Returns the note assigned to this node.int
Returns the number of child nodes of this.boolean
hasNote()
Returns whether or not a note is assigned to this node.boolean
isEmpty()
Check whether or not this node is empty, i.e.boolean
isLeaf()
Check whether or not this is a leaf node.boolean
isRoot()
Check whether or not this is a root node.boolean
isStrict()
Check whether or not the children of this node are strictly ordered.Normalize this tree.setStrict
(boolean strict) Sets whether or not the children of this node are strictly ordered.sort()
Sort non-strict children recursively down the tree.Swap the internals of this tree with another.toString()
toString
(int limit) Generates a non-parseable, human-readable string representation of this trace node.
-
Constructor Details
-
TraceNode
public TraceNode()Create an empty trace tree.
-
-
Method Details
-
swap
Swap the internals of this tree with another.- Parameters:
other
- The tree to swap internals with.- Returns:
- This, to allow chaining.
-
clear
Remove all trace information from this tree.- Returns:
- This, to allow chaining.
-
sort
Sort non-strict children recursively down the tree.- Returns:
- This, to allow chaining.
-
compareTo
- Specified by:
compareTo
in interfaceComparable<TraceNode>
-
compact
Compact this tree. This will reduce the height of this tree as much as possible without removing information stored in it.- Returns:
- This, to allow chaining.
-
normalize
Normalize this tree. This will transform all equivalent trees into the same form. Note that this will also perform an implicit compaction of the tree.- Returns:
- This, to allow chaining.
-
isRoot
public boolean isRoot()Check whether or not this is a root node.- Returns:
- True if this has no parent.
-
isLeaf
public boolean isLeaf()Check whether or not this is a leaf node.- Returns:
- True if this has no children.
-
isEmpty
public boolean isEmpty()Check whether or not this node is empty, i.e. it has no note and no children.- Returns:
- True if this node is empty.
-
isStrict
public boolean isStrict()Check whether or not the children of this node are strictly ordered.- Returns:
- True if this node is strict.
-
setStrict
Sets whether or not the children of this node are strictly ordered.- Parameters:
strict
- True to order children strictly.- Returns:
- This, to allow chaining.
-
hasNote
public boolean hasNote()Returns whether or not a note is assigned to this node.- Returns:
- True if a note is assigned.
-
getNote
Returns the note assigned to this node.- Returns:
- The note.
-
getNumChildren
public int getNumChildren()Returns the number of child nodes of this.- Returns:
- The number of children.
-
getChild
Returns the child trace node at the given index.- Parameters:
i
- The index of the child to return.- Returns:
- The child at the given index.
-
addChild
Convenience method to add a child node containing a note to this.- Parameters:
note
- The note to assign to the child.- Returns:
- This, to allow chaining.
-
addChild
Adds a child node to this.- Parameters:
child
- The child to add.- Returns:
- This, to allow chaining.
-
addChildren
Adds a list of child nodes to this.- Parameters:
children
- The children to add.- Returns:
- This, to allow chaining.
-
toString
-
toString
Generates a non-parseable, human-readable string representation of this trace node.- Parameters:
limit
- soft limit for maximum string size- Returns:
- generated string
-
encode
Returns a parseable (usingdecode(String)
) string representation of this trace node.- Returns:
- A string representation of this tree.
-
decode
Build a trace tree from the given string representation (possibly encoded usingencode()
).- Parameters:
str
- The string to parse.- Returns:
- The corresponding trace tree, or an empty node if parsing failed.
-