Class TraceNode


  • public class TraceNode
    extends java.lang.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 ThreadRobustList for its children. That list allows multiple threads to inspect the hierarchy of a TraceNode tree while there are other threads concurrently modifying it, without incurring the cost of memory synchronization. The only caveat being that for each TraceNode there can never be more than exactly one writer thread. If multiple threads need to mutate a single TraceNode, then the writer threads need to synchronize their access on the TraceNode.

    Since:
    5.1.15
    Author:
    Steinar Knutsen, bratseth
    • Constructor Summary

      Constructors 
      Constructor Description
      TraceNode​(java.lang.Object payload, long timestamp)
      Creates a new instance of this class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T extends TraceVisitor>
      T
      accept​(T visitor)
      Visits this TraceNode and all of its descendants in depth-first, prefix order.
      TraceNode add​(TraceNode child)
      Adds another TraceNode as a child to this.
      java.lang.Iterable<TraceNode> children()
      Returns the child TraceNodes of this.
      <PAYLOADTYPE>
      java.lang.Iterable<PAYLOADTYPE>
      descendants​(java.lang.Class<PAYLOADTYPE> payloadType)
      Returns a read-only iterable of all payloads that are instances of payloadType, in all its decendants.
      boolean isRoot()
      Returns whether or not this TraceNode is a root node (i.e.
      TraceNode parent()
      Returns the parent TraceNode of this.
      java.lang.Object payload()
      Returns the payload of this TraceNode, or null if none.
      TraceNode root()
      Returns the root TraceNode of the tree that this TraceNode belongs to.
      long timestamp()
      Returns the timestamp of this TraceNode.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TraceNode

        public TraceNode​(java.lang.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 Detail

      • 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:
        java.lang.IllegalArgumentException - if child is not a root TraceNode
        See Also:
        isRoot()
      • descendants

        public <PAYLOADTYPE> java.lang.Iterable<PAYLOADTYPE> descendants​(java.lang.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 java.lang.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 java.lang.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object