Package io.grpc

Class Context.Storage

java.lang.Object
io.grpc.Context.Storage
Enclosing class:
Context

public abstract static class Context.Storage extends Object
Defines the mechanisms for attaching and detaching the "current" context. The constructor for extending classes must not trigger any activity that can use Context, which includes logging, otherwise it can trigger an infinite initialization loop. Extending classes must not assume that only one instance will be created; Context guarantees it will only use one instance, but it may create multiple and then throw away all but one.

The default implementation will put the current context in a ThreadLocal. If an alternative implementation named io.grpc.override.ContextStorageOverride exists in the classpath, it will be used instead of the default implementation.

This API is experimental and subject to change.

  • Constructor Details

    • Storage

      public Storage()
  • Method Details

    • doAttach

      public abstract Context doAttach(Context toAttach)
      Implements Context.attach().

      Caution: Context.attach() interprets a return value of null to mean the same thing as Context.ROOT.

      See also: current().

      Parameters:
      toAttach - the context to be attached
      Returns:
      A Context that should be passed back into detach(Context, Context) as the toRestore parameter. null is a valid return value, but see caution note.
    • detach

      public abstract void detach(Context toDetach, Context toRestore)
      Parameters:
      toDetach - the context to be detached. Should be, or be equivalent to, the current context of the current scope
      toRestore - the context to be the current. Should be, or be equivalent to, the context of the outer scope
    • current

      public abstract Context current()
      Implements Context.current().

      Caution: Context interprets a return value of null to mean the same thing as Context.ROOT.

      See also doAttach(Context).

      Returns:
      The context of the current scope. null is a valid return value, but see caution note.