Class RequestContext.ContextScope

java.lang.Object
com.loomcache.server.context.RequestContext.ContextScope
Enclosing class:
RequestContext

public static class RequestContext.ContextScope extends Object
Fluent builder for creating a scoped context.

Usage:

  var context = RequestContext.newScope()
          .correlationId(123L)
          .nodeId("node-1");
  context.run(() -> {
      // context is bound here
      String node = RequestContext.nodeId();
  });
Since:
1.0
  • Constructor Details

    • ContextScope

      public ContextScope()
  • Method Details

    • correlationId

      public RequestContext.ContextScope correlationId(@Nullable Long value)
      Set correlation ID.
      Parameters:
      value - the correlation ID
      Returns:
      this builder for chaining
    • nodeId

      public RequestContext.ContextScope nodeId(@Nullable String value)
      Set node ID.
      Parameters:
      value - the node ID
      Returns:
      this builder for chaining
    • clientAddress

      public RequestContext.ContextScope clientAddress(@Nullable String value)
      Set client address.
      Parameters:
      value - the client address
      Returns:
      this builder for chaining
    • messageType

      public RequestContext.ContextScope messageType(@Nullable String value)
      Set message type.
      Parameters:
      value - the message type
      Returns:
      this builder for chaining
    • clientId

      public RequestContext.ContextScope clientId(@Nullable String value)
      Set client ID.
      Parameters:
      value - the client ID
      Returns:
      this builder for chaining
    • run

      public void run(Runnable runnable)
      Execute a runnable within this scoped context.
      Parameters:
      runnable - the code to execute with context bound
    • call

      public <T> T call(Supplier<T> supplier)
      Execute a supplier within this scoped context and return its result.
      Type Parameters:
      T - the return type
      Parameters:
      supplier - the code to execute with context bound
      Returns:
      the result of the supplier