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

grpc / grpc-java / #18818

06 Sep 2023 02:58PM UTC coverage: 88.283% (-0.02%) from 88.301%
#18818

push

github-actions

ejona86
api: Make offload executor's purpose more clear

Blocking can be confused with the blocking stub, which is unrelated. I'm
purposefully not saying "it is used only for X," as that isn't what we
need from the API. But it is still helpful to users to describe the
sorts of things that use it.

Fixes #10508

30327 of 34352 relevant lines covered (88.28%)

0.88 hits per line

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

10.71
/../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
   * Provides a custom {@code User-Agent} for the application.
164
   *
165
   * <p>It's an optional parameter. The library will provide a user agent independent of this
166
   * option. If provided, the given agent will prepend the library's user agent information.
167
   *
168
   * @return this
169
   * @since 1.0.0
170
   */
171
  public abstract T userAgent(String userAgent);
172

173
  /**
174
   * Overrides the authority used with TLS and HTTP virtual hosting. It does not change what host is
175
   * actually connected to. Is commonly in the form {@code host:port}.
176
   *
177
   * <p>If the channel builder overrides authority, any authority override from name resolution
178
   * result (via {@link EquivalentAddressGroup#ATTR_AUTHORITY_OVERRIDE}) will be discarded.
179
   *
180
   * <p>This method is intended for testing, but may safely be used outside of tests as an
181
   * alternative to DNS overrides.
182
   *
183
   * @return this
184
   * @since 1.0.0
185
   */
186
  public abstract T overrideAuthority(String authority);
187

188
  /**
189
   * Use of a plaintext connection to the server. By default a secure connection mechanism
190
   * such as TLS will be used.
191
   *
192
   * <p>Should only be used for testing or for APIs where the use of such API or the data
193
   * exchanged is not sensitive.
194
   *
195
   * <p>This assumes prior knowledge that the target of this channel is using plaintext.  It will
196
   * not perform HTTP/1.1 upgrades.
197
   *
198
   * @return this
199
   * @throws IllegalStateException if ChannelCredentials were provided when constructing the builder
200
   * @throws UnsupportedOperationException if plaintext mode is not supported.
201
   * @since 1.11.0
202
   */
203
  public T usePlaintext() {
204
    throw new UnsupportedOperationException();
×
205
  }
206

207
  /**
208
   * Makes the client use TLS. Note: this is enabled by default.
209
   *
210
   * <p>It is recommended to use the {@link ChannelCredentials} API
211
   * instead of this method.
212
   *
213
   * @return this
214
   * @throws IllegalStateException if ChannelCredentials were provided when constructing the builder
215
   * @throws UnsupportedOperationException if transport security is not supported.
216
   * @since 1.9.0
217
   */
218
  public T useTransportSecurity() {
219
    throw new UnsupportedOperationException();
×
220
  }
221

222
  /**
223
   * Provides a custom {@link NameResolver.Factory} for the channel. If this method is not called,
224
   * the builder will try the providers registered in the default {@link NameResolverRegistry} for
225
   * the given target.
226
   *
227
   * <p>This method should rarely be used, as name resolvers should provide a {@code
228
   * NameResolverProvider} and users rely on service loading to find implementations in the class
229
   * path. That allows application's configuration to easily choose the name resolver via the
230
   * 'target' string passed to {@link ManagedChannelBuilder#forTarget(String)}.
231
   *
232
   * @return this
233
   * @since 1.0.0
234
   * @deprecated Most usages should use a globally-registered {@link NameResolverProvider} instead,
235
   *     with either the SPI mechanism or {@link NameResolverRegistry#register}. Replacements for
236
   *     all use-cases are not necessarily available yet. See
237
   *     <a href="https://github.com/grpc/grpc-java/issues/7133">#7133</a>.
238
   */
239
  @Deprecated
240
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770")
241
  public abstract T nameResolverFactory(NameResolver.Factory resolverFactory);
242

243
  /**
244
   * Sets the default load-balancing policy that will be used if the service config doesn't specify
245
   * one.  If not set, the default will be the "pick_first" policy.
246
   *
247
   * <p>Policy implementations are looked up in the
248
   * {@link LoadBalancerRegistry#getDefaultRegistry default LoadBalancerRegistry}.
249
   *
250
   * <p>This method is implemented by all stock channel builders that are shipped with gRPC, but may
251
   * not be implemented by custom channel builders, in which case this method will throw.
252
   *
253
   * @return this
254
   * @since 1.18.0
255
   */
256
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
257
  public T defaultLoadBalancingPolicy(String policy) {
258
    throw new UnsupportedOperationException();
×
259
  }
260

261
  /**
262
   * Enables full-stream decompression of inbound streams. This will cause the channel's outbound
263
   * headers to advertise support for GZIP compressed streams, and gRPC servers which support the
264
   * feature may respond with a GZIP compressed stream.
265
   *
266
   * <p>EXPERIMENTAL: This method is here to enable an experimental feature, and may be changed or
267
   * removed once the feature is stable.
268
   *
269
   * @throws UnsupportedOperationException if unsupported
270
   * @since 1.7.0
271
   */
272
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3399")
273
  public T enableFullStreamDecompression() {
274
    throw new UnsupportedOperationException();
×
275
  }
276

277
  /**
278
   * Set the decompression registry for use in the channel. This is an advanced API call and
279
   * shouldn't be used unless you are using custom message encoding. The default supported
280
   * decompressors are in {@link DecompressorRegistry#getDefaultInstance}.
281
   *
282
   * @return this
283
   * @since 1.0.0
284
   */
285
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1704")
286
  public abstract T decompressorRegistry(DecompressorRegistry registry);
287

288
  /**
289
   * Set the compression 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
   * compressors are in {@link CompressorRegistry#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 compressorRegistry(CompressorRegistry registry);
298

299
  /**
300
   * Set the duration without ongoing RPCs before going to idle mode.
301
   *
302
   * <p>In idle mode the channel shuts down all connections, the NameResolver and the
303
   * LoadBalancer. A new RPC would take the channel out of idle mode. A channel starts in idle mode.
304
   * Defaults to 30 minutes.
305
   *
306
   * <p>This is an advisory option. Do not rely on any specific behavior related to this option.
307
   *
308
   * @return this
309
   * @since 1.0.0
310
   */
311
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/2022")
312
  public abstract T idleTimeout(long value, TimeUnit unit);
313

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

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

356
  /**
357
   * Sets the time without read activity before sending a keepalive ping. An unreasonably small
358
   * value might be increased, and {@code Long.MAX_VALUE} nano seconds or an unreasonably large
359
   * value will disable keepalive. Defaults to infinite.
360
   *
361
   * <p>Clients must receive permission from the service owner before enabling this option.
362
   * Keepalives can increase the load on services and are commonly "invisible" making it hard to
363
   * notice when they are causing excessive load. Clients are strongly encouraged to use only as
364
   * small of a value as necessary.
365
   *
366
   * @throws UnsupportedOperationException if unsupported
367
   * @see <a href="https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md">gRFC A8
368
   *     Client-side Keepalive</a>
369
   * @since 1.7.0
370
   */
371
  public T keepAliveTime(long keepAliveTime, TimeUnit timeUnit) {
372
    throw new UnsupportedOperationException();
×
373
  }
374

375
  /**
376
   * Sets the time waiting for read activity after sending a keepalive ping. If the time expires
377
   * without any read activity on the connection, the connection is considered dead. An unreasonably
378
   * small value might be increased. Defaults to 20 seconds.
379
   *
380
   * <p>This value should be at least multiple times the RTT to allow for lost packets.
381
   *
382
   * @throws UnsupportedOperationException if unsupported
383
   * @see <a href="https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md">gRFC A8
384
   *     Client-side Keepalive</a>
385
   * @since 1.7.0
386
   */
387
  public T keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit) {
388
    throw new UnsupportedOperationException();
×
389
  }
390

391
  /**
392
   * Sets whether keepalive will be performed when there are no outstanding RPC on a connection.
393
   * Defaults to {@code false}.
394
   *
395
   * <p>Clients must receive permission from the service owner before enabling this option.
396
   * Keepalives on unused connections can easilly accidentally consume a considerable amount of
397
   * bandwidth and CPU. {@link ManagedChannelBuilder#idleTimeout idleTimeout()} should generally be
398
   * used instead of this option.
399
   *
400
   * @throws UnsupportedOperationException if unsupported
401
   * @see #keepAliveTime(long, TimeUnit)
402
   * @see <a href="https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md">gRFC A8
403
   *     Client-side Keepalive</a>
404
   * @since 1.7.0
405
   */
406
  public T keepAliveWithoutCalls(boolean enable) {
407
    throw new UnsupportedOperationException();
×
408
  }
409

410
  /**
411
   * Sets the maximum number of retry attempts that may be configured by the service config. If the
412
   * service config specifies a larger value it will be reduced to this value.  Setting this number
413
   * to zero is not effectively the same as {@code disableRetry()} because the former does not
414
   * disable
415
   * <a
416
   * href="https://github.com/grpc/proposal/blob/master/A6-client-retries.md#transparent-retries">
417
   * transparent retry</a>.
418
   *
419
   * <p>This method may not work as expected for the current release because retry is not fully
420
   * implemented yet.
421
   *
422
   * @return this
423
   * @since 1.11.0
424
   */
425
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
426
  public T maxRetryAttempts(int maxRetryAttempts) {
427
    throw new UnsupportedOperationException();
×
428
  }
429

430
  /**
431
   * Sets the maximum number of hedged attempts that may be configured by the service config. If the
432
   * service config specifies a larger value it will be reduced to this value.
433
   *
434
   * <p>This method may not work as expected for the current release because retry is not fully
435
   * implemented yet.
436
   *
437
   * @return this
438
   * @since 1.11.0
439
   */
440
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
441
  public T maxHedgedAttempts(int maxHedgedAttempts) {
442
    throw new UnsupportedOperationException();
×
443
  }
444

445
  /**
446
   * Sets the retry buffer size in bytes. If the buffer limit is exceeded, no RPC
447
   * could retry at the moment, and in hedging case all hedges but one of the same RPC will cancel.
448
   * The implementation may only estimate the buffer size being used rather than count the
449
   * exact physical memory allocated. The method does not have any effect if retry is disabled by
450
   * the client.
451
   *
452
   * <p>This method may not work as expected for the current release because retry is not fully
453
   * implemented yet.
454
   *
455
   * @return this
456
   * @since 1.10.0
457
   */
458
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
459
  public T retryBufferSize(long bytes) {
460
    throw new UnsupportedOperationException();
×
461
  }
462

463
  /**
464
   * Sets the per RPC buffer limit in bytes used for retry. The RPC is not retriable if its buffer
465
   * limit is exceeded. The implementation may only estimate the buffer size being used rather than
466
   * count the exact physical memory allocated. It does not have any effect if retry is disabled by
467
   * the client.
468
   *
469
   * <p>This method may not work as expected for the current release because retry is not fully
470
   * implemented yet.
471
   *
472
   * @return this
473
   * @since 1.10.0
474
   */
475
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
476
  public T perRpcBufferLimit(long bytes) {
477
    throw new UnsupportedOperationException();
×
478
  }
479

480

481
  /**
482
   * Disables the retry and hedging subsystem provided by the gRPC library. This is designed for the
483
   * case when users have their own retry implementation and want to avoid their own retry taking
484
   * place simultaneously with the gRPC library layer retry.
485
   *
486
   * @return this
487
   * @since 1.11.0
488
   */
489
  public T disableRetry() {
490
    throw new UnsupportedOperationException();
×
491
  }
492

493
  /**
494
   * Enables the retry and hedging subsystem which will use
495
   * <a href="https://github.com/grpc/proposal/blob/master/A6-client-retries.md#integration-with-service-config">
496
   * per-method configuration</a>. If a method is unconfigured, it will be limited to
497
   * transparent retries, which are safe for non-idempotent RPCs. Service config is ideally provided
498
   * by the name resolver, but may also be specified via {@link #defaultServiceConfig}.
499
   *
500
   * @return this
501
   * @since 1.11.0
502
   */
503
  public T enableRetry() {
504
    throw new UnsupportedOperationException();
×
505
  }
506

507
  /**
508
   * Sets the BinaryLog object that this channel should log to. The channel does not take
509
   * ownership of the object, and users are responsible for calling {@link BinaryLog#close()}.
510
   *
511
   * @param binaryLog the object to provide logging.
512
   * @return this
513
   * @since 1.13.0
514
   */
515
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4017")
516
  public T setBinaryLog(BinaryLog binaryLog) {
517
    throw new UnsupportedOperationException();
×
518
  }
519

520
  /**
521
   * Sets the maximum number of channel trace events to keep in the tracer for each channel or
522
   * subchannel. If set to 0, channel tracing is effectively disabled.
523
   *
524
   * @return this
525
   * @since 1.13.0
526
   */
527
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4471")
528
  public T maxTraceEvents(int maxTraceEvents) {
529
    throw new UnsupportedOperationException();
×
530
  }
531

532
  /**
533
   * Sets the proxy detector to be used in addresses name resolution. If <code>null</code> is passed
534
   * the default proxy detector will be used.  For how proxies work in gRPC, please refer to the
535
   * documentation on {@link ProxyDetector}.
536
   *
537
   * @return this
538
   * @since 1.19.0
539
   */
540
  public T proxyDetector(ProxyDetector proxyDetector) {
541
    throw new UnsupportedOperationException();
×
542
  }
543

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

603
  /**
604
   * Disables service config look-up from the naming system, which is enabled by default.
605
   *
606
   * @return this
607
   * @since 1.20.0
608
   */
609
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5189")
610
  public T disableServiceConfigLookUp() {
611
    throw new UnsupportedOperationException();
×
612
  }
613

614
  /**
615
   * Builds a channel using the given parameters.
616
   *
617
   * @since 1.0.0
618
   */
619
  public abstract ManagedChannel build();
620

621
  /**
622
   * Returns the correctly typed version of the builder.
623
   */
624
  private T thisT() {
625
    @SuppressWarnings("unchecked")
626
    T thisT = (T) this;
×
627
    return thisT;
×
628
  }
629
}
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