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

grpc / grpc-java / #19216

09 May 2024 02:28AM UTC coverage: 88.369% (-0.007%) from 88.376%
#19216

push

github

ejona86
opentelemetry: Add grpc.target label to per-call metrics

As defined by gRFC A66, the target is on all client-side per-call
metrics (both call and attempt).

31538 of 35689 relevant lines covered (88.37%)

0.88 hits per line

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

10.0
/../api/src/main/java/io/grpc/ManagedChannelBuilder.java
1
/*
2
 * Copyright 2015 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc;
18

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

421
  /**
422
   * Sets the maximum number of retry attempts that may be configured by the service config. If the
423
   * service config specifies a larger value it will be reduced to this value.  Setting this number
424
   * to zero is not effectively the same as {@code disableRetry()} because the former does not
425
   * disable
426
   * <a
427
   * href="https://github.com/grpc/proposal/blob/master/A6-client-retries.md#transparent-retries">
428
   * transparent retry</a>.
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 maxRetryAttempts(int maxRetryAttempts) {
438
    throw new UnsupportedOperationException();
×
439
  }
440

441
  /**
442
   * Sets the maximum number of hedged attempts that may be configured by the service config. If the
443
   * service config specifies a larger value it will be reduced to this value.
444
   *
445
   * <p>This method may not work as expected for the current release because retry is not fully
446
   * implemented yet.
447
   *
448
   * @return this
449
   * @since 1.11.0
450
   */
451
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3982")
452
  public T maxHedgedAttempts(int maxHedgedAttempts) {
453
    throw new UnsupportedOperationException();
×
454
  }
455

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

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

491

492
  /**
493
   * Disables the retry and hedging subsystem provided by the gRPC library. This is designed for the
494
   * case when users have their own retry implementation and want to avoid their own retry taking
495
   * place simultaneously with the gRPC library layer retry.
496
   *
497
   * @return this
498
   * @since 1.11.0
499
   */
500
  public T disableRetry() {
501
    throw new UnsupportedOperationException();
×
502
  }
503

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

518
  /**
519
   * Sets the BinaryLog object that this channel should log to. The channel does not take
520
   * ownership of the object, and users are responsible for calling {@link BinaryLog#close()}.
521
   *
522
   * @param binaryLog the object to provide logging.
523
   * @return this
524
   * @since 1.13.0
525
   */
526
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4017")
527
  public T setBinaryLog(BinaryLog binaryLog) {
528
    throw new UnsupportedOperationException();
×
529
  }
530

531
  /**
532
   * Sets the maximum number of channel trace events to keep in the tracer for each channel or
533
   * subchannel. If set to 0, channel tracing is effectively disabled.
534
   *
535
   * @return this
536
   * @since 1.13.0
537
   */
538
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/4471")
539
  public T maxTraceEvents(int maxTraceEvents) {
540
    throw new UnsupportedOperationException();
×
541
  }
542

543
  /**
544
   * Sets the proxy detector to be used in addresses name resolution. If <code>null</code> is passed
545
   * the default proxy detector will be used.  For how proxies work in gRPC, please refer to the
546
   * documentation on {@link ProxyDetector}.
547
   *
548
   * @return this
549
   * @since 1.19.0
550
   */
551
  public T proxyDetector(ProxyDetector proxyDetector) {
552
    throw new UnsupportedOperationException();
×
553
  }
554

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

614
  /**
615
   * Disables service config look-up from the naming system, which is enabled by default.
616
   *
617
   * @return this
618
   * @since 1.20.0
619
   */
620
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/5189")
621
  public T disableServiceConfigLookUp() {
622
    throw new UnsupportedOperationException();
×
623
  }
624

625
  /**
626
   * Adds a {@link MetricSink} for channel to use for configuring and recording metrics.
627
   *
628
   * @return this
629
   * @since 1.64.0
630
   */
631
  @ExperimentalApi("https://github.com/grpc/grpc-java/issues/11110")
632
  public T addMetricSink(MetricSink metricSink) {
633
    throw new UnsupportedOperationException();
×
634
  }
635

636

637
  /**
638
   * Builds a channel using the given parameters.
639
   *
640
   * @since 1.0.0
641
   */
642
  public abstract ManagedChannel build();
643

644
  /**
645
   * Returns the correctly typed version of the builder.
646
   */
647
  private T thisT() {
648
    @SuppressWarnings("unchecked")
649
    T thisT = (T) this;
×
650
    return thisT;
×
651
  }
652
}
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

© 2025 Coveralls, Inc