21
21
import io .grpc .ClientCall ;
22
22
import io .grpc .ManagedChannel ;
23
23
import io .grpc .MethodDescriptor ;
24
+ import io .grpc .internal .GrpcUtil ;
24
25
import io .grpc .internal .SharedResourceHolder .Resource ;
25
26
import io .grpc .netty .NettyChannelBuilder ;
26
27
import io .netty .channel .EventLoopGroup ;
@@ -45,6 +46,9 @@ static Resource<Channel> getHandshakerChannelForTesting(String handshakerAddress
45
46
return new ChannelResource (handshakerAddress );
46
47
}
47
48
49
+ private static final boolean EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS =
50
+ GrpcUtil .getFlag ("GRPC_EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS" , false );
51
+
48
52
private static class ChannelResource implements Resource <Channel > {
49
53
private final String target ;
50
54
@@ -57,12 +61,16 @@ public Channel create() {
57
61
/* Use its own event loop thread pool to avoid blocking. */
58
62
EventLoopGroup eventGroup =
59
63
new NioEventLoopGroup (1 , new DefaultThreadFactory ("handshaker pool" , true ));
60
- ManagedChannel channel = NettyChannelBuilder .forTarget (target )
64
+ NettyChannelBuilder channelBuilder =
65
+ NettyChannelBuilder .forTarget (target )
61
66
.channelType (NioSocketChannel .class , InetSocketAddress .class )
62
67
.directExecutor ()
63
68
.eventLoopGroup (eventGroup )
64
- .usePlaintext ()
65
- .build ();
69
+ .usePlaintext ();
70
+ if (EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS ) {
71
+ channelBuilder .keepAliveTime (10 , TimeUnit .MINUTES ).keepAliveTimeout (10 , TimeUnit .SECONDS );
72
+ }
73
+ ManagedChannel channel = channelBuilder .build ();
66
74
return new EventLoopHoldingChannel (channel , eventGroup );
67
75
}
68
76
0 commit comments