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

grpc / grpc-java / #19162

17 Apr 2024 10:10PM UTC coverage: 88.107% (-0.01%) from 88.117%
#19162

push

github

web-flow
Add MetricRecorder and MetricSink interface (#11109)

Adds interfaces required for recording metrics from gRPC components. And added API to get `MetricRecorder` in `LoadBalancer.Helper` and add `MetricSink` to `ManagedChannelBuilder`.

31190 of 35400 relevant lines covered (88.11%)

0.88 hits per line

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

10.34
/../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
   * Adds a {@link ClientTransportFilter}. The order of filters being added is the order they will
164
   * be executed
165
   *
166
   * @return this
167
   * @since 1.60.0
168
   */
169
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/10652")
170
  public T addTransportFilter(ClientTransportFilter filter) {
171
    throw new UnsupportedOperationException();
×
172
  }
173

174
  /**
175
   * Provides a custom {@code User-Agent} for the application.
176
   *
177
   * <p>It's an optional parameter. The library will provide a user agent independent of this
178
   * option. If provided, the given agent will prepend the library's user agent information.
179
   *
180
   * @return this
181
   * @since 1.0.0
182
   */
183
  public abstract T userAgent(String userAgent);
184

185
  /**
186
   * Overrides the authority used with TLS and HTTP virtual hosting. It does not change what host is
187
   * actually connected to. Is commonly in the form {@code host:port}.
188
   *
189
   * <p>If the channel builder overrides authority, any authority override from name resolution
190
   * result (via {@link EquivalentAddressGroup#ATTR_AUTHORITY_OVERRIDE}) will be discarded.
191
   *
192
   * <p>This method is intended for testing, but may safely be used outside of tests as an
193
   * alternative to DNS overrides.
194
   *
195
   * @return this
196
   * @since 1.0.0
197
   */
198
  public abstract T overrideAuthority(String authority);
199

200
  /**
201
   * Use of a plaintext connection to the server. By default a secure connection mechanism
202
   * such as TLS will be used.
203
   *
204
   * <p>Should only be used for testing or for APIs where the use of such API or the data
205
   * exchanged is not sensitive.
206
   *
207
   * <p>This assumes prior knowledge that the target of this channel is using plaintext.  It will
208
   * not perform HTTP/1.1 upgrades.
209
   *
210
   * @return this
211
   * @throws IllegalStateException if ChannelCredentials were provided when constructing the builder
212
   * @throws UnsupportedOperationException if plaintext mode is not supported.
213
   * @since 1.11.0
214
   */
215
  public T usePlaintext() {
216
    throw new UnsupportedOperationException();
×
217
  }
218

219
  /**
220
   * Makes the client use TLS. Note: this is enabled by default.
221
   *
222
   * <p>It is recommended to use the {@link ChannelCredentials} API
223
   * instead of this method.
224
   *
225
   * @return this
226
   * @throws IllegalStateException if ChannelCredentials were provided when constructing the builder
227
   * @throws UnsupportedOperationException if transport security is not supported.
228
   * @since 1.9.0
229
   */
230
  public T useTransportSecurity() {
231
    throw new UnsupportedOperationException();
×
232
  }
233

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

255
  /**
256
   * Sets the default load-balancing policy that will be used if the service config doesn't specify
257
   * one.  If not set, the default will be the "pick_first" policy.
258
   *
259
   * <p>Policy implementations are looked up in the
260
   * {@link LoadBalancerRegistry#getDefaultRegistry default LoadBalancerRegistry}.
261
   *
262
   * <p>This method is implemented by all stock channel builders that are shipped with gRPC, but may
263
   * not be implemented by custom channel builders, in which case this method will throw.
264
   *
265
   * @return this
266
   * @since 1.18.0
267
   */
268
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
269
  public T defaultLoadBalancingPolicy(String policy) {
270
    throw new UnsupportedOperationException();
×
271
  }
272

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

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

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

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

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

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

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

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

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

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

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

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

476

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

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

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

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

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

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

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

610
  /**
611
   * Adds a {@link MetricSink} for channel to use for configuring and recording metrics.
612
   *
613
   * @return this
614
   * @since 1.64.0
615
   */
616
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/11110")
617
  public T addMetricSink(MetricSink metricSink) {
618
    throw new UnsupportedOperationException();
×
619
  }
620

621

622
  /**
623
   * Builds a channel using the given parameters.
624
   *
625
   * @since 1.0.0
626
   */
627
  public abstract ManagedChannel build();
628

629
  /**
630
   * Returns the correctly typed version of the builder.
631
   */
632
  private T thisT() {
633
    @SuppressWarnings("unchecked")
634
    T thisT = (T) this;
×
635
    return thisT;
×
636
  }
637
}
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