use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project pancm_project by xuwujing.
the class NettyServerFilter method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline ph = ch.pipeline();
// 处理http服务的关键handler
ph.addLast("encoder", new HttpResponseEncoder());
ph.addLast("decoder", new HttpRequestDecoder());
ph.addLast("aggregator", new HttpObjectAggregator(10 * 1024 * 1024));
// 服务端业务逻辑
ph.addLast("handler", new NettyServerHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project pancm_project by xuwujing.
the class NettyClientFilter method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline ph = ch.pipeline();
/*
* 解码和编码,应和服务端一致
* */
// ph.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
ph.addLast("decoder", new StringDecoder());
ph.addLast("encoder", new StringEncoder());
// 客户端的逻辑
ph.addLast("handler", new NettyClientHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project pancm_project by xuwujing.
the class NettyServerDemo4 method start.
/**
* Start.
*/
public void start() {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap sbs = new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).localAddress(new InetSocketAddress(port)).childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new StringDecoder());
// 绑定自定义业务逻辑
p.addLast(new NettyServerHandlerDemo4());
}
}).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
// 绑定端口,开始接收进来的连接
ChannelFuture future = sbs.bind(port).sync();
System.out.println("Netty服务端启动成功,端口为: " + port);
// 释放监听
future.channel().closeFuture().sync();
} catch (Exception e) {
// 释放资源
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project wso2-synapse by wso2.
the class ChannelPipelineInitializer method initializeHttpConsumerChannel.
private void initializeHttpConsumerChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast("sslHandler", sslCtx.newHandler(ch.alloc()));
}
pipeline.addLast(new HttpServerCodec());
if (consumerContext.getLogicHandler() != null) {
pipeline.addLast("logicHandler", consumerContext.getLogicHandler());
}
pipeline.addLast("httpResponseHandler", new org.apache.synapse.commons.emulator.http.consumer.HttpResponseProcessHandler(consumerContext));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelPipeline in project tech by ffyyhh995511.
the class HelloClientInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
/*
* 这个地方的 必须和服务端对应上。否则无法正常解码和编码
*
* 解码和编码 我将会在下一张为大家详细的讲解。再次暂时不做详细的描述
*
* */
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
// 客户端的逻辑
pipeline.addLast("handler", new HelloClientHandler());
}
Aggregations