use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project apollo by apollo-rsps.
the class HttpChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("chunker", new HttpObjectAggregator(MAX_REQUEST_LENGTH));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("timeout", new IdleStateHandler(NetworkConstants.IDLE_TIME, 0, 0));
pipeline.addLast("handler", handler);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project apollo by apollo-rsps.
the class JagGrabChannelInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(MAX_REQUEST_LENGTH, DOUBLE_LINE_FEED_DELIMITER));
pipeline.addLast("string-decoder", new StringDecoder(JAGGRAB_CHARSET));
pipeline.addLast("jaggrab-decoder", new JagGrabRequestDecoder());
pipeline.addLast("jaggrab-encoder", new JagGrabResponseEncoder());
pipeline.addLast("timeout", new IdleStateHandler(NetworkConstants.IDLE_TIME, 0, 0));
pipeline.addLast("handler", handler);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project elephant by yanghuijava.
the class NettyRemotingClient method start.
@Override
public void start() {
this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(nettyClientConfig.getClientWorkerThreads(), new ThreadFactory() {
private AtomicInteger threadIndex = new AtomicInteger(0);
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "NettyClientWorkerThread_" + this.threadIndex.incrementAndGet());
}
});
this.bootstrap.group(this.eventLoopGroupWorker).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_KEEPALIVE, false).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, nettyClientConfig.getConnectTimeoutMillis()).option(ChannelOption.SO_SNDBUF, nettyClientConfig.getClientSocketSndBufSize()).option(ChannelOption.SO_RCVBUF, nettyClientConfig.getClientSocketRcvBufSize()).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
// 编码
ch.pipeline().addLast(new NettyEncoder());
// 解码
ch.pipeline().addLast(new NettyDecoder());
// 心跳
ch.pipeline().addLast(new IdleStateHandler(0, 0, nettyClientConfig.getClientChannelMaxIdleTimeSeconds()));
// 业务处理
ch.pipeline().addLast(defaultEventExecutorGroup, new NettyConnectManageHandler(), new NettyClientHandler());
}
});
this.timer.schedule(new TimerTask() {
@Override
public void run() {
try {
NettyRemotingClient.this.scanResponseTable();
} catch (Throwable e) {
log.error("scanResponseTable exception:{}", e);
}
}
}, 1000 * 3, 1000);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project elephant by yanghuijava.
the class NettyRemotingServer method start.
@Override
public void start() {
this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(nettyServerConfig.getServerWorkerThreads(), new ThreadFactory() {
private AtomicInteger threadIndex = new AtomicInteger(0);
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "NettyServerCodecThread_" + this.threadIndex.incrementAndGet());
}
});
ServerBootstrap childHandler = this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupSelector).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 1024).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_KEEPALIVE, false).childOption(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize()).option(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize()).localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
// 编码
ch.pipeline().addLast(new NettyEncoder());
// 解码
ch.pipeline().addLast(new NettyDecoder());
// 心跳
ch.pipeline().addLast(new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()));
// 业务处理
ch.pipeline().addLast(defaultEventExecutorGroup, new NettyConnetManageHandler(), new NettyServerHandler());
}
});
if (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) {
childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
}
try {
ChannelFuture sync = this.serverBootstrap.bind().sync();
InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress();
this.port = addr.getPort();
log.info("netty server already started!monitor at port {}", this.port);
} catch (InterruptedException e1) {
throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.timeout.IdleStateHandler in project nuls by nuls-io.
the class NulsChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline p = socketChannel.pipeline();
p.addLast("idle", new IdleStateHandler(READ_IDEL_TIME_OUT, WRITE_IDEL_TIME_OUT, ALL_IDEL_TIME_OUT, TimeUnit.SECONDS));
// p.addLast("decoder", new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, MAX_FRAME_LENGTH, 4, 4, 6, 0, true));
// p.addLast("encoder0", new LengthFieldPrepender(8, false));
p.addLast("decoder", new NulsMessageDecoder());
p.addLast("encoder0", new NulsMessageEncoder());
p.addLast("heartbeat", new HeartbeatServerHandler());
p.addLast(t);
}
Aggregations