• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 The gRPC Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc;
18 
19 import javax.annotation.concurrent.ThreadSafe;
20 
21 /**
22  * Interface for intercepting incoming calls before that are dispatched by
23  * {@link ServerCallHandler}.
24  *
25  * <p>Implementers use this mechanism to add cross-cutting behavior to server-side calls. Common
26  * example of such behavior include:
27  * <ul>
28  * <li>Enforcing valid authentication credentials</li>
29  * <li>Logging and monitoring call behavior</li>
30  * <li>Delegating calls to other servers</li>
31  * </ul>
32  *
33  * <p>The interceptor may be called for multiple {@link ServerCall calls} by one or more threads
34  * without completing the previous ones first. Refer to the
35  * {@link io.grpc.ServerCall.Listener ServerCall.Listener} docs for more details regarding thread
36  * safety of the returned listener.
37  */
38 @ThreadSafe
39 public interface ServerInterceptor {
40   /**
41    * Intercept {@link ServerCall} dispatch by the {@code next} {@link ServerCallHandler}. General
42    * semantics of {@link ServerCallHandler#startCall} apply and the returned
43    * {@link io.grpc.ServerCall.Listener} must not be {@code null}.
44    *
45    * <p>If the implementation throws an exception, {@code call} will be closed with an error.
46    * Implementations must not throw an exception if they started processing that may use {@code
47    * call} on another thread.
48    *
49    * @param call object to receive response messages
50    * @param headers which can contain extra call metadata from {@link ClientCall#start},
51    *                e.g. authentication credentials.
52    * @param next next processor in the interceptor chain
53    * @return listener for processing incoming messages for {@code call}, never {@code null}.
54    */
interceptCall( ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next)55   <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
56       ServerCall<ReqT, RespT> call,
57       Metadata headers,
58       ServerCallHandler<ReqT, RespT> next);
59 }
60