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

grpc / grpc-java / #18799

18 Aug 2023 01:05AM UTC coverage: 88.291% (+0.006%) from 88.285%
#18799

push

github-actions

web-flow
api: ManagedChannelBuilder note about ipv6 scope id JDK bug. (#10503)

Adds a note on how to avoid a JDK bug by converting an ipv6 scope ID to
its numeric form.

30349 of 34374 relevant lines covered (88.29%)

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.
121
   *
122
   * <p>It's an optional parameter. If the user has not provided an executor when the channel is
123
   * built, the builder will use a static cached thread pool.
124
   *
125
   * <p>The channel won't take ownership of the given executor. It's caller's responsibility to shut
126
   * down the executor when it's desired.
127
   *
128
   * @return this
129
   * @throws UnsupportedOperationException if unsupported
130
   * @since 1.25.0
131
   */
132
  public T offloadExecutor(Executor executor) {
133
    throw new UnsupportedOperationException();
×
134
  }
135

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

478

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

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

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

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

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

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

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

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

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