3535import java .util .concurrent .ConcurrentHashMap ;
3636import java .util .concurrent .TimeUnit ;
3737
38+ /**
39+ * A factory for creating gRPC-based transports for xDS communication.
40+ *
41+ * <p>WARNING: This class reuses channels when possible, based on the provided {@link
42+ * Bootstrapper.ServerInfo} with important considerations. The {@link Bootstrapper.ServerInfo}
43+ * includes {@link ChannelCredentials}, which is compared by reference equality. This means every
44+ * {@link Bootstrapper.BootstrapInfo} would have non-equal copies of {@link
45+ * Bootstrapper.ServerInfo}, even if they all represent the same xDS server configuration. For gRPC
46+ * name resolution with the {@code xds} and {@code google-c2p} scheme, this transport sharing works
47+ * as expected as it internally reuses a single {@link Bootstrapper.BootstrapInfo} instance.
48+ * Otherwise, new transports would be created for each {@link Bootstrapper.ServerInfo} despite them
49+ * possibly representing the same xDS server configuration and defeating the purpose of transport
50+ * sharing.
51+ */
3852final class GrpcXdsTransportFactory implements XdsTransportFactory {
3953
4054 private final CallCredentials callCredentials ;
@@ -44,14 +58,6 @@ final class GrpcXdsTransportFactory implements XdsTransportFactory {
4458 // NOTE: ConcurrentHashMap is used as a per-entry lock and all reads and writes must be a mutation
4559 // via the ConcurrentHashMap APIs to acquire the per-entry lock in order to ensure thread safety
4660 // for reference counting of each GrpcXdsTransport instance.
47- //
48- // WARNING: ServerInfo includes ChannelCredentials, which is compared by reference equality.
49- // This means every BootstrapInfo would have non-equal copies of ServerInfo, even if they all
50- // represent the same xDS server configuration. For gRPC name resolution with the `xds` and
51- // `google-c2p` scheme, this transport sharing works as expected as it internally reuses a single
52- // BootstrapInfo instance. Otherwise, new transports would be created for each ServerInfo despite
53- // them possibly representing the same xDS server configuration and defeating the purpose of
54- // transport sharing.
5561 private static final Map <Bootstrapper .ServerInfo , GrpcXdsTransport > xdsServerInfoToTransportMap =
5662 new ConcurrentHashMap <>();
5763
0 commit comments