我在这里看到了常见问题解答http://netty.io/4.0/guide/#faq.4但我正在寻找更多详细信息。(FAQ 中的代码摘录如下。)我认为DefaultEventExecutor
应该是DefaultEventExecutorGroup
,但我没有找到一个全面的解释,让我知道在MyHandler
课堂上放什么,或者如何处理更复杂的情况。
- 你在什么方面实施
MyHandler
?messageReceived
? - 信息如何从上一步 (
HttpChunkAggregator
) 流向MyHandler
? 换句话说,一个处理程序调用什么来将消息传递给下一个处理程序? - 如果有两个带有阻塞代码的处理程序,可以并行执行,你会怎么做,然后(我猜)将它们的结果组合到第三个处理程序中来编写响应?
[来自常见问题]
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