Package io.grpc

Class Contexts


  • public final class Contexts
    extends Object
    Utility methods for working with Contexts in GRPC.
    • Method Detail

      • interceptCall

        public static <ReqT,​RespT> ServerCall.Listener<ReqT> interceptCall​(Context context,
                                                                                 ServerCall<ReqT,​RespT> call,
                                                                                 Metadata headers,
                                                                                 ServerCallHandler<ReqT,​RespT> next)
        Make the provided Context Context.current() for the creation of a listener to a received call and for all events received by that listener.

        This utility is expected to be used by ServerInterceptor implementations that need to augment the Context in which the application does work when receiving events from the client.

        Parameters:
        context - to make Context.current().
        call - used to send responses to client.
        headers - received from client.
        next - handler used to create the listener to be wrapped.
        Returns:
        listener that will receive events in the scope of the provided context.
      • statusFromCancelled

        @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1975")
        public static Status statusFromCancelled​(Context context)
        Returns the Status of a cancelled context or null if the context is not cancelled.