Search in sources :

Example 66 with IdleStateHandler

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);
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 67 with IdleStateHandler

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);
}
Also used : JagGrabResponseEncoder(org.apollo.net.codec.jaggrab.JagGrabResponseEncoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) DelimiterBasedFrameDecoder(io.netty.handler.codec.DelimiterBasedFrameDecoder) StringDecoder(io.netty.handler.codec.string.StringDecoder) JagGrabRequestDecoder(org.apollo.net.codec.jaggrab.JagGrabRequestDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 68 with IdleStateHandler

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);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) RemotingSendRequestException(com.yanghui.elephant.remoting.exception.RemotingSendRequestException) RemotingConnectException(com.yanghui.elephant.remoting.exception.RemotingConnectException) RemotingTimeoutException(com.yanghui.elephant.remoting.exception.RemotingTimeoutException) TimerTask(java.util.TimerTask) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler)

Example 69 with IdleStateHandler

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);
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ThreadFactory(java.util.concurrent.ThreadFactory) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler)

Example 70 with IdleStateHandler

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);
}
Also used : NulsMessageDecoder(io.nuls.network.netty.conn.serialization.NulsMessageDecoder) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) NulsMessageEncoder(io.nuls.network.netty.conn.serialization.NulsMessageEncoder) HeartbeatServerHandler(io.nuls.network.netty.conn.handler.HeartbeatServerHandler)

Aggregations

IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)70 ChannelPipeline (io.netty.channel.ChannelPipeline)35 SocketChannel (io.netty.channel.socket.SocketChannel)18 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)14 LoggingHandler (io.netty.handler.logging.LoggingHandler)14 SslHandler (io.netty.handler.ssl.SslHandler)14 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)12 ChannelFuture (io.netty.channel.ChannelFuture)10 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)10 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)9 Bootstrap (io.netty.bootstrap.Bootstrap)8 EventLoopGroup (io.netty.channel.EventLoopGroup)8 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)7 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)7 IdleStateEvent (io.netty.handler.timeout.IdleStateEvent)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 Channel (io.netty.channel.Channel)6 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 SslContext (io.netty.handler.ssl.SslContext)6 InetSocketAddress (java.net.InetSocketAddress)6