5454@ ExperimentalApi ("There is no plan to make this API stable, given transport API instability" )
5555public final class CronetChannelBuilder extends ForwardingChannelBuilder2 <CronetChannelBuilder > {
5656
57+ private static final int DEFAULT_READ_BUFFER_SIZE = 4 * 1024 ;
58+
5759 /** BidirectionalStream.Builder factory used for getting the gRPC BidirectionalStream. */
5860 public static abstract class StreamBuilderFactory {
5961 public abstract BidirectionalStream .Builder newBidirectionalStreamBuilder (
@@ -109,6 +111,7 @@ public static CronetChannelBuilder forAddress(String name, int port) {
109111 private boolean trafficStatsUidSet ;
110112 private int trafficStatsUid ;
111113 private Network network ;
114+ private int readBufferSize = DEFAULT_READ_BUFFER_SIZE ;
112115
113116 private CronetChannelBuilder (String host , int port , CronetEngine cronetEngine ) {
114117 final class CronetChannelTransportFactoryBuilder implements ClientTransportFactoryBuilder {
@@ -142,6 +145,15 @@ public CronetChannelBuilder maxMessageSize(int maxMessageSize) {
142145 return this ;
143146 }
144147
148+ /**
149+ * Sets the buffer size to read from the network. Default to {@link #DEFAULT_READ_BUFFER_SIZE}.
150+ */
151+ public CronetChannelBuilder readBufferSize (int readBufferSize ) {
152+ checkArgument (readBufferSize >= 0 , "readBufferSize must be >= 0" );
153+ this .readBufferSize = readBufferSize ;
154+ return this ;
155+ }
156+
145157 /**
146158 * Sets the Cronet channel to always use PUT instead of POST. Defaults to false.
147159 */
@@ -226,7 +238,8 @@ ClientTransportFactory buildTransportFactory() {
226238 trafficStatsTag ,
227239 trafficStatsUidSet ,
228240 trafficStatsUid ,
229- network ),
241+ network ,
242+ readBufferSize ),
230243 MoreExecutors .directExecutor (),
231244 scheduledExecutorService ,
232245 maxMessageSize ,
@@ -247,6 +260,7 @@ static class CronetTransportFactory implements ClientTransportFactory {
247260 private final boolean usingSharedScheduler ;
248261 private final boolean useGetForSafeMethods ;
249262 private final boolean usePutForIdempotentMethods ;
263+ private final int readBufferSize ;
250264
251265 private CronetTransportFactory (
252266 StreamBuilderFactory streamFactory ,
@@ -256,7 +270,8 @@ private CronetTransportFactory(
256270 boolean alwaysUsePut ,
257271 TransportTracer transportTracer ,
258272 boolean useGetForSafeMethods ,
259- boolean usePutForIdempotentMethods ) {
273+ boolean usePutForIdempotentMethods ,
274+ int readBufferSize ) {
260275 usingSharedScheduler = timeoutService == null ;
261276 this .timeoutService = usingSharedScheduler
262277 ? SharedResourceHolder .get (GrpcUtil .TIMER_SERVICE ) : timeoutService ;
@@ -267,6 +282,7 @@ private CronetTransportFactory(
267282 this .transportTracer = Preconditions .checkNotNull (transportTracer , "transportTracer" );
268283 this .useGetForSafeMethods = useGetForSafeMethods ;
269284 this .usePutForIdempotentMethods = usePutForIdempotentMethods ;
285+ this .readBufferSize = readBufferSize ;
270286 }
271287
272288 @ Override
@@ -275,7 +291,8 @@ public ConnectionClientTransport newClientTransport(
275291 InetSocketAddress inetSocketAddr = (InetSocketAddress ) addr ;
276292 return new CronetClientTransport (streamFactory , inetSocketAddr , options .getAuthority (),
277293 options .getUserAgent (), options .getEagAttributes (), executor , maxMessageSize ,
278- alwaysUsePut , transportTracer , useGetForSafeMethods , usePutForIdempotentMethods );
294+ alwaysUsePut , transportTracer , useGetForSafeMethods , usePutForIdempotentMethods ,
295+ readBufferSize );
279296 }
280297
281298 @ Override
0 commit comments