Interface StreamController (2.41.0)

public interface StreamController

Allows the implementer of 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().

Methods

cancel()

public abstract void cancel()

Cancel the stream early.

This will manifest as an onError on the ResponseObserver with the cause being a CancellationException.

disableAutoInboundFlowControl()

public abstract void disableAutoInboundFlowControl()

Disables automatic flow control.

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 to receive messages.

request(int count)

public abstract void request(int count)

Requests up to the given number of responses from the call to be delivered to 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.

Parameter
NameDescription
countint

the requested number of messages to be delivered to the listener. Must be non-negative.