1 /* 2 * Copyright 2016 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.stub; 18 19 import io.grpc.ExperimentalApi; 20 21 import javax.annotation.Nullable; 22 23 /** 24 * A refinement of {@link CallStreamObserver} that allows for lower-level interaction with 25 * client calls. 26 * 27 * <p>Like {@code StreamObserver}, implementations are not required to be thread-safe; if multiple 28 * threads will be writing to an instance concurrently, the application must synchronize its calls. 29 * 30 * <p>DO NOT MOCK: The API is too complex to reliably mock. Use InProcessChannelBuilder to create 31 * "real" RPCs suitable for testing and make a fake for the server-side. 32 */ 33 @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1788") 34 public abstract class ClientCallStreamObserver<V> extends CallStreamObserver<V> { 35 /** 36 * Prevent any further processing for this {@code ClientCallStreamObserver}. No further messages 37 * will be received. The server is informed of cancellations, but may not stop processing the 38 * call. Cancelling an already 39 * {@code cancel()}ed {@code ClientCallStreamObserver} has no effect. 40 * 41 * <p>No other methods on this class can be called after this method has been called. 42 * 43 * <p>It is recommended that at least one of the arguments to be non-{@code null}, to provide 44 * useful debug information. Both argument being null may log warnings and result in suboptimal 45 * performance. Also note that the provided information will not be sent to the server. 46 * 47 * @param message if not {@code null}, will appear as the description of the CANCELLED status 48 * @param cause if not {@code null}, will appear as the cause of the CANCELLED status 49 */ cancel(@ullable String message, @Nullable Throwable cause)50 public abstract void cancel(@Nullable String message, @Nullable Throwable cause); 51 } 52