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 appli
(
Context context,
ServerCall<ReqT, RespT> call,
Metadata headers,
ServerCallHandler<ReqT, RespT> next)
| 42 | * @return listener that will receive events in the scope of the provided context. |
| 43 | */ |
| 44 | public static <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall( |
| 45 | Context context, |
| 46 | ServerCall<ReqT, RespT> call, |
| 47 | Metadata headers, |
| 48 | ServerCallHandler<ReqT, RespT> next) { |
| 49 | Context previous = context.attach(); |
| 50 | try { |
| 51 | return new ContextualizedServerCallListener<>( |
| 52 | next.startCall(call, headers), |
| 53 | context); |
| 54 | } finally { |
| 55 | context.detach(previous); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Implementation of {@link io.grpc.ForwardingServerCallListener} that attaches a context before |