Class TraceNode
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
-
Method Summary
Modifier and TypeMethodDescription<T extends TraceVisitor>
Taccept
(T visitor) Visits thisTraceNode
and all of its descendants in depth-first, prefix order.Adds anotherTraceNode
as a child to this.children()
Returns the childTraceNodes
of this.<PAYLOADTYPE>
Iterable<PAYLOADTYPE>descendants
(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.parent()
Returns the parentTraceNode
of this.payload()
Returns the payload of thisTraceNode
, or null if none.root()
Returns the rootTraceNode
of the tree that thisTraceNode
belongs to.long
Returns the timestamp of thisTraceNode
.toString()
-
Constructor Details
-
TraceNode
Creates a new instance of this class.
- Parameters:
payload
- the payload to assign to this, may benull
timestamp
- the timestamp to assign to this
-
-
Method Details
-
add
Adds another
TraceNode
as a child to this.- Parameters:
child
- the TraceNode to add- Returns:
- this, to allow chaining
- Throws:
IllegalArgumentException
- ifchild
is not a root TraceNode- See Also:
-
descendants
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
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
Returns the parent
TraceNode
of this.- Returns:
- the parent
-
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
Returns the root
TraceNode
of the tree that thisTraceNode
belongs to.- Returns:
- the root
-
accept
Visits this
TraceNode
and all of its descendants in depth-first, prefix order.- Parameters:
visitor
- The visitor to accept.- Returns:
- The
visitor
parameter.
-
toString
-