public boolean close(boolean needPrint) {
        this.conStatus.set(CLIENT_STATUS_DEAD);
        long curTime = System.currentTimeMillis();
        this.chanInvalidTime.set(curTime);
        final CountDownLatch awaitLatch = new CountDownLatch(1);
        boolean ret = true;
        String channelStr = "";
        try {
            if (channel == null) {
                channelStr = hostInfo.getReferenceName();
            } else {
                channelStr = channel.toString();
                ChannelFuture future = channel.close();
                future.addListener(new ChannelFutureListener() {

                    public void operationComplete(ChannelFuture arg0) throws Exception {
                        awaitLatch.countDown();
                    }
                });
                // Wait until the connection is close.
                awaitLatch.await(tcpConfig.getConCloseWaitPeriodMs(), TimeUnit.MILLISECONDS);
                // Return if close this connection fail.
                if (!future.isSuccess()) {
                    ret = false;
                }
            }
        } catch (Throwable ex) {
            if (conExptCnt.shouldPrint()) {
                logger.warn("NettyClient({}) close {} exception", senderId, channelStr, ex);
            }
            ret = false;
        } finally {
            this.channel = null;
            this.channelStr = "";
            this.msgInflightCnt.set(0);
        }
        if (needPrint) {
            if (ret) {
                logger.info("NettyClient({}) close {} success, wast {}ms",
                        this.senderId, channelStr, (System.currentTimeMillis() - curTime));
            } else {
                logger.info("NettyClient({}) close {} failure, wast {}ms",
                        this.senderId, channelStr, (System.currentTimeMillis() - curTime));
            }
        }
        return ret;
    }
TCP Netty client class

Used to manage TCP netty client, including connection, closing, keep-alive, sending status check, etc.
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/tcp/TcpNettyClient.java