From 65634bda11cf81e2287700dd4cdd6fd947060034 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 17 Dec 2009 10:19:09 +0000 Subject: [PATCH] * Better documentation for developers * Fixed a bug where a channelOpen event is swallowed --- .../org/jboss/netty/handler/timeout/IdleStateHandler.java | 8 +++++++- .../jboss/netty/handler/timeout/ReadTimeoutHandler.java | 7 ++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jboss/netty/handler/timeout/IdleStateHandler.java b/src/main/java/org/jboss/netty/handler/timeout/IdleStateHandler.java index 87ecb8c0ef..0d87b6da8e 100644 --- a/src/main/java/org/jboss/netty/handler/timeout/IdleStateHandler.java +++ b/src/main/java/org/jboss/netty/handler/timeout/IdleStateHandler.java @@ -202,7 +202,9 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler public void beforeAdd(ChannelHandlerContext ctx) throws Exception { if (ctx.getPipeline().isAttached()) { - // channelOpen() has been called already - initialize here instead. + // channelOpen event has been fired already, which means + // this.channelOpen() will not be invoked. + // We have to initialize here instead. initialize(ctx); } } @@ -222,7 +224,11 @@ public class IdleStateHandler extends SimpleChannelUpstreamHandler @Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { + // This method will be invoked only if this handler was added + // before channelOpen event is fired. If a user adds this handler + // after the channelOpen event, initialize() will be called by beforeAdd(). initialize(ctx); + ctx.sendUpstream(e); } @Override diff --git a/src/main/java/org/jboss/netty/handler/timeout/ReadTimeoutHandler.java b/src/main/java/org/jboss/netty/handler/timeout/ReadTimeoutHandler.java index eed2a39b9b..da3a996b94 100644 --- a/src/main/java/org/jboss/netty/handler/timeout/ReadTimeoutHandler.java +++ b/src/main/java/org/jboss/netty/handler/timeout/ReadTimeoutHandler.java @@ -121,7 +121,9 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler public void beforeAdd(ChannelHandlerContext ctx) throws Exception { if (ctx.getPipeline().isAttached()) { - // channelOpen() has been called already - initialize here instead. + // channelOpen event has been fired already, which means + // this.channelOpen() will not be invoked. + // We have to initialize here instead. initialize(ctx); } } @@ -141,6 +143,9 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler @Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { + // This method will be invoked only if this handler was added + // before channelOpen event is fired. If a user adds this handler + // after the channelOpen event, initialize() will be called by beforeAdd(). initialize(ctx); ctx.sendUpstream(e); }