Class TraceNode
- java.lang.Object
-
- com.yahoo.yolean.trace.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 eachTraceNode
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 aTraceNode
tree while there are other threads concurrently modifying it, without incurring the cost of memory synchronization. The only caveat being that for eachTraceNode
there can never be more than exactly one writer thread. If multiple threads need to mutate a singleTraceNode
, then the writer threads need to synchronize their access on theTraceNode
.- 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>
Taccept(T visitor)
Visits thisTraceNode
and all of its descendants in depth-first, prefix order.TraceNode
add(TraceNode child)
Adds anotherTraceNode
as a child to this.java.lang.Iterable<TraceNode>
children()
Returns the childTraceNodes
of this.<PAYLOADTYPE>
java.lang.Iterable<PAYLOADTYPE>descendants(java.lang.Class<PAYLOADTYPE> payloadType)
Returns a read-only iterable of allpayloads
that are instances ofpayloadType
, in all its decendants.boolean
isRoot()
Returns whether or not thisTraceNode
is a root node (i.e.TraceNode
parent()
Returns the parentTraceNode
of this.java.lang.Object
payload()
Returns the payload of thisTraceNode
, or null if none.TraceNode
root()
Returns the rootTraceNode
of the tree that thisTraceNode
belongs to.long
timestamp()
Returns the timestamp of thisTraceNode
.java.lang.String
toString()
-
-
-
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
- ifchild
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 ofpayloadType
, in all its decendants. The payload of thisTraceNode
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
ifparent()
returnsnull
-
root
public TraceNode root()
Returns the root
TraceNode
of the tree that thisTraceNode
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 classjava.lang.Object
-
-