Fixed Javadoc of LifeCycleAwareChannelHandler

* Some handlers (e.g. SslHandler, ZlibEncoder) need to store its context somewhere, and they needed to implement both beforeAdd() and channelOpen() because beforeAdd() is not called if pipeline is not attached.  This led to code duplication.  To address this issue, ChannelPipeline now always calls the life cycle listeners whether it is attached or not
This commit is contained in:
Trustin Lee 2009-12-17 09:11:07 +00:00
parent f7606ffc31
commit 7048c51898

View File

@ -18,40 +18,6 @@ package org.jboss.netty.channel;
/**
* A {@link ChannelHandler} that is notified when it is added to or removed
* from a {@link ChannelPipeline}.
* <p>
* Please note that the methods of this handler is called only when the
* {@link ChannelPipeline} it belongs to has been
* {@linkplain ChannelPipeline#attach(Channel, ChannelSink) attached}.
* That is, if you add a {@link LifeCycleAwareChannelHandler} to the unattached
* {@link ChannelPipeline}, the life cycle handler methods in this handler will
* not be invoked because there's no associated {@link ChannelHandlerContext}:
* <pre>
* // Create a new pipeline which is unattached initially.
* ChannelPipeline pipeline = Channels.pipeline();
* // beforeAdd() and afterAdd() will not be called.
* pipeline.addLast("handler", new MyLifeCycleAwareChannelHandler());
* // beforeRemove() and afterRemove() will not be called.
* pipeline.remove("handler");
* </pre>
* However, once the {@link ChannelPipeline} is attached and the
* {@code channelOpen} event is fired, the life cycle handler methods will
* be invoked on addition or removal:
* <pre>
* public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent evt) {
* // channelOpen event has been triggered, which means the pipeline has
* // been attached to the channel.
* ChannelPipeline pipeline = ctx.getChannel().getPipeline();
* // beforeAdd() and afterAdd() will be called.
* pipeline.addLast("handler", new MyLifeCycleAwareChannelHandler());
* }
*
* public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent evt) {
* // Once attached, the pipeline is never detached.
* ChannelPipeline pipeline = ctx.getChannel().getPipeline();
* // beforeRemove() and afterRemove() will be called.
* pipeline.remove("handler");
* }
* </pre>
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (trustin@gmail.com)