如何为" slave"引导netty频道应用

时间:2014-08-01 16:33:41

标签: netty

我想实施一个网络"奴隶"侦听传出 websocket连接上的请求的应用程序。所以在bootstrap上,应用程序会:

  1. 打开与远程服务器的ws连接
  2. 使用"老板"在ws连接上侦听命令事件循环
  3. 处理"工人"上的命令。事件循环
  4. 我的问题是如何提升频道 - 为了方便起见,我宁愿使用引导对象(我的意思是手动配置频道),但是:

    1. ServerBootstrap需要本地侦听套接字
    2. Bootstrap只有一个eventloop
    3. AbstractBootstrap无法在包外部进行子类化,ServerBootstrap / Bootstrap是最终的
    4. 有关如何在不复制大量现有* Bootstrap代码的情况下引导通道的任何建议吗?

1 个答案:

答案 0 :(得分:0)

我最终通过ChannelPipeline.html.addLast()将EventExecutorGroup直接传递给管道 - 我在api文档中错过了这个。

来自javadocs:

static final EventExecutorGroup group = new DefaultEventExecutorGroup(16);
...

ChannelPipeline pipeline = ch.pipeline();

pipeline.addLast("decoder", new MyProtocolDecoder());
pipeline.addLast("encoder", new MyProtocolEncoder());

// Tell the pipeline to run MyBusinessLogicHandler's event handler methods
// in a different thread than an I/O thread so that the I/O thread is not blocked by
// a time-consuming task.
// If your business logic is fully asynchronous or finished very quickly, you don't
// need to specify a group.
pipeline.addLast(group, "handler", new MyBusinessLogicHandler());