@BetaApi(value="The surface for streaming is not stable yet and may change in the future.")
public interface StreamController
ResponseObserver to control the flow of responses.
An instance of this class will be passed to ResponseObserver.onStart(StreamController), at which point the receiver can disable automatic
flow control. The receiver can also save a reference to the instance and terminate the stream
early using cancel().
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Cancel the stream early.
|
void |
disableAutoInboundFlowControl()
Disables automatic flow control.
|
void |
request(int count)
Requests up to the given number of responses from the call to be delivered to
ResponseObserver.onResponse(Object). |
void cancel()
This will manifest as an onError on the ResponseObserver with the cause being a
CancellationException.
void disableAutoInboundFlowControl()
The next response is requested immediately after the current response is processed by ResponseObserver.onResponse(Object). If disabled, an application must make explicit calls to
request(int) to receive messages.
void request(int count)
ResponseObserver.onResponse(Object). No additional messages will be delivered.
This method can only be called after disabling automatic flow control.
Message delivery is guaranteed to be sequential in the order received. In addition, the listener methods will not be accessed concurrently. While it is not guaranteed that the same thread will always be used, it is guaranteed that only a single thread will access the listener at a time.
If called multiple times, the number of messages able to delivered will be the sum of the calls.
This method is safe to call from multiple threads without external synchronizaton.
count - the requested number of messages to be delivered to the listener. Must be
non-negative.