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

grpc / grpc-java / #20383

30 Jul 2026 04:33PM UTC coverage: 89.149% (-0.005%) from 89.154%
#20383

push

github

ejona86
api: Better explain the executors and how to configure them

38310 of 42973 relevant lines covered (89.15%)

0.89 hits per line

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

9.38
/../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 an RFC 3986 URI, or an authority
49
   * string.
50
   *
51
   * <p>Example URIs:
52
   * <ul>
53
   *   <li>{@code "dns:///foo.googleapis.com:8080"}</li>
54
   *   <li>{@code "dns:///foo.googleapis.com"}</li>
55
   *   <li>{@code "dns:///%5B2001:db8:85a3:8d3:1319:8a2e:370:7348%5D:443"}</li>
56
   *   <li>{@code "dns://8.8.8.8/foo.googleapis.com:8080"}</li>
57
   *   <li>{@code "dns://8.8.8.8/foo.googleapis.com"}</li>
58
   *   <li>{@code "zookeeper://zk.example.com:9900/example_service"}</li>
59
   *   <li>{@code "intent:#Intent;package=com.some.app;action=a;category=c;end;"}</li>
60
   * </ul>
61
   *
62
   * <p>An authority string will be converted to a URI having the scheme of the name resolver with
63
   * the highest priority (e.g. {@code "dns"}), the empty string as the authority, and
64
   * {@code target} as its absolute path. We recommend libraries specify {@code target} as a URI
65
   * instead since they cannot know which NameResolver will be default at runtime.
66
   * Example authority strings:
67
   * <ul>
68
   *   <li>{@code "localhost"}</li>
69
   *   <li>{@code "127.0.0.1"}</li>
70
   *   <li>{@code "localhost:8080"}</li>
71
   *   <li>{@code "foo.googleapis.com:8080"}</li>
72
   *   <li>{@code "127.0.0.1:8080"}</li>
73
   *   <li>{@code "[2001:db8:85a3:8d3:1319:8a2e:370:7348]"}</li>
74
   *   <li>{@code "[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443"}</li>
75
   * </ul>
76
   *
77
   * <p>The URI form of {@code target} is preferred because it is less ambiguous. For example, the
78
   * target string {@code foo:8080} is a valid authority string with host {@code foo} and port
79
   * {@code 8080} but it is also a valid RFC 3986 URI with scheme {@code foo} and path {@code 8080}.
80
   * gRPC prioritizes the URI form, which means {@code foo:8080} will be treated as a URI with
81
   * scheme {@code foo}. Using {@code dns:///foo:8080} avoids this ambiguity.
82
   *
83
   * <p>Note that there is an open JDK bug on {@link java.net.URI} class parsing an ipv6 scope ID:
84
   * bugs.openjdk.org/browse/JDK-8199396. This method is exposed to this bug. If you experience an
85
   * issue, a work-around is to convert the scope ID to its numeric form (e.g. by using
86
   * Inet6Address.getScopeId()) before calling this method.
87
   * 
88
   * @since 1.0.0
89
   */
90
  public static ManagedChannelBuilder<?> forTarget(String target) {
91
    return ManagedChannelProvider.provider().builderForTarget(target);
1✔
92
  }
93

94
  /**
95
   * Execute application code directly in the transport thread. The application must not block under
96
   * any circumstances.
97
   *
98
   * <p>Depending on the underlying transport and the application code, using a direct executor may
99
   * lead to 10s of µs latency reduction but causes a substantial performance degradation when
100
   * misused.
101
   *
102
   * <p>Calling this method is semantically equivalent to calling {@link #executor(Executor)} and
103
   * passing in a direct executor. However, this is the preferred way as it may allow the transport
104
   * to perform special optimizations.
105
   *
106
   * @return this
107
   * @since 1.0.0
108
   */
109
  public abstract T directExecutor();
110

111
  /**
112
   * Set the default executor for callbacks. This is used for async and future stub callbacks, but
113
   * can be overridden by {@link CallOptions#withExecutor} and {@code stub.withExecutor()}. Blocking
114
   * stubs specify a per-RPC executor. This is also used for {@link
115
   * ManagedChannel#notifyWhenStateChanged}.
116
   *
117
   * <p>It's an optional parameter. If the user has not provided an executor when the channel is
118
   * built, the builder will use a static cached thread pool.
119
   *
120
   * <p>The channel won't take ownership of the given executor. It's caller's responsibility to
121
   * shut down the executor when it's desired.
122
   *
123
   * @return this
124
   * @since 1.0.0
125
   */
126
  public abstract T executor(Executor executor);
127

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

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

159
  /**
160
   * Adds interceptors that will be called before the channel performs its real work. This is
161
   * functionally equivalent to using {@link ClientInterceptors#intercept(Channel,
162
   * ClientInterceptor...)}, but while still having access to the original {@code ManagedChannel}.
163
   * Interceptors run in the reverse order in which they are added, just as with consecutive calls
164
   * to {@code ClientInterceptors.intercept()}.
165
   *
166
   * @return this
167
   * @since 1.0.0
168
   */
169
  public abstract T intercept(ClientInterceptor... interceptors);
170

171
  /**
172
   * Internal-only: Adds a factory that will construct an interceptor based on the channel's target.
173
   * This can be used to work around nameResolverFactory() changing the target string.
174
   */
175
  @Internal
176
  protected T interceptWithTarget(InterceptorFactory factory) {
177
    throw new UnsupportedOperationException();
×
178
  }
179

180
  /** Internal-only. */
181
  @Internal
182
  protected interface InterceptorFactory {
183
    ClientInterceptor newInterceptor(String target);
184
  }
185

186
  /**
187
   * Adds a {@link ClientTransportFilter}. The order of filters being added is the order they will
188
   * be executed
189
   *
190
   * @return this
191
   * @since 1.60.0
192
   */
193
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/10652")
194
  public T addTransportFilter(ClientTransportFilter filter) {
195
    throw new UnsupportedOperationException();
×
196
  }
197

198
  /**
199
   * Provides a custom {@code User-Agent} for the application.
200
   *
201
   * <p>It's an optional parameter. The library will provide a user agent independent of this
202
   * option. If provided, the given agent will prepend the library's user agent information.
203
   *
204
   * @return this
205
   * @since 1.0.0
206
   */
207
  public abstract T userAgent(String userAgent);
208

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

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

243
  /**
244
   * Makes the client use TLS. Note: this is enabled by default.
245
   *
246
   * <p>It is recommended to use the {@link ChannelCredentials} API
247
   * instead of this method.
248
   *
249
   * @return this
250
   * @throws IllegalStateException if ChannelCredentials were provided when constructing the builder
251
   * @throws UnsupportedOperationException if transport security is not supported.
252
   * @since 1.9.0
253
   */
254
  public T useTransportSecurity() {
255
    throw new UnsupportedOperationException();
×
256
  }
257

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

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

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

308
  /**
309
   * Set the compression registry for use in the channel.  This is an advanced API call and
310
   * shouldn't be used unless you are using custom message encoding.   The default supported
311
   * compressors are in {@link CompressorRegistry#getDefaultInstance}.
312
   *
313
   * @return this
314
   * @since 1.0.0
315
   */
316
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1704")
317
  public abstract T compressorRegistry(CompressorRegistry registry);
318

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

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

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

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

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

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

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

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

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

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

510

511
  /**
512
   * Disables the retry and hedging subsystem provided by the gRPC library. This is designed for the
513
   * case when users have their own retry implementation and want to avoid their own retry taking
514
   * place simultaneously with the gRPC library layer retry.
515
   *
516
   * @return this
517
   * @since 1.11.0
518
   */
519
  public T disableRetry() {
520
    throw new UnsupportedOperationException();
×
521
  }
522

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

537
  /**
538
   * Sets the BinaryLog object that this channel should log to. The channel does not take
539
   * ownership of the object, and users are responsible for calling {@link BinaryLog#close()}.
540
   *
541
   * @param binaryLog the object to provide logging.
542
   * @return this
543
   * @since 1.13.0
544
   */
545
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4017")
546
  public T setBinaryLog(BinaryLog binaryLog) {
547
    throw new UnsupportedOperationException();
×
548
  }
549

550
  /**
551
   * Sets the maximum number of channel trace events to keep in the tracer for each channel or
552
   * subchannel. If set to 0, channel tracing is effectively disabled.
553
   *
554
   * @return this
555
   * @since 1.13.0
556
   */
557
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4471")
558
  public T maxTraceEvents(int maxTraceEvents) {
559
    throw new UnsupportedOperationException();
×
560
  }
561

562
  /**
563
   * Sets the proxy detector to be used in addresses name resolution. If <code>null</code> is passed
564
   * the default proxy detector will be used.  For how proxies work in gRPC, please refer to the
565
   * documentation on {@link ProxyDetector}.
566
   *
567
   * @return this
568
   * @since 1.19.0
569
   */
570
  public T proxyDetector(ProxyDetector proxyDetector) {
571
    throw new UnsupportedOperationException();
×
572
  }
573

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

633
  /**
634
   * Disables service config look-up from the naming system, which is enabled by default.
635
   *
636
   * @return this
637
   * @since 1.20.0
638
   */
639
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5189")
640
  public T disableServiceConfigLookUp() {
641
    throw new UnsupportedOperationException();
×
642
  }
643

644
  /**
645
   * Adds a {@link MetricSink} for channel to use for configuring and recording metrics.
646
   *
647
   * @return this
648
   * @since 1.64.0
649
   */
650
  @Internal
651
  protected T addMetricSink(MetricSink metricSink) {
652
    throw new UnsupportedOperationException();
×
653
  }
654

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

673

674
  /**
675
   * Sets a configurator that will be applied to all internal child channels created by this
676
   * channel.
677
   *
678
   * <p>This allows injecting universal configuration (like interceptors)
679
   * into auxiliary channels created by gRPC infrastructure, such as xDS control plane connections.
680
   *
681
   * @param channelConfigurator the configurator to apply.
682
   * @return this
683
   * @since 1.83.0
684
   */
685
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12574")
686
  public T childChannelConfigurator(ChannelConfigurator channelConfigurator) {
687
    throw new UnsupportedOperationException("Not implemented");
×
688
  }
689

690
  /**
691
   * Builds a channel using the given parameters.
692
   *
693
   * @since 1.0.0
694
   */
695
  public abstract ManagedChannel build();
696

697
  /**
698
   * Returns the correctly typed version of the builder.
699
   */
700
  private T thisT() {
701
    @SuppressWarnings("unchecked")
702
    T thisT = (T) this;
×
703
    return thisT;
×
704
  }
705
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc