
cn.t.tool.nettytool.daemon.client.NettyTcpClient Maven / Gradle / Ivy
package cn.t.tool.nettytool.daemon.client;
import cn.t.tool.nettytool.daemon.listener.DaemonListener;
import cn.t.util.common.CollectionUtil;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.AttributeKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class NettyTcpClient extends AbstractDaemonClient {
private static final Logger logger = LoggerFactory.getLogger(NettyTcpClient.class);
private final ChannelInitializer channelInitializer;
private Channel clientChannel;
private final Map, Object> childAttrs = new ConcurrentHashMap<>();
@Override
public void doStart() {
EventLoopGroup workerGroup = new NioEventLoopGroup(1);
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(workerGroup)
.channel(NioSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, true)
.handler(channelInitializer);
if(!CollectionUtil.isEmpty(childAttrs)) {
for(Map.Entry, Object> entry: childAttrs.entrySet()) {
@SuppressWarnings("unchecked")
AttributeKey
© 2015 - 2025 Weber Informatics LLC | Privacy Policy