代码如下:
/**
* Invoked when a{@link Channel}is open, but not bound nor connected.
*/
publicvoidchannelOpen(
ChannelHandlerContext ctx, ChannelStateEvent e)throwsException {
ctx.sendUpstream(e);
}
表明这是一个上行事件。
那么什么时候会触发这个行为呢?
------------------------------------------------------------------------------------------------
java.lang.Exception
at org.jboss.netty.channel.SimpleChannelHandler.channelOpen(SimpleChannelHandler.java:172)
at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:111)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559)
at org.jboss.netty.channel.Channels.fireChannelOpen(Channels.java:170)
at org.jboss.netty.channel.socket.nio.NioAcceptedSocketChannel.(NioAcceptedSocketChannel.java:42)
at org.jboss.netty.channel.socket.nio.NioServerBoss.registerAcceptedChannel(NioServerBoss.java:140)
at org.jboss.netty.channel.socket.nio.NioServerBoss.process(NioServerBoss.java:104)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:1)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
从这个堆栈可以分析出,这个事件的意义:
NioServerBoss线程运行时,如果有1个客户连接过来了,初始化NioAcceptedSocketChannel的时候,
调用NioAcceptedSocketChannel自身pipeline中对channelOpen事件的处理。