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 to initiate processing of incoming remote calls. Advanced applications and generated 23 * code will implement this interface to allows {@link Server}s to invoke service methods. 24 */ 25 @ThreadSafe 26 public interface ServerCallHandler<RequestT, ResponseT> { 27 /** 28 * Starts asynchronous processing of an incoming call. 29 * 30 * <p>Callers of this method transfer their ownership of the non-thread-safe {@link ServerCall} 31 * and {@link Metadata} arguments to the {@link ServerCallHandler} implementation for processing. 32 * Ownership means that the implementation may invoke methods on {@code call} and {@code headers} 33 * while {@link #startCall} runs and at any time after it returns normally. On the other hand, if 34 * {@link #startCall} throws, ownership of {@code call} and {@code headers} reverts to the caller 35 * and the implementation loses the right to call methods on these objects (from some other 36 * thread, say). 37 * 38 * <p>Ownership also includes the responsibility to eventually close {@code call}. In particular, 39 * if {@link #startCall} throws an exception, the caller must handle it by closing {@code call} 40 * with an error. Since {@code call} can only be closed once, an implementation can report errors 41 * either to {@link ServerCall#close} for itself or by throwing an exception, but not both. 42 * 43 * <p>Returns a non-{@code null} listener for the incoming call. Callers of this method must 44 * arrange for events associated with {@code call} to be delivered there. 45 * 46 * @param call object for responding to the remote client. 47 * @param headers request headers received from the client but open to modification by an owner 48 * @return listener for processing incoming request messages for {@code call} 49 */ startCall( ServerCall<RequestT, ResponseT> call, Metadata headers)50 ServerCall.Listener<RequestT> startCall( 51 ServerCall<RequestT, ResponseT> call, 52 Metadata headers); 53 } 54