• 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.internal;
18 
19 import io.grpc.Metadata;
20 import io.grpc.Status;
21 
22 /** An observer of client-side stream events. */
23 public interface ClientStreamListener extends StreamListener {
24   /**
25    * Called upon receiving all header information from the remote end-point. Note that transports
26    * are not required to call this method if no header information is received, this would occur
27    * when a stream immediately terminates with an error and only
28    * {@link #closed(io.grpc.Status, Metadata)} is called.
29    *
30    * <p>This method should return quickly, as the same thread may be used to process other streams.
31    *
32    * @param headers the fully buffered received headers.
33    */
headersRead(Metadata headers)34   void headersRead(Metadata headers);
35 
36   /**
37    * Called when the stream is fully closed. {@link
38    * io.grpc.Status.Code#OK} is the only status code that is guaranteed
39    * to have been sent from the remote server. Any other status code may have been caused by
40    * abnormal stream termination. This is guaranteed to always be the final call on a listener. No
41    * further callbacks will be issued.
42    *
43    * <p>This method should return quickly, as the same thread may be used to process other streams.
44    *
45    * @param status details about the remote closure
46    * @param trailers trailing metadata
47    */
48   // TODO(zdapeng): remove this method in favor of the 3-arg one.
closed(Status status, Metadata trailers)49   void closed(Status status, Metadata trailers);
50 
51   /**
52    * Called when the stream is fully closed. {@link
53    * io.grpc.Status.Code#OK} is the only status code that is guaranteed
54    * to have been sent from the remote server. Any other status code may have been caused by
55    * abnormal stream termination. This is guaranteed to always be the final call on a listener. No
56    * further callbacks will be issued.
57    *
58    * <p>This method should return quickly, as the same thread may be used to process other streams.
59    *
60    * @param status details about the remote closure
61    * @param rpcProgress RPC progress when client stream listener is closed
62    * @param trailers trailing metadata
63    */
closed(Status status, RpcProgress rpcProgress, Metadata trailers)64   void closed(Status status, RpcProgress rpcProgress, Metadata trailers);
65 
66   /**
67    * The progress of the RPC when client stream listener is closed.
68    */
69   enum RpcProgress {
70     /**
71      * The RPC is processed by the server normally.
72      */
73     PROCESSED,
74     /**
75      * The RPC is not processed by the server's application logic.
76      */
77     REFUSED,
78     /**
79      * The RPC is dropped (by load balancer).
80      */
81     DROPPED
82   }
83 }
84