io.netty.channel.socket.nio.NioSocketChannel#pipeline ( )源码实例Demo

下面列出了io.netty.channel.socket.nio.NioSocketChannel#pipeline ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: api-gateway-core   文件: BackPoolHandler.java
@Override
    public void channelCreated(Channel ch) throws Exception {
        logger.debug("channelCreated. Channel ID: {}", ch.id());
        NioSocketChannel channel = (NioSocketChannel) ch;
        channel.config().setKeepAlive(true);
        channel.config().setTcpNoDelay(true);
        ChannelPipeline pipeline = channel.pipeline();
        if (sslCtx != null) {
            pipeline.addLast(sslCtx.newHandler(ch.alloc()));
        }
        pipeline.addLast(new HttpClientCodec());
        pipeline.addLast(new HttpContentDecompressor());
        pipeline.addLast(new HttpObjectAggregator(1024 * 1024 * 64));
        pipeline.addLast(new ChunkedWriteHandler());
//        pipeline.addLast(new ReadTimeoutHandler(requestHolder.route.getTimeoutInMilliseconds(), TimeUnit.MILLISECONDS));
        pipeline.addLast(new BackHandler());
    }
 
源代码2 项目: protools   文件: HttpClientChannelPoolHandler.java
@Override
public void channelCreated(Channel channel) {

    NioSocketChannel nioSocketChannel = (NioSocketChannel) channel;
    nioSocketChannel.config().setTcpNoDelay(true).setKeepAlive(true);

    final ChannelPipeline p = nioSocketChannel.pipeline();

    //HTTPS
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(channel.alloc()));
    }

    p.addLast(new HttpClientCodec(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE));

    p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
}
 
源代码3 项目: Okra   文件: GpbTcpServer.java
@Override
    protected ChannelHandler newChannelInitializer() {
        return new ChannelInitializer<NioSocketChannel>() {
            @Override
            protected void initChannel(NioSocketChannel ch) throws Exception {
                ChannelPipeline cp = ch.pipeline();
                cp.addLast("frame", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2));
                cp.addLast("prepender", FRAME_PREPENDER);
                cp.addLast("decoder", GPB_DECODER_HANDLER);
                cp.addLast("encoder", GPB_ENCODER_HANDLER);
                // handler
                cp.addLast("handler", serverHandler);
//                cp.addLast("handler", new ServerHandler());
            }
        };
    }
 
源代码4 项目: Okra   文件: PlacementServer.java
@Override
protected ChannelHandler newChannelInitializer() {
    return new ChannelInitializer<NioSocketChannel>() {
        @Override
        protected void initChannel(NioSocketChannel ch) throws Exception {
            ChannelPipeline cp = ch.pipeline();
            cp.addLast("frame", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2));
            cp.addLast("prepender", new LengthFieldPrepender(2, false));
            // Any other useful handler
            cp.addLast("strDecoder", STRING_DECODER);
            cp.addLast("strEncoder", STRING_ENCODER);
            cp.addLast("handler", new DisruptorAdapterBy41xHandler<JsonRequest>() {
                protected Executor newExecutor(Session session, JsonRequest msg) {
                    return new Executor() {
                        @Override
                        @SuppressWarnings("unchecked")
                        public void onExecute() {
                            try {
                                Command command = serviceManager.getCommand(msg.getApi());
                                if (command == null) {
                                    LOG.warn("Command is not exist. API : ", msg.getApi());
                                    return;
                                }
                                command.execute(session, msg);
                            } catch (Exception e) {
                                LOG.error("Error occured by execute command.", e);
                            }
                        }

                        @Override
                        public void release() {

                        }
                    };
                }
            });
        }
    };
}
 
源代码5 项目: Okra   文件: TcpServer.java
@Override
protected ChannelHandler newChannelInitializer() {
    return new ChannelInitializer<NioSocketChannel>() {
        @Override
        protected void initChannel(NioSocketChannel ch) throws Exception {
            ChannelPipeline cp = ch.pipeline();
            cp.addLast("frame", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2));
            cp.addLast("prepender", FRAME_PREPENDER);
            // Any other useful handler
            cp.addLast("handler", new ExampleSocketHandler());
        }
    };
}
 
源代码6 项目: Okra   文件: BenchmarkClient.java
@Override
protected ChannelHandler newChannelInitializer() {
    return new ChannelInitializer<NioSocketChannel>() {
        @Override
        protected void initChannel(NioSocketChannel ch) throws Exception {
            ChannelPipeline cp = ch.pipeline();
            cp.addLast("frame", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2));
            cp.addLast("prepender", FRAME_PREPENDER);
            // Any other useful handler
            cp.addLast("strDecoder", STRING_DECODER);
            cp.addLast("strEncoder", STRING_ENCODER);
            cp.addLast("handler", new SimpleChannelInboundHandler<String>() {
                @Override
                protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
                    COUNT.getAndIncrement();
                    ChannelPromise voidPromise = ctx.voidPromise();
                    if (ctx.channel().isWritable()) {
                        ctx.writeAndFlush(msg, voidPromise);
                    } else {
                        ctx.channel().eventLoop().schedule(() -> {
                            ctx.writeAndFlush(msg, voidPromise);
                        }, 1L, TimeUnit.SECONDS);
                    }
                }
            });
        }
    };
}
 
源代码7 项目: Okra   文件: BenchmarkServer.java
@Override
protected ChannelHandler newChannelInitializer() {
    return new ChannelInitializer<NioSocketChannel>() {
            @Override
            protected void initChannel(NioSocketChannel ch) throws Exception {
                ChannelPipeline cp = ch.pipeline();
                cp.addLast("frame", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2));
                cp.addLast("prepender", FRAME_PREPENDER);
                // Any other useful handler
                cp.addLast("strDecoder", STRING_DECODER);
                cp.addLast("strEncoder", STRING_ENCODER);
                cp.addLast("handler", HANDLER);
            }
    };
}
 
源代码8 项目: Okra   文件: HttpServer.java
@Override
protected ChannelHandler newChannelInitializer() {
    return new ChannelInitializer<NioSocketChannel>() {
        @Override
        protected void initChannel(NioSocketChannel ch) throws Exception {
            ChannelPipeline cp = ch.pipeline();
            cp.addLast("decoder", new HttpRequestDecoder());
            cp.addLast("encoder", new HttpResponseEncoder());
            cp.addLast("aggregator", new HttpObjectAggregator(1048576));
            cp.addLast("handler", new ExampleApiHandler());
        }
    };
}