• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #20063

11 Nov 2025 03:44PM UTC coverage: 88.562% (+0.02%) from 88.539%
#20063

push

github

ejona86
api: Document A18 TCP_USER_TIMEOUT handling for keepalive

Fixes #12487

35089 of 39621 relevant lines covered (88.56%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.68
/../api/src/main/java/io/grpc/ManagedChannelBuilder.java
1
/*
2
 * Copyright 2015 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;
18

19
import com.google.common.base.Preconditions;
20
import java.util.List;
21
import java.util.Map;
22
import java.util.concurrent.Executor;
23
import java.util.concurrent.TimeUnit;
24
import javax.annotation.Nullable;
25

26
/**
27
 * A builder for {@link ManagedChannel} instances.
28
 *
29
 * @param <T> The concrete type of this builder.
30
 */
31
public abstract class ManagedChannelBuilder<T extends ManagedChannelBuilder<T>> {
1✔
32
  /**
33
   * Creates a channel with the target's address and port number.
34
   *
35
   * <p>Note that there is an open JDK bug on {@link java.net.URI} class parsing an ipv6 scope ID:
36
   * bugs.openjdk.org/browse/JDK-8199396. This method is exposed to this bug. If you experience an
37
   * issue, a work-around is to convert the scope ID to its numeric form (e.g. by using
38
   * Inet6Address.getScopeId()) before calling this method.
39
   *
40
   * @see #forTarget(String)
41
   * @since 1.0.0
42
   */
43
  public static ManagedChannelBuilder<?> forAddress(String name, int port) {
44
    return ManagedChannelProvider.provider().builderForAddress(name, port);
1✔
45
  }
46

47
  /**
48
   * Creates a channel with a target string, which can be either a valid {@link
49
   * NameResolver}-compliant URI, or an authority string.
50
   *
51
   * <p>A {@code NameResolver}-compliant URI is an absolute hierarchical URI as defined by {@link
52
   * java.net.URI}. Example URIs:
53
   * <ul>
54
   *   <li>{@code "dns:///foo.googleapis.com:8080"}</li>
55
   *   <li>{@code "dns:///foo.googleapis.com"}</li>
56
   *   <li>{@code "dns:///%5B2001:db8:85a3:8d3:1319:8a2e:370:7348%5D:443"}</li>
57
   *   <li>{@code "dns://8.8.8.8/foo.googleapis.com:8080"}</li>
58
   *   <li>{@code "dns://8.8.8.8/foo.googleapis.com"}</li>
59
   *   <li>{@code "zookeeper://zk.example.com:9900/example_service"}</li>
60
   * </ul>
61
   *
62
   * <p>An authority string will be converted to a {@code NameResolver}-compliant URI, which has
63
   * the scheme from the name resolver with the highest priority (e.g. {@code "dns"}),
64
   * no authority, and the original authority string as its path after properly escaped.
65
   * We recommend libraries to specify the schema explicitly if it is known, since libraries cannot
66
   * know which NameResolver will be default during runtime.
67
   * Example authority strings:
68
   * <ul>
69
   *   <li>{@code "localhost"}</li>
70
   *   <li>{@code "127.0.0.1"}</li>
71
   *   <li>{@code "localhost:8080"}</li>
72
   *   <li>{@code "foo.googleapis.com:8080"}</li>
73
   *   <li>{@code "127.0.0.1:8080"}</li>
74
   *   <li>{@code "[2001:db8:85a3:8d3:1319:8a2e:370:7348]"}</li>
75
   *   <li>{@code "[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443"}</li>
76
   * </ul>
77
   *
78
   * <p>Note that there is an open JDK bug on {@link java.net.URI} class parsing an ipv6 scope ID:
79
   * bugs.openjdk.org/browse/JDK-8199396. This method is exposed to this bug. If you experience an
80
   * issue, a work-around is to convert the scope ID to its numeric form (e.g. by using
81
   * Inet6Address.getScopeId()) before calling this method.
82
   * 
83
   * @since 1.0.0
84
   */
85
  public static ManagedChannelBuilder<?> forTarget(String target) {
86
    return ManagedChannelProvider.provider().builderForTarget(target);
1✔
87
  }
88

89
  /**
90
   * Execute application code directly in the transport thread.
91
   *
92
   * <p>Depending on the underlying transport, using a direct executor may lead to substantial
93
   * performance improvements. However, it also requires the application to not block under
94
   * any circumstances.
95
   *
96
   * <p>Calling this method is semantically equivalent to calling {@link #executor(Executor)} and
97
   * passing in a direct executor. However, this is the preferred way as it may allow the transport
98
   * to perform special optimizations.
99
   *
100
   * @return this
101
   * @since 1.0.0
102
   */
103
  public abstract T directExecutor();
104

105
  /**
106
   * Provides a custom executor.
107
   *
108
   * <p>It's an optional parameter. If the user has not provided an executor when the channel is
109
   * built, the builder will use a static cached thread pool.
110
   *
111
   * <p>The channel won't take ownership of the given executor. It's caller's responsibility to
112
   * shut down the executor when it's desired.
113
   *
114
   * @return this
115
   * @since 1.0.0
116
   */
117
  public abstract T executor(Executor executor);
118

119
  /**
120
   * Provides a custom executor that will be used for operations that block or are expensive, to
121
   * avoid blocking asynchronous code paths. For example, DNS queries and OAuth token fetching over
122
   * HTTP could use this executor.
123
   *
124
   * <p>It's an optional parameter. If the user has not provided an executor when the channel is
125
   * built, the builder will use a static cached thread pool.
126
   *
127
   * <p>The channel won't take ownership of the given executor. It's caller's responsibility to shut
128
   * down the executor when it's desired.
129
   *
130
   * @return this
131
   * @throws UnsupportedOperationException if unsupported
132
   * @since 1.25.0
133
   */
134
  public T offloadExecutor(Executor executor) {
135
    throw new UnsupportedOperationException();
×
136
  }
137

138
  /**
139
   * Adds interceptors that will be called before the channel performs its real work. This is
140
   * functionally equivalent to using {@link ClientInterceptors#intercept(Channel, List)}, but while
141
   * still having access to the original {@code ManagedChannel}. Interceptors run in the reverse
142
   * order in which they are added, just as with consecutive calls to {@code
143
   * ClientInterceptors.intercept()}.
144
   *
145
   * @return this
146
   * @since 1.0.0
147
   */
148
  public abstract T intercept(List<ClientInterceptor> interceptors);
149

150
  /**
151
   * Adds interceptors that will be called before the channel performs its real work. This is
152
   * functionally equivalent to using {@link ClientInterceptors#intercept(Channel,
153
   * ClientInterceptor...)}, but while still having access to the original {@code ManagedChannel}.
154
   * Interceptors run in the reverse order in which they are added, just as with consecutive calls
155
   * to {@code ClientInterceptors.intercept()}.
156
   *
157
   * @return this
158
   * @since 1.0.0
159
   */
160
  public abstract T intercept(ClientInterceptor... interceptors);
161

162
  /**
163
   * Internal-only: Adds a factory that will construct an interceptor based on the channel's target.
164
   * This can be used to work around nameResolverFactory() changing the target string.
165
   */
166
  @Internal
167
  protected T interceptWithTarget(InterceptorFactory factory) {
168
    throw new UnsupportedOperationException();
×
169
  }
170

171
  /** Internal-only. */
172
  @Internal
173
  protected interface InterceptorFactory {
174
    ClientInterceptor newInterceptor(String target);
175
  }
176

177
  /**
178
   * Adds a {@link ClientTransportFilter}. The order of filters being added is the order they will
179
   * be executed
180
   *
181
   * @return this
182
   * @since 1.60.0
183
   */
184
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/10652")
185
  public T addTransportFilter(ClientTransportFilter filter) {
186
    throw new UnsupportedOperationException();
×
187
  }
188

189
  /**
190
   * Provides a custom {@code User-Agent} for the application.
191
   *
192
   * <p>It's an optional parameter. The library will provide a user agent independent of this
193
   * option. If provided, the given agent will prepend the library's user agent information.
194
   *
195
   * @return this
196
   * @since 1.0.0
197
   */
198
  public abstract T userAgent(String userAgent);
199

200
  /**
201
   * Overrides the authority used with TLS and HTTP virtual hosting. It does not change what host is
202
   * actually connected to. Is commonly in the form {@code host:port}.
203
   *
204
   * <p>If the channel builder overrides authority, any authority override from name resolution
205
   * result (via {@link EquivalentAddressGroup#ATTR_AUTHORITY_OVERRIDE}) will be discarded.
206
   *
207
   * <p>This method is intended for testing, but may safely be used outside of tests as an
208
   * alternative to DNS overrides.
209
   *
210
   * @return this
211
   * @since 1.0.0
212
   */
213
  public abstract T overrideAuthority(String authority);
214

215
  /**
216
   * Use of a plaintext connection to the server. By default a secure connection mechanism
217
   * such as TLS will be used.
218
   *
219
   * <p>Should only be used for testing or for APIs where the use of such API or the data
220
   * exchanged is not sensitive.
221
   *
222
   * <p>This assumes prior knowledge that the target of this channel is using plaintext.  It will
223
   * not perform HTTP/1.1 upgrades.
224
   *
225
   * @return this
226
   * @throws IllegalStateException if ChannelCredentials were provided when constructing the builder
227
   * @throws UnsupportedOperationException if plaintext mode is not supported.
228
   * @since 1.11.0
229
   */
230
  public T usePlaintext() {
231
    throw new UnsupportedOperationException();
×
232
  }
233

234
  /**
235
   * Makes the client use TLS. Note: this is enabled by default.
236
   *
237
   * <p>It is recommended to use the {@link ChannelCredentials} API
238
   * instead of this method.
239
   *
240
   * @return this
241
   * @throws IllegalStateException if ChannelCredentials were provided when constructing the builder
242
   * @throws UnsupportedOperationException if transport security is not supported.
243
   * @since 1.9.0
244
   */
245
  public T useTransportSecurity() {
246
    throw new UnsupportedOperationException();
×
247
  }
248

249
  /**
250
   * Provides a custom {@link NameResolver.Factory} for the channel. If this method is not called,
251
   * the builder will try the providers registered in the default {@link NameResolverRegistry} for
252
   * the given target.
253
   *
254
   * <p>This method should rarely be used, as name resolvers should provide a {@code
255
   * NameResolverProvider} and users rely on service loading to find implementations in the class
256
   * path. That allows application's configuration to easily choose the name resolver via the
257
   * 'target' string passed to {@link ManagedChannelBuilder#forTarget(String)}.
258
   *
259
   * @return this
260
   * @since 1.0.0
261
   * @deprecated Most usages should use a globally-registered {@link NameResolverProvider} instead,
262
   *     with either the SPI mechanism or {@link NameResolverRegistry#register}. Replacements for
263
   *     all use-cases are not necessarily available yet. See
264
   *     <a href="https://github.com/grpc/grpc-java/issues/7133">#7133</a>.
265
   */
266
  @Deprecated
267
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770")
268
  public abstract T nameResolverFactory(NameResolver.Factory resolverFactory);
269

270
  /**
271
   * Sets the default load-balancing policy that will be used if the service config doesn't specify
272
   * one.  If not set, the default will be the "pick_first" policy.
273
   *
274
   * <p>Policy implementations are looked up in the
275
   * {@link LoadBalancerRegistry#getDefaultRegistry default LoadBalancerRegistry}.
276
   *
277
   * <p>This method is implemented by all stock channel builders that are shipped with gRPC, but may
278
   * not be implemented by custom channel builders, in which case this method will throw.
279
   *
280
   * @return this
281
   * @since 1.18.0
282
   */
283
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
284
  public T defaultLoadBalancingPolicy(String policy) {
285
    throw new UnsupportedOperationException();
×
286
  }
287

288
  /**
289
   * Set the decompression registry for use in the channel. This is an advanced API call and
290
   * shouldn't be used unless you are using custom message encoding. The default supported
291
   * decompressors are in {@link DecompressorRegistry#getDefaultInstance}.
292
   *
293
   * @return this
294
   * @since 1.0.0
295
   */
296
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1704")
297
  public abstract T decompressorRegistry(DecompressorRegistry registry);
298

299
  /**
300
   * Set the compression registry for use in the channel.  This is an advanced API call and
301
   * shouldn't be used unless you are using custom message encoding.   The default supported
302
   * compressors are in {@link CompressorRegistry#getDefaultInstance}.
303
   *
304
   * @return this
305
   * @since 1.0.0
306
   */
307
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1704")
308
  public abstract T compressorRegistry(CompressorRegistry registry);
309

310
  /**
311
   * Set the duration without ongoing RPCs before going to idle mode.
312
   *
313
   * <p>In idle mode the channel shuts down all connections, the NameResolver and the
314
   * LoadBalancer. A new RPC would take the channel out of idle mode. A channel starts in idle mode.
315
   * Defaults to 30 minutes.
316
   *
317
   * <p>This is an advisory option. Do not rely on any specific behavior related to this option.
318
   *
319
   * @return this
320
   * @since 1.0.0
321
   */
322
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2022")
323
  public abstract T idleTimeout(long value, TimeUnit unit);
324

325
  /**
326
   * Sets the maximum message size allowed to be received on the channel. If not called,
327
   * defaults to 4 MiB. The default provides protection to clients who haven't considered the
328
   * possibility of receiving large messages while trying to be large enough to not be hit in normal
329
   * usage.
330
   *
331
   * <p>This method is advisory, and implementations may decide to not enforce this.  Currently,
332
   * the only known transport to not enforce this is {@code InProcessTransport}.
333
   *
334
   * @param bytes the maximum number of bytes a single message can be.
335
   * @return this
336
   * @throws IllegalArgumentException if bytes is negative.
337
   * @since 1.1.0
338
   */
339
  public T maxInboundMessageSize(int bytes) {
340
    // intentional noop rather than throw, this method is only advisory.
341
    Preconditions.checkArgument(bytes >= 0, "bytes must be >= 0");
×
342
    return thisT();
×
343
  }
344

345
  /**
346
   * Sets the maximum size of metadata allowed to be received. {@code Integer.MAX_VALUE} disables
347
   * the enforcement. The default is implementation-dependent, but is not generally less than 8 KiB
348
   * and may be unlimited.
349
   *
350
   * <p>This is cumulative size of the metadata. The precise calculation is
351
   * implementation-dependent, but implementations are encouraged to follow the calculation used for
352
   * <a href="http://httpwg.org/specs/rfc7540.html#rfc.section.6.5.2">
353
   * HTTP/2's SETTINGS_MAX_HEADER_LIST_SIZE</a>. It sums the bytes from each entry's key and value,
354
   * plus 32 bytes of overhead per entry.
355
   *
356
   * @param bytes the maximum size of received metadata
357
   * @return this
358
   * @throws IllegalArgumentException if bytes is non-positive
359
   * @since 1.17.0
360
   */
361
  public T maxInboundMetadataSize(int bytes) {
362
    Preconditions.checkArgument(bytes > 0, "maxInboundMetadataSize must be > 0");
×
363
    // intentional noop rather than throw, this method is only advisory.
364
    return thisT();
×
365
  }
366

367
  /**
368
   * Sets the time without read activity before sending a keepalive ping. An unreasonably small
369
   * value might be increased, and {@code Long.MAX_VALUE} nano seconds or an unreasonably large
370
   * value will disable keepalive. Defaults to infinite.
371
   *
372
   * <p>Clients must receive permission from the service owner before enabling this option.
373
   * Keepalives can increase the load on services and are commonly "invisible" making it hard to
374
   * notice when they are causing excessive load. Clients are strongly encouraged to use only as
375
   * small of a value as necessary.
376
   *
377
   * <p>When the channel implementation supports TCP_USER_TIMEOUT, enabling keepalive will also
378
   * enable TCP_USER_TIMEOUT for the connection. This requires <em>all</em> sent packets to receive
379
   * a TCP acknowledgement before the keepalive timeout. The keepalive time is not used for
380
   * TCP_USER_TIMEOUT, except as a signal to enable the feature. grpc-netty supports
381
   * TCP_USER_TIMEOUT on Linux platforms supported by netty-transport-native-epoll.
382
   *
383
   * @throws UnsupportedOperationException if unsupported
384
   * @see <a href="https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md">gRFC A8
385
   *     Client-side Keepalive</a>
386
   * @see <a href="https://github.com/grpc/proposal/blob/master/A18-tcp-user-timeout.md">gRFC A18
387
   *     TCP User Timeout</a>
388
   * @since 1.7.0
389
   */
390
  public T keepAliveTime(long keepAliveTime, TimeUnit timeUnit) {
391
    throw new UnsupportedOperationException();
×
392
  }
393

394
  /**
395
   * Sets the time waiting for read activity after sending a keepalive ping. If the time expires
396
   * without any read activity on the connection, the connection is considered dead. An unreasonably
397
   * small value might be increased. Defaults to 20 seconds.
398
   *
399
   * <p>This value should be at least multiple times the RTT to allow for lost packets.
400
   *
401
   * @throws UnsupportedOperationException if unsupported
402
   * @see <a href="https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md">gRFC A8
403
   *     Client-side Keepalive</a>
404
   * @see <a href="https://github.com/grpc/proposal/blob/master/A18-tcp-user-timeout.md">gRFC A18
405
   *     TCP User Timeout</a>
406
   * @since 1.7.0
407
   */
408
  public T keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit) {
409
    throw new UnsupportedOperationException();
×
410
  }
411

412
  /**
413
   * Sets whether keepalive will be performed when there are no outstanding RPC on a connection.
414
   * Defaults to {@code false}.
415
   *
416
   * <p>Clients must receive permission from the service owner before enabling this option.
417
   * Keepalives on unused connections can easilly accidentally consume a considerable amount of
418
   * bandwidth and CPU. {@link ManagedChannelBuilder#idleTimeout idleTimeout()} should generally be
419
   * used instead of this option.
420
   *
421
   * @throws UnsupportedOperationException if unsupported
422
   * @see #keepAliveTime(long, TimeUnit)
423
   * @see <a href="https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md">gRFC A8
424
   *     Client-side Keepalive</a>
425
   * @since 1.7.0
426
   */
427
  public T keepAliveWithoutCalls(boolean enable) {
428
    throw new UnsupportedOperationException();
×
429
  }
430

431
  /**
432
   * Sets the maximum number of retry attempts that may be configured by the service config. If the
433
   * service config specifies a larger value it will be reduced to this value.  Setting this number
434
   * to zero is not effectively the same as {@code disableRetry()} because the former does not
435
   * disable
436
   * <a
437
   * href="https://github.com/grpc/proposal/blob/master/A6-client-retries.md#transparent-retries">
438
   * transparent retry</a>.
439
   *
440
   * <p>This method may not work as expected for the current release because retry is not fully
441
   * implemented yet.
442
   *
443
   * @return this
444
   * @since 1.11.0
445
   */
446
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
447
  public T maxRetryAttempts(int maxRetryAttempts) {
448
    throw new UnsupportedOperationException();
×
449
  }
450

451
  /**
452
   * Sets the maximum number of hedged attempts that may be configured by the service config. If the
453
   * service config specifies a larger value it will be reduced to this value.
454
   *
455
   * <p>This method may not work as expected for the current release because retry is not fully
456
   * implemented yet.
457
   *
458
   * @return this
459
   * @since 1.11.0
460
   */
461
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
462
  public T maxHedgedAttempts(int maxHedgedAttempts) {
463
    throw new UnsupportedOperationException();
×
464
  }
465

466
  /**
467
   * Sets the retry buffer size in bytes. If the buffer limit is exceeded, no RPC
468
   * could retry at the moment, and in hedging case all hedges but one of the same RPC will cancel.
469
   * The implementation may only estimate the buffer size being used rather than count the
470
   * exact physical memory allocated. The method does not have any effect if retry is disabled by
471
   * the client.
472
   *
473
   * <p>This method may not work as expected for the current release because retry is not fully
474
   * implemented yet.
475
   *
476
   * @return this
477
   * @since 1.10.0
478
   */
479
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
480
  public T retryBufferSize(long bytes) {
481
    throw new UnsupportedOperationException();
×
482
  }
483

484
  /**
485
   * Sets the per RPC buffer limit in bytes used for retry. The RPC is not retriable if its buffer
486
   * limit is exceeded. The implementation may only estimate the buffer size being used rather than
487
   * count the exact physical memory allocated. It does not have any effect if retry is disabled by
488
   * the client.
489
   *
490
   * <p>This method may not work as expected for the current release because retry is not fully
491
   * implemented yet.
492
   *
493
   * @return this
494
   * @since 1.10.0
495
   */
496
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
497
  public T perRpcBufferLimit(long bytes) {
498
    throw new UnsupportedOperationException();
×
499
  }
500

501

502
  /**
503
   * Disables the retry and hedging subsystem provided by the gRPC library. This is designed for the
504
   * case when users have their own retry implementation and want to avoid their own retry taking
505
   * place simultaneously with the gRPC library layer retry.
506
   *
507
   * @return this
508
   * @since 1.11.0
509
   */
510
  public T disableRetry() {
511
    throw new UnsupportedOperationException();
×
512
  }
513

514
  /**
515
   * Enables the retry and hedging subsystem which will use
516
   * <a href="https://github.com/grpc/proposal/blob/master/A6-client-retries.md#integration-with-service-config">
517
   * per-method configuration</a>. If a method is unconfigured, it will be limited to
518
   * transparent retries, which are safe for non-idempotent RPCs. Service config is ideally provided
519
   * by the name resolver, but may also be specified via {@link #defaultServiceConfig}.
520
   *
521
   * @return this
522
   * @since 1.11.0
523
   */
524
  public T enableRetry() {
525
    throw new UnsupportedOperationException();
×
526
  }
527

528
  /**
529
   * Sets the BinaryLog object that this channel should log to. The channel does not take
530
   * ownership of the object, and users are responsible for calling {@link BinaryLog#close()}.
531
   *
532
   * @param binaryLog the object to provide logging.
533
   * @return this
534
   * @since 1.13.0
535
   */
536
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4017")
537
  public T setBinaryLog(BinaryLog binaryLog) {
538
    throw new UnsupportedOperationException();
×
539
  }
540

541
  /**
542
   * Sets the maximum number of channel trace events to keep in the tracer for each channel or
543
   * subchannel. If set to 0, channel tracing is effectively disabled.
544
   *
545
   * @return this
546
   * @since 1.13.0
547
   */
548
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4471")
549
  public T maxTraceEvents(int maxTraceEvents) {
550
    throw new UnsupportedOperationException();
×
551
  }
552

553
  /**
554
   * Sets the proxy detector to be used in addresses name resolution. If <code>null</code> is passed
555
   * the default proxy detector will be used.  For how proxies work in gRPC, please refer to the
556
   * documentation on {@link ProxyDetector}.
557
   *
558
   * @return this
559
   * @since 1.19.0
560
   */
561
  public T proxyDetector(ProxyDetector proxyDetector) {
562
    throw new UnsupportedOperationException();
×
563
  }
564

565
  /**
566
   * Provides a service config to the channel. The channel will use the default service config when
567
   * the name resolver provides no service config or if the channel disables lookup service config
568
   * from name resolver (see {@link #disableServiceConfigLookUp()}). The argument
569
   * {@code serviceConfig} is a nested map representing a Json object in the most natural way:
570
   *
571
   *        <table border="1">
572
   *          <tr>
573
   *            <td>Json entry</td><td>Java Type</td>
574
   *          </tr>
575
   *          <tr>
576
   *            <td>object</td><td>{@link Map}</td>
577
   *          </tr>
578
   *          <tr>
579
   *            <td>array</td><td>{@link List}</td>
580
   *          </tr>
581
   *          <tr>
582
   *            <td>string</td><td>{@link String}</td>
583
   *          </tr>
584
   *          <tr>
585
   *            <td>number</td><td>{@link Double}</td>
586
   *          </tr>
587
   *          <tr>
588
   *            <td>boolean</td><td>{@link Boolean}</td>
589
   *          </tr>
590
   *          <tr>
591
   *            <td>null</td><td>{@code null}</td>
592
   *          </tr>
593
   *        </table>
594
   *
595
   * <p>If null is passed, then there will be no default service config.
596
   *
597
   * <p>Your preferred JSON parser may not produce results in the format expected. For such cases,
598
   * you can convert its output. For example, if your parser produces Integers and other Numbers
599
   * in addition to Double:
600
   *
601
   * <pre>{@code @SuppressWarnings("unchecked")
602
   * private static Object convertNumbers(Object o) {
603
   *   if (o instanceof Map) {
604
   *     ((Map) o).replaceAll((k,v) -> convertNumbers(v));
605
   *   } else if (o instanceof List) {
606
   *     ((List) o).replaceAll(YourClass::convertNumbers);
607
   *   } else if (o instanceof Number && !(o instanceof Double)) {
608
   *     o = ((Number) o).doubleValue();
609
   *   }
610
   *   return o;
611
   * }}</pre>
612
   *
613
   * @return this
614
   * @throws IllegalArgumentException When the given serviceConfig is invalid or the current version
615
   *         of grpc library can not parse it gracefully. The state of the builder is unchanged if
616
   *         an exception is thrown.
617
   * @since 1.20.0
618
   */
619
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5189")
620
  public T defaultServiceConfig(@Nullable Map<String, ?> serviceConfig) {
621
    throw new UnsupportedOperationException();
×
622
  }
623

624
  /**
625
   * Disables service config look-up from the naming system, which is enabled by default.
626
   *
627
   * @return this
628
   * @since 1.20.0
629
   */
630
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5189")
631
  public T disableServiceConfigLookUp() {
632
    throw new UnsupportedOperationException();
×
633
  }
634

635
  /**
636
   * Adds a {@link MetricSink} for channel to use for configuring and recording metrics.
637
   *
638
   * @return this
639
   * @since 1.64.0
640
   */
641
  @Internal
642
  protected T addMetricSink(MetricSink metricSink) {
643
    throw new UnsupportedOperationException();
×
644
  }
645

646
  /**
647
   * Provides a "custom" argument for the {@link NameResolver}, if applicable, replacing any 'value'
648
   * previously provided for 'key'.
649
   *
650
   * <p>NB: If the selected {@link NameResolver} does not understand 'key', or target URI resolution
651
   * isn't needed at all, your custom argument will be silently ignored.
652
   *
653
   * <p>See {@link NameResolver.Args#getArg(NameResolver.Args.Key)} for more.
654
   *
655
   * @param key identifies the argument in a type-safe manner
656
   * @param value the argument itself
657
   * @return this
658
   */
659
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770")
660
  public <X> T setNameResolverArg(NameResolver.Args.Key<X> key, X value) {
661
    throw new UnsupportedOperationException();
×
662
  }
663

664
  /**
665
   * Builds a channel using the given parameters.
666
   *
667
   * @since 1.0.0
668
   */
669
  public abstract ManagedChannel build();
670

671
  /**
672
   * Returns the correctly typed version of the builder.
673
   */
674
  private T thisT() {
675
    @SuppressWarnings("unchecked")
676
    T thisT = (T) this;
×
677
    return thisT;
×
678
  }
679
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc