Class ClientRequestContext
java.lang.Object
com.loomcache.client.context.ClientRequestContext
Request context propagation for LoomClient using ThreadLocal.
ThreadLocals provide per-thread context propagation compatible with Java 17+. Each thread sees its own isolated copy of the context values.
This class provides client-side context for distributed cache operations: - Request ID: unique identifier for this request (for tracing) - Operation Name: the cache operation being performed (GET, PUT, etc.) - Map Name: the specific map/cache being accessed - Start Timestamp: when the request was initiated (for latency tracking)
Usage with try-with-resources
var context = ClientRequestContext.newScope()
.requestId("req-12345")
.operationName("GET")
.mapName("user-cache")
.startTimestamp(System.nanoTime());
context.run(() -> {
// Within this block, context is accessible via:
String reqId = ClientRequestContext.requestId();
String op = ClientRequestContext.operationName();
// ... rest of operation ...
});
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFluent builder for constructing scoped context with specific values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisActive()Check if any context is currently set.static @Nullable StringmapName()Get the current map name, or null if not set.newScope()Create a new scope builder for setting context values.static @Nullable StringGet the current operation name, or null if not set.static @Nullable StringGet the current request ID, or null if not set.static @Nullable LongGet the current start timestamp, or null if not set.
-
Constructor Details
-
ClientRequestContext
public ClientRequestContext()
-
-
Method Details
-
requestId
Get the current request ID, or null if not set.- Returns:
- the request ID or null if not set in current scope
-
operationName
Get the current operation name, or null if not set.- Returns:
- the operation name or null if not set in current scope
-
mapName
Get the current map name, or null if not set.- Returns:
- the map name or null if not set in current scope
-
startTimestamp
Get the current start timestamp, or null if not set.- Returns:
- the start timestamp or null if not set in current scope
-
isActive
public static boolean isActive()Check if any context is currently set. -
newScope
Create a new scope builder for setting context values.- Returns:
- a new builder
-