Class TraceNode

java.lang.Object
com.yahoo.messagebus.TraceNode
All Implemented Interfaces:
Comparable<TraceNode>

public class TraceNode extends Object implements 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 Details

    • TraceNode

      public TraceNode()
      Create an empty trace tree.
  • Method Details

    • swap

      public TraceNode swap(TraceNode other)
      Swap the internals of this tree with another.
      Parameters:
      other - The tree to swap internals with.
      Returns:
      This, to allow chaining.
    • clear

      public TraceNode clear()
      Remove all trace information from this tree.
      Returns:
      This, to allow chaining.
    • sort

      public TraceNode sort()
      Sort non-strict children recursively down the tree.
      Returns:
      This, to allow chaining.
    • compareTo

      public int compareTo(TraceNode rhs)
      Specified by:
      compareTo in interface Comparable<TraceNode>
    • compact

      public 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

      public TraceNode 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

      public TraceNode setStrict(boolean strict)
      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

      public String 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

      public TraceNode getChild(int i)
      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

      public TraceNode addChild(String note)
      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

      public TraceNode addChild(TraceNode child)
      Adds a child node to this.
      Parameters:
      child - The child to add.
      Returns:
      This, to allow chaining.
    • addChildren

      public TraceNode addChildren(List<TraceNode> children)
      Adds a list of child nodes to this.
      Parameters:
      children - The children to add.
      Returns:
      This, to allow chaining.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(int limit)
      Generates a non-parseable, human-readable string representation of this trace node.
      Parameters:
      limit - soft limit for maximum string size
      Returns:
      generated string
    • encode

      public String encode()
      Returns a parseable (using decode(String)) string representation of this trace node.
      Returns:
      A string representation of this tree.
    • decode

      public static TraceNode decode(String str)
      Build a trace tree from the given string representation (possibly encoded using encode()).
      Parameters:
      str - The string to parse.
      Returns:
      The corresponding trace tree, or an empty node if parsing failed.