我在这里看到常见问题http://netty.io/4.0/guide/#faq.4,但我正在寻找更多细节。 (摘自下面的常见问题解答代码。)
我假设DefaultEventExecutor
应该是DefaultEventExecutorGroup
,但我找不到一个总体解释,让我知道要放在MyHandler
课程中的内容,或者如何处理更复杂的情况。
MyHandler
中实施了什么? messageReceived
? HttpChunkAggregator
)流向MyHandler
?换句话说,一个处理程序调用什么来将消息传递给下一个处理程序? [来自FAQ]
public static void main(String[] args) throws Exception {
final EventExecutor executor = new DefaultEventExecutor(8);
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup());
bootstrap.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel channel) {
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
// MyHandler contains code that blocks so add it with the
// EventExecutor to the pipeline.
pipeline.addLast(executor, "handler", new MyHandler());
}
});
sb.bind(socketAddress);
// Other code
}
public class MyHandler extends SimpleChannelUpstreamHandler {
// Your blocking application code
答案 0 :(得分:0)
BlockingReadHandler
可能会给你一个想法,虽然它是3.x.它已从4.0中删除,因为它不是很有用 - 大多数人只是想保持异步。还请注意,使用基于反应器的框架模拟阻塞操作只会因为上下文切换增加而降低性能。