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

grpc / grpc-java / #20230

31 Mar 2026 09:55AM UTC coverage: 88.734% (+0.01%) from 88.72%
#20230

push

github

web-flow
openTelemetry: add tcp metrics (#12652)

Implements [A80](https://github.com/grpc/proposal/pull/519)

35697 of 40229 relevant lines covered (88.73%)

0.89 hits per line

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

97.14
/../core/src/main/java/io/grpc/internal/ClientTransportFactory.java
1
/*
2
 * Copyright 2014 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.internal;
18

19
import com.google.common.base.Objects;
20
import com.google.common.base.Preconditions;
21
import com.google.errorprone.annotations.CheckReturnValue;
22
import io.grpc.Attributes;
23
import io.grpc.CallCredentials;
24
import io.grpc.ChannelCredentials;
25
import io.grpc.ChannelLogger;
26
import io.grpc.HttpConnectProxiedSocketAddress;
27
import io.grpc.MetricRecorder;
28
import java.io.Closeable;
29
import java.net.SocketAddress;
30
import java.util.Collection;
31
import java.util.concurrent.ScheduledExecutorService;
32
import javax.annotation.Nullable;
33

34
/** Pre-configured factory for creating {@link ConnectionClientTransport} instances. */
35
public interface ClientTransportFactory extends Closeable {
36
  /**
37
   * Creates an unstarted transport for exclusive use. Ownership of {@code options} is passed to the
38
   * callee; the caller should not reuse or read from the options after this method is called.
39
   *
40
   * @param serverAddress the address that the transport is connected to
41
   * @param options additional configuration
42
   * @param channelLogger logger for the transport.
43
   */
44
  ConnectionClientTransport newClientTransport(
45
      SocketAddress serverAddress,
46
      ClientTransportOptions options,
47
      ChannelLogger channelLogger);
48

49
  /**
50
   * Returns an executor for scheduling provided by the transport. The service should be configured
51
   * to allow cancelled scheduled runnables to be GCed.
52
   *
53
   * <p>The executor should not be used after the factory has been closed. The caller should ensure
54
   * any outstanding tasks are cancelled before the factory is closed. However, it is a
55
   * <a href="https://github.com/grpc/grpc-java/issues/1981">known issue</a> that ClientCallImpl may
56
   * use this executor after close, so implementations should not go out of their way to prevent
57
   * usage.
58
   */
59
  ScheduledExecutorService getScheduledExecutorService();
60

61
  /**
62
   * Swaps to a new ChannelCredentials with all other settings unchanged. Returns null if the
63
   * ChannelCredentials is not supported by the current ClientTransportFactory settings.
64
   */
65
  @CheckReturnValue
66
  @Nullable
67
  SwapChannelCredentialsResult swapChannelCredentials(ChannelCredentials channelCreds);
68

69
  /**
70
   * Releases any resources.
71
   *
72
   * <p>After this method has been called, it's no longer valid to call
73
   * {@link #newClientTransport}. No guarantees about thread-safety are made.
74
   */
75
  @Override
76
  void close();
77

78
  /**
79
   * Returns the {@link SocketAddress} types this transport supports.
80
   */
81
  Collection<Class<? extends SocketAddress>> getSupportedSocketAddressTypes();
82

83
  /**
84
   * Options passed to {@link #newClientTransport}. Although it is safe to save this object if
85
   * received, it is generally expected that the useful fields are copied and then the options
86
   * object is discarded. This allows using {@code final} for those fields as well as avoids
87
   * retaining unused objects contained in the options.
88
   */
89
  final class ClientTransportOptions {
1✔
90
    private ChannelLogger channelLogger;
91
    private String authority = "unknown-authority";
1✔
92
    private Attributes eagAttributes = Attributes.EMPTY;
1✔
93
    @Nullable private String userAgent;
94
    @Nullable private HttpConnectProxiedSocketAddress connectProxiedSocketAddr;
95
    private MetricRecorder metricRecorder = new MetricRecorder() {
1✔
96
    };
97

98
    public ChannelLogger getChannelLogger() {
99
      return channelLogger;
×
100
    }
101

102
    public ClientTransportOptions setChannelLogger(ChannelLogger channelLogger) {
103
      this.channelLogger = channelLogger;
1✔
104
      return this;
1✔
105
    }
106

107
    public MetricRecorder getMetricRecorder() {
108
      return metricRecorder;
1✔
109
    }
110

111
    public ClientTransportOptions setMetricRecorder(MetricRecorder metricRecorder) {
112
      this.metricRecorder = Preconditions.checkNotNull(metricRecorder, "metricRecorder");
1✔
113
      return this;
1✔
114
    }
115

116
    public String getAuthority() {
117
      return authority;
1✔
118
    }
119

120
    /** Sets the non-null authority. */
121
    public ClientTransportOptions setAuthority(String authority) {
122
      this.authority = Preconditions.checkNotNull(authority, "authority");
1✔
123
      return this;
1✔
124
    }
125

126
    public Attributes getEagAttributes() {
127
      return eagAttributes;
1✔
128
    }
129

130
    /** Sets the non-null EquivalentAddressGroup's attributes. */
131
    public ClientTransportOptions setEagAttributes(Attributes eagAttributes) {
132
      Preconditions.checkNotNull(eagAttributes, "eagAttributes");
1✔
133
      this.eagAttributes = eagAttributes;
1✔
134
      return this;
1✔
135
    }
136

137
    @Nullable
138
    public String getUserAgent() {
139
      return userAgent;
1✔
140
    }
141

142
    public ClientTransportOptions setUserAgent(@Nullable String userAgent) {
143
      this.userAgent = userAgent;
1✔
144
      return this;
1✔
145
    }
146

147
    @Nullable
148
    public HttpConnectProxiedSocketAddress getHttpConnectProxiedSocketAddress() {
149
      return connectProxiedSocketAddr;
1✔
150
    }
151

152
    public ClientTransportOptions setHttpConnectProxiedSocketAddress(
153
        @Nullable HttpConnectProxiedSocketAddress connectProxiedSocketAddr) {
154
      this.connectProxiedSocketAddr = connectProxiedSocketAddr;
1✔
155
      return this;
1✔
156
    }
157

158
    @Override
159
    public int hashCode() {
160
      return Objects.hashCode(authority, eagAttributes, userAgent, connectProxiedSocketAddr);
1✔
161
    }
162

163
    @Override
164
    public boolean equals(Object o) {
165
      if (!(o instanceof ClientTransportOptions)) {
1✔
166
        return false;
1✔
167
      }
168
      ClientTransportOptions that = (ClientTransportOptions) o;
1✔
169
      return this.authority.equals(that.authority)
1✔
170
          && this.eagAttributes.equals(that.eagAttributes)
1✔
171
          && Objects.equal(this.userAgent, that.userAgent)
1✔
172
          && Objects.equal(this.connectProxiedSocketAddr, that.connectProxiedSocketAddr);
1✔
173
    }
174
  }
175

176
  final class SwapChannelCredentialsResult {
177
    final ClientTransportFactory transportFactory;
178
    @Nullable final CallCredentials callCredentials;
179

180
    public SwapChannelCredentialsResult(
181
        ClientTransportFactory transportFactory, @Nullable CallCredentials callCredentials) {
1✔
182
      this.transportFactory = Preconditions.checkNotNull(transportFactory, "transportFactory");
1✔
183
      this.callCredentials = callCredentials;
1✔
184
    }
1✔
185
  }
186
}
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