guohao commented on code in PR #9968: URL: https://github.com/apache/dubbo/pull/9968#discussion_r857434838
########## dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/transport/TripleClientHandler.java: ########## @@ -22,23 +22,60 @@ import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http2.DefaultHttp2PingFrame; +import io.netty.handler.codec.http2.Http2FrameCodec; import io.netty.handler.codec.http2.Http2GoAwayFrame; +import io.netty.handler.codec.http2.Http2PingFrame; import io.netty.util.ReferenceCountUtil; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + public class TripleClientHandler extends ChannelDuplexHandler { + static final long CLIENT_SCHEDULE_PING = 0x1141a85a98L; + private final FrameworkModel frameworkModel; - public TripleClientHandler(FrameworkModel frameworkModel) { + private Http2FrameCodec codec; + + private ScheduledExecutorService pingExecutor; + + private int heartbeatInterval; + + private int lossConnectCount = 0; + + public TripleClientHandler(FrameworkModel frameworkModel, Http2FrameCodec codec, + int heartbeatInterval) { this.frameworkModel = frameworkModel; + this.codec = codec; + this.heartbeatInterval = heartbeatInterval; } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + lossConnectCount = 0; if (msg instanceof Http2GoAwayFrame) { final ConnectionHandler connectionHandler = ctx.pipeline().get(ConnectionHandler.class); connectionHandler.onGoAway(ctx.channel()); } ReferenceCountUtil.release(msg); } + + @Override + public void channelActive(ChannelHandlerContext ctx) { + + pingExecutor.schedule(() -> { + if (codec.connection().numActiveStreams() <= 0 && lossConnectCount > 2) { Review Comment: The `schedule` may lead to too many ping tasks -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org