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

grpc / grpc-java / #18883

03 Nov 2023 04:57PM UTC coverage: 88.246% (+0.03%) from 88.218%
#18883

push

github

web-flow
core, netty, okhttp: implement new logic for nameResolverFactory API in channelBuilder (#10590)

* core, netty, okhttp: implement new logic for nameResolverFactory API in channelBuilder
fix ManagedChannelImpl to use NameResolverRegistry instead of NameResolverFactory
fix the ManagedChannelImplBuilder and remove nameResolverFactory

* Integrate target parsing and NameResolverProvider searching

Actually creating the name resolver is now delayed to the end of
ManagedChannelImpl.getNameResolver; we don't want to call into the name
resolver to determine if we should use the name resolver.

Added getDefaultScheme() to NameResolverRegistry to avoid needing
NameResolver.Factory.
---------

Co-authored-by: Eric Anderson <ejona@google.com>

30370 of 34415 relevant lines covered (88.25%)

0.88 hits per line

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

44.83
/../netty/src/main/java/io/grpc/netty/InternalNettyChannelBuilder.java
1
/*
2
 * Copyright 2016 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.netty;
18

19
import com.google.common.annotations.VisibleForTesting;
20
import io.grpc.Internal;
21
import io.grpc.internal.ClientTransportFactory;
22
import io.grpc.internal.GrpcUtil;
23
import io.grpc.internal.SharedResourcePool;
24
import io.grpc.internal.TransportTracer;
25
import io.netty.channel.socket.nio.NioSocketChannel;
26
import java.net.InetSocketAddress;
27

28
/**
29
 * Internal {@link NettyChannelBuilder} accessor.  This is intended for usage internal to the gRPC
30
 * team.  If you *really* think you need to use this, contact the gRPC team first.
31
 */
32
@Internal
33
public final class InternalNettyChannelBuilder {
34

35
  public static void disableCheckAuthority(NettyChannelBuilder builder) {
36
    builder.disableCheckAuthority();
×
37
  }
×
38

39
  public static void enableCheckAuthority(NettyChannelBuilder builder) {
40
    builder.enableCheckAuthority();
×
41
  }
×
42

43
  /** A class that provides a Netty handler to control protocol negotiation. */
44
  public interface ProtocolNegotiatorFactory {
45
    InternalProtocolNegotiator.ProtocolNegotiator buildProtocolNegotiator();
46
  }
47

48
  /**
49
   * Sets the {@link ProtocolNegotiatorFactory} to be used. Overrides any specified negotiation type
50
   * and {@code SslContext}.
51
   */
52
  public static void setProtocolNegotiatorFactory(
53
      NettyChannelBuilder builder, final ProtocolNegotiatorFactory protocolNegotiator) {
54
    builder.protocolNegotiatorFactory(new ProtocolNegotiator.ClientFactory() {
1✔
55
      @Override public ProtocolNegotiator newNegotiator() {
56
        return protocolNegotiator.buildProtocolNegotiator();
1✔
57
      }
58

59
      @Override public int getDefaultPort() {
60
        return GrpcUtil.DEFAULT_PORT_SSL;
1✔
61
      }
62
    });
63
  }
1✔
64

65
  /**
66
   * Sets the {@link ProtocolNegotiatorFactory} to be used. Overrides any specified negotiation type
67
   * and {@code SslContext}.
68
   */
69
  public static void setProtocolNegotiatorFactory(
70
      NettyChannelBuilder builder, InternalProtocolNegotiator.ClientFactory protocolNegotiator) {
71
    builder.protocolNegotiatorFactory(protocolNegotiator);
×
72
  }
×
73

74
  public static void setStatsEnabled(NettyChannelBuilder builder, boolean value) {
75
    builder.setStatsEnabled(value);
1✔
76
  }
1✔
77

78
  public static void setTracingEnabled(NettyChannelBuilder builder, boolean value) {
79
    builder.setTracingEnabled(value);
×
80
  }
×
81

82
  public static void setStatsRecordStartedRpcs(NettyChannelBuilder builder, boolean value) {
83
    builder.setStatsRecordStartedRpcs(value);
×
84
  }
×
85

86
  public static void setStatsRecordFinishedRpcs(NettyChannelBuilder builder, boolean value) {
87
    builder.setStatsRecordFinishedRpcs(value);
×
88
  }
×
89

90
  public static void setStatsRecordRealTimeMetrics(NettyChannelBuilder builder, boolean value) {
91
    builder.setStatsRecordRealTimeMetrics(value);
×
92
  }
×
93

94
  public static void setStatsRecordRetryMetrics(NettyChannelBuilder builder, boolean value) {
95
    builder.setStatsRecordRetryMetrics(value);
×
96
  }
×
97

98
  /**
99
   * Sets {@link io.grpc.Channel} and {@link io.netty.channel.EventLoopGroup} to Nio. A major
100
   * benefit over using setters is gRPC will manage the life cycle of {@link
101
   * io.netty.channel.EventLoopGroup}.
102
   */
103
  public static void useNioTransport(NettyChannelBuilder builder) {
104
    builder.channelType(NioSocketChannel.class, InetSocketAddress.class);
1✔
105
    builder
1✔
106
        .eventLoopGroupPool(SharedResourcePool.forResource(Utils.NIO_WORKER_EVENT_LOOP_GROUP));
1✔
107
  }
1✔
108

109
  public static ClientTransportFactory buildTransportFactory(NettyChannelBuilder builder) {
110
    return builder.buildTransportFactory();
1✔
111
  }
112

113
  @VisibleForTesting
114
  public static void setTransportTracerFactory(
115
      NettyChannelBuilder builder, TransportTracer.Factory factory) {
116
    builder.setTransportTracerFactory(factory);
1✔
117
  }
1✔
118

119
  private InternalNettyChannelBuilder() {}
120
}
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