例如,Floodlight openflow堆栈使用Netty作为其IO,并定义了以下Pipeline工厂类。
public class OpenflowPipelineFactory implements ChannelPipelineFactory {
protected Controller controller;
protected ThreadPoolExecutor pipelineExecutor;
protected Timer timer;
protected IdleStateHandler idleHandler;
protected ReadTimeoutHandler readTimeoutHandler;
public OpenflowPipelineFactory(Controller controller,
ThreadPoolExecutor pipelineExecutor) {
super();
this.controller = controller;
this.pipelineExecutor = pipelineExecutor;
this.timer = new HashedWheelTimer();
this.idleHandler = new IdleStateHandler(timer, 20, 25, 0);
this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30);
}
@Override
public ChannelPipeline getPipeline() throws Exception {
OFChannelState state = new OFChannelState();
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("ofmessagedecoder", new OFMessageDecoder());
pipeline.addLast("ofmessageencoder", new OFMessageEncoder());
pipeline.addLast("idle", idleHandler);
pipeline.addLast("timeout", readTimeoutHandler);
pipeline.addLast("handshaketimeout",
new HandshakeTimeoutHandler(state, timer, 15));
if (pipelineExecutor != null)
pipeline.addLast("pipelineExecutor",
new ExecutionHandler(pipelineExecutor));
pipeline.addLast("handler", controller.getChannelHandler(state));
return pipeline;
}
}
但实际上,由于Floodlight为构造函数的第二个参数赋予null,因此永远不会将执行处理程序和执行程序对象分配给管道。
...
final ServerBootstrap bootstrap = createServerBootStrap();
bootstrap.setOption("reuseAddr", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE);
ChannelPipelineFactory pfact = new OpenflowPipelineFactory(this, null);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(openFlowPort);
final ChannelGroup cg = new DefaultChannelGroup();
cg.add(bootstrap.bind(sa));
...
我的问题是,“如果没有管道执行器被设置为管道会发生什么?”假设有任何默认的管道执行器?如果是,OrderedMemoryAwareThreadPoolExecutor执行器总是被假设?
提前感谢您,等待Netty和Floodlight专家的一些帮助。
答案 0 :(得分:0)
如果ChannelPipeline中没有ExecutionHandler,IO线程将处理所有事件。如果添加了ExecutionHandler,则会在ExecutionHandler之后将事件卸载到处理程序的额外Thread-Pool。这允许阻止操作。