2626import io .grpc .Context ;
2727import io .grpc .Grpc ;
2828import io .grpc .ManagedChannel ;
29+ import io .grpc .ManagedChannelBuilder ;
2930import io .grpc .Metadata ;
3031import io .grpc .MethodDescriptor ;
32+ import io .grpc .Server ;
3133import io .grpc .Status ;
3234import io .grpc .xds .client .Bootstrapper ;
3335import io .grpc .xds .client .XdsTransportFactory ;
@@ -37,15 +39,19 @@ final class GrpcXdsTransportFactory implements XdsTransportFactory {
3739
3840 private final CallCredentials callCredentials ;
3941 private final ManagedChannel parentChannel ;
42+ private final Server parentServer ;
4043
41- GrpcXdsTransportFactory (CallCredentials callCredentials , ManagedChannel parentChannel ) {
44+
45+ GrpcXdsTransportFactory (CallCredentials callCredentials , ManagedChannel parentChannel ,
46+ Server parentServer ) {
4247 this .callCredentials = callCredentials ;
4348 this .parentChannel = parentChannel ;
49+ this .parentServer = parentServer ;
4450 }
4551
4652 @ Override
4753 public XdsTransport create (Bootstrapper .ServerInfo serverInfo ) {
48- return new GrpcXdsTransport (serverInfo , callCredentials , parentChannel );
54+ return new GrpcXdsTransport (serverInfo , callCredentials , parentChannel , parentServer );
4955 }
5056
5157 @ VisibleForTesting
@@ -78,13 +84,17 @@ public GrpcXdsTransport(Bootstrapper.ServerInfo serverInfo, CallCredentials call
7884 }
7985
8086 public GrpcXdsTransport (Bootstrapper .ServerInfo serverInfo , CallCredentials callCredentials ,
81- ManagedChannel parentChannel ) {
87+ ManagedChannel parentChannel , Server parentServer ) {
8288 String target = serverInfo .target ();
8389 ChannelCredentials channelCredentials = (ChannelCredentials ) serverInfo .implSpecificConfig ();
84- this .channel = Grpc .newChannelBuilder (target , channelCredentials )
85- .keepAliveTime (5 , TimeUnit .MINUTES )
86- .configureChannel (parentChannel )
87- .build ();
90+ ManagedChannelBuilder <?> channelBuilder = Grpc .newChannelBuilder (target , channelCredentials )
91+ .keepAliveTime (5 , TimeUnit .MINUTES );
92+ if (parentChannel != null ) {
93+ channelBuilder .configureChannel (parentChannel );
94+ } else if (parentServer != null ) {
95+ channelBuilder .configureChannel (parentServer );
96+ }
97+ this .channel = channelBuilder .build ();
8898 this .callCredentials = callCredentials ;
8999 }
90100
0 commit comments