Class ServerStream<V> (2.17.0)

publicclassServerStream<V>implementsIterable<V>

A blocking Iterable-style wrapper around server stream responses.

This class asynchronously pulls responses from upstream viaStreamController#request(int) and exposes them via its Iterator. The implementation is back pressure aware and uses a constant buffer of 1 item.

Please note that the stream can only be consumed once and must either be fully consumed or be canceled.

Neither this class nor the iterator it returns is thread-safe.

Example usage:

ServerStream<Item>stream=...;for(Itemitem:stream){System.out.println(item.id());// Allow for early terminationif(item.id().equals("needle")){// Cancelling the stream will causehasNext() to return false on the next iteration,// naturally breaking the loop.stream.cancel();}}

Inheritance

java.lang.Object >ServerStream<V>

Implements

Iterable<V>

Type Parameter

NameDescription
V

Methods

cancel()

publicvoidcancel()

Cleanly cancels a partially consumed stream. The associated iterator will return false for the hasNext() in the next iteration. This maintains the contract that an observed true from hasNext() will yield an item in next(), but afterwards will return false.

isReceiveReady()

publicbooleanisReceiveReady()

Returns true if the next call to the iterator's hasNext() or next() is guaranteed to be nonblocking.

Returns
TypeDescription
boolean

If the call on any of the iterator's methods is guaranteed to be nonblocking.

iterator()

publicIterator<V>iterator()
Returns
TypeDescription
Iterator<V>

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.