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 synchronized list for its children. To avoid contention, each TraceNode should only
have one writer thread.
- Author:
- Steinar Knutsen, bratseth
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends TraceVisitor>
Taccept(T visitor) Visits thisTraceNodeand all of its descendants in depth-first, prefix order.Adds anotherTraceNodeas a child to this.children()Returns the childTraceNodesof this.<PAYLOADTYPE>
Iterable<PAYLOADTYPE>descendants(Class<PAYLOADTYPE> payloadType) Returns a read-only iterable of allpayloadsthat are instances ofpayloadType, in all its decendants.booleanisRoot()Returns whether or not thisTraceNodeis a root node (i.e. it has no parent).parent()Returns the parentTraceNodeof this.payload()Returns the payload of thisTraceNode, or null if none.root()Returns the rootTraceNodeof the tree that thisTraceNodebelongs to.longReturns the timestamp of thisTraceNode.toString()
-
Constructor Details
-
TraceNode
Creates a new instance of this class.
- Parameters:
payload- the payload to assign to this, may benulltimestamp- the timestamp to assign to this
-
-
Method Details
-
add
Adds another
TraceNodeas a child to this.- Parameters:
child- the TraceNode to add- Returns:
- this, to allow chaining
- Throws:
IllegalArgumentException- ifchildis not a root TraceNode- See Also:
-
descendants
Returns a read-only iterable of all
payloadsthat are instances ofpayloadType, in all its decendants. The payload of thisTraceNodeis 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
TraceNodeof this.- Returns:
- the parent
-
children
Returns the child
TraceNodesof this.- Returns:
- the children
-
isRoot
public boolean isRoot()Returns whether or not this
TraceNodeis a root node (i.e. it has no parent).- Returns:
trueifparent()returnsnull
-
root
Returns the root
TraceNodeof the tree that thisTraceNodebelongs to.- Returns:
- the root
-
accept
Visits this
TraceNodeand all of its descendants in depth-first, prefix order.- Parameters:
visitor- The visitor to accept.- Returns:
- The
visitorparameter.
-
toString
-