Class TraceNode

java.lang.Object
com.yahoo.yolean.trace.TraceNode

public class TraceNode extends Object

This class represents a single node in a tree of TraceNodes. The trace forms a tree where there is a branch for each parallel execution, and a node within such a branch for each traced event. As each TraceNode may contain a payload of any type, the trace tree can be used to exchange any thread-safe state between producers and consumers in different threads, whether or not the shape of the trace tree is relevant to the particular information.

This class uses a synchronized list for its children. To avoid contention, each TraceNode should only have one writer thread.

Author:
Steinar Knutsen, bratseth
  • Constructor Details

    • TraceNode

      public TraceNode(Object payload, long timestamp)

      Creates a new instance of this class.

      Parameters:
      payload - the payload to assign to this, may be null
      timestamp - the timestamp to assign to this
  • Method Details

    • add

      public TraceNode add(TraceNode child)

      Adds another TraceNode as a child to this.

      Parameters:
      child - the TraceNode to add
      Returns:
      this, to allow chaining
      Throws:
      IllegalArgumentException - if child is not a root TraceNode
      See Also:
    • descendants

      public <PAYLOADTYPE> Iterable<PAYLOADTYPE> descendants(Class<PAYLOADTYPE> payloadType)

      Returns a read-only iterable of all payloads that are instances of payloadType, in all its decendants. The payload of this TraceNode is ignored.

      The payloads are retrieved in depth-first, prefix order.

      Parameters:
      payloadType - the type of payloads to retrieve
      Returns:
      the payloads, never null
    • payload

      public Object payload()

      Returns the payload of this TraceNode, or null if none.

      Returns:
      the payload
    • timestamp

      public long timestamp()

      Returns the timestamp of this TraceNode.

      Returns:
      the timestamp
    • parent

      public TraceNode parent()

      Returns the parent TraceNode of this.

      Returns:
      the parent
    • children

      public Iterable<TraceNode> children()

      Returns the child TraceNodes of this.

      Returns:
      the children
    • isRoot

      public boolean isRoot()

      Returns whether or not this TraceNode is a root node (i.e. it has no parent).

      Returns:
      true if parent() returns null
    • root

      public TraceNode root()

      Returns the root TraceNode of the tree that this TraceNode belongs to.

      Returns:
      the root
    • accept

      public <T extends TraceVisitor> T accept(T visitor)

      Visits this TraceNode and all of its descendants in depth-first, prefix order.

      Parameters:
      visitor - The visitor to accept.
      Returns:
      The visitor parameter.
    • toString

      public String toString()
      Overrides:
      toString in class Object