Record Class FlowContext
- Record Components:
traceId- a correlation identifier shared by every call in the same chain, generated once when the chain's root method is entereddepth- the zero-based nesting level of the current call within the chain; the root call has depth 0, a call it makes directly has depth 1, and so on
@Logged calls on the same thread.
When a @Logged method calls another @Logged method
directly or indirectly, this context lets an interceptor recognize that
both calls belong to the same logical operation and record their relative
order. Combined with MethodInvocationEvent, this makes it
possible to reconstruct a call chain such as methodA -> methodB ->
methodC in log output, and to see exactly where in that chain a failure
occurred.
This class holds only a correlation identifier and a depth counter; it does not store method arguments, return values, or any other invocation data, consistent with the rest of this library.
Instances are managed per-thread by the interceptor, typically through
a ThreadLocal. This class itself has no thread-affinity logic; it
is a plain, immutable-per-call data holder.
-
Constructor Summary
ConstructorsConstructorDescriptionFlowContext(String traceId, int depth) Creates an instance of aFlowContextrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintdepth()Returns the value of thedepthrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.next()Creates the context for a nested call one level deeper than this one, keeping the sametraceId()so it remains part of the same chain.static FlowContextroot()Creates the root context for a new call chain, deriving the trace id from a single 64-bit random value.final StringtoString()Returns a string representation of this record class.traceId()Returns the value of thetraceIdrecord component.
-
Constructor Details
-
Method Details
-
root
Creates the root context for a new call chain, deriving the trace id from a single 64-bit random value.This identifier only needs to be unique enough to avoid confusing concurrent call chains in log output; it is not a security token. A single value from
ThreadLocalRandomis used deliberately instead ofUUID.randomUUID(), since the latter relies onSecureRandominternally and produces twice the amount of random data than this use case requires.ThreadLocalRandomavoids any shared-state locking, making this call cheap even under high concurrency.- Returns:
- a new root
FlowContext
-
next
Creates the context for a nested call one level deeper than this one, keeping the sametraceId()so it remains part of the same chain.- Returns:
- a new
FlowContextwith the same trace id and depth incremented by one
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
traceId
Returns the value of thetraceIdrecord component.- Returns:
- the value of the
traceIdrecord component
-
depth
public int depth()Returns the value of thedepthrecord component.- Returns:
- the value of the
depthrecord component
-