Fix javadocs for ChannelPipeline

This commit is contained in:
Norman Maurer 2012-12-23 15:54:30 +01:00
parent 7d79587ade
commit 6ef1729d06

View File

@ -20,7 +20,6 @@ import io.netty.buffer.MessageBuf;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.channels.Channels;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -28,7 +27,7 @@ import java.util.NoSuchElementException;
/** /**
* A list of {@link ChannelHandler}s which handles or intercepts * A list of {@link ChannelHandler}s which handles or intercepts
* {@link ChannelEvent}s of a {@link Channel}. {@link ChannelPipeline} * inbound and outbount operations of a {@link Channel}. {@link ChannelPipeline}
* implements an advanced form of the * implements an advanced form of the
* <a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.html">Intercepting * <a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/InterceptingFilter.html">Intercepting
* Filter</a> pattern to give a user full control over how an event is handled * Filter</a> pattern to give a user full control over how an event is handled
@ -36,69 +35,64 @@ import java.util.NoSuchElementException;
* *
* <h3>Creation of a pipeline</h3> * <h3>Creation of a pipeline</h3>
* *
* For each new channel, a new pipeline must be created and attached to the * For each new channel, a new pipeline iscreated and attached to the
* channel. Once attached, the coupling between the channel and the pipeline * channel. Once attached, the coupling between the channel and the pipeline
* is permanent; the channel cannot attach another pipeline to it nor detach * is permanent; the channel cannot attach another pipeline to it nor detach
* the current pipeline from it. * the current pipeline from it. All of this is handled for you and you not need
* to take care of this.
* <p> * <p>
* The recommended way to create a new pipeline is to use the helper methods in *
* {@link Channels} rather than calling an individual implementation's
* constructor:
* <pre>
* import static io.netty.channel.{@link Channels}.*;
* {@link ChannelPipeline} pipeline = pipeline(); // same with Channels.pipeline()
* </pre>
* *
* <h3>How an event flows in a pipeline</h3> * <h3>How an event flows in a pipeline</h3>
* *
* The following diagram describes how {@link ChannelEvent}s are processed by * The following diagram describes how I/O is processed by
* {@link ChannelHandler}s in a {@link ChannelPipeline} typically. * {@link ChannelHandler}s in a {@link ChannelPipeline} typically.
* A {@link ChannelEvent} can be handled by either a {@link ChannelUpstreamHandler} * A I/O-operation can be handled by either a {@link ChannelInboundHandler}
* or a {@link ChannelDownstreamHandler} and be forwarded to the closest * or a {@link ChannelOutboundHandler} and be forwarded to the closest
* handler by calling {@link ChannelHandlerContext#sendUpstream(ChannelEvent)} * handler by calling either one of the methods defined in the
* or {@link ChannelHandlerContext#sendDownstream(ChannelEvent)}. The meaning * {@link ChannelInboundInvoker} interface for inbound I/O or by one
* of the event is interpreted somewhat differently depending on whether it is * of the methods defined in the {@link ChannelOutboundInvoker} interface
* going upstream or going downstream. Please refer to {@link ChannelEvent} for * for outbound I/O. {@link ChannelPipeline} extends both of them.
* more information. *
* <pre> * <pre>
* I/O Request * I/O Request
* via {@link Channel} or * via {@link Channel} or
* {@link ChannelHandlerContext} * {@link ChannelHandlerContext}
* | * |
* +----------------------------------------+---------------+ * +----------------------------------------------------+-----------------+
* | ChannelPipeline | | * | ChannelPipeline | |
* | \|/ | * | \|/ |
* | +----------------------+ +-----------+------------+ | * | +----------------------+ +-----------+------------+ |
* | | Upstream Handler N | | Downstream Handler 1 | | * | | Inbound Handler N | | Outbound Handler 1 | |
* | +----------+-----------+ +-----------+------------+ | * | +----------+-----------+ +-----------+------------+ |
* | /|\ | | * | /|\ | |
* | | \|/ | * | | \|/ |
* | +----------+-----------+ +-----------+------------+ | * | +----------+-----------+ +-----------+------------+ |
* | | Upstream Handler N-1 | | Downstream Handler 2 | | * | | Inbound Handler N-1 | | Outbound Handler 2 | |
* | +----------+-----------+ +-----------+------------+ | * | +----------+-----------+ +-----------+------------+ |
* | /|\ . | * | /|\ . |
* | . . | * | . . |
* | [ sendUpstream() ] [ sendDownstream() ] | * | [{@link ChannelInboundInvoker}] [{@link ChannelOutboundInvoker}()] |
* | [ + VAL_INBOUND data ] [ + VAL_OUTBOUND data ] | * | [ method call] [method call] |
* | . . | * | . . |
* | . \|/ | * | . \|/ |
* | +----------+-----------+ +-----------+------------+ | * | +----------+-----------+ +-----------+------------+ |
* | | Upstream Handler 2 | | Downstream Handler M-1 | | * | | Inbound Handler 2 | | Outbound Handler M-1 | |
* | +----------+-----------+ +-----------+------------+ | * | +----------+-----------+ +-----------+------------+ |
* | /|\ | | * | /|\ | |
* | | \|/ | * | | \|/ |
* | +----------+-----------+ +-----------+------------+ | * | +----------+-----------+ +-----------+------------+ |
* | | Upstream Handler 1 | | Downstream Handler M | | * | | Inbound Handler 1 | | Outbound Handler M | |
* | +----------+-----------+ +-----------+------------+ | * | +----------+-----------+ +-----------+------------+ |
* | /|\ | | * | /|\ | |
* +-------------+--------------------------+---------------+ * +---------------+------------------------------------+-----------------+
* | \|/ * | \|/
* +-------------+--------------------------+---------------+ * +---------------+------------------------------------+-----------------+
* | | | | * | | | |
* | [ Socket.read() ] [ Socket.write() ] | * | [ Socket.read() ] [ Socket.write() ] |
* | | * | |
* | Netty Internal I/O Threads (Transport Implementation) | * | Netty Internal I/O Threads (Transport Implementation) |
* +--------------------------------------------------------+ * +----------------------------------------------------------------------+
* </pre> * </pre>
* An upstream event is handled by the upstream handlers in the bottom-up * An upstream event is handled by the upstream handlers in the bottom-up
* direction as shown on the left side of the diagram. An upstream handler * direction as shown on the left side of the diagram. An upstream handler
@ -117,12 +111,12 @@ import java.util.NoSuchElementException;
* <p> * <p>
* For example, let us assume that we created the following pipeline: * For example, let us assume that we created the following pipeline:
* <pre> * <pre>
* {@link ChannelPipeline} p = {@link Channels}.pipeline(); * {@link ChannelPipeline} p = ...;
* p.addLast("1", new UpstreamHandlerA()); * p.addLast("1", new InboundHandlerA());
* p.addLast("2", new UpstreamHandlerB()); * p.addLast("2", new InboundHandlerB());
* p.addLast("3", new DownstreamHandlerA()); * p.addLast("3", new OutboundHandlerA());
* p.addLast("4", new DownstreamHandlerB()); * p.addLast("4", new OutboundHandlerB());
* p.addLast("5", new UpstreamHandlerX()); * p.addLast("5", new InboundOutboundHandlerX());
* </pre> * </pre>
* In the example above, the class whose name starts with {@code Upstream} means * In the example above, the class whose name starts with {@code Upstream} means
* it is an upstream handler. The class whose name starts with * it is an upstream handler. The class whose name starts with
@ -133,13 +127,13 @@ import java.util.NoSuchElementException;
* is 5, 4, 3, 2, 1. On top of this principle, {@link ChannelPipeline} skips * is 5, 4, 3, 2, 1. On top of this principle, {@link ChannelPipeline} skips
* the evaluation of certain handlers to shorten the stack depth: * the evaluation of certain handlers to shorten the stack depth:
* <ul> * <ul>
* <li>3 and 4 don't implement {@link ChannelUpstreamHandler}, and therefore the * <li>3 and 4 don't implement {@link ChannelInboundHandler}, and therefore the
* actual evaluation order of an upstream event will be: 1, 2, and 5.</li> * actual evaluation order of an upstream event will be: 1, 2, and 5.</li>
* <li>1, 2, and 5 don't implement {@link ChannelDownstreamHandler}, and * <li>1, 2, and 5 don't implement {@link ChannelOutboundHandler}, and
* therefore the actual evaluation order of a downstream event will be: * therefore the actual evaluation order of a downstream event will be:
* 4 and 3.</li> * 4 and 3.</li>
* <li>If 5 extended {@link SimpleChannelHandler} which implements both * <li>If 5 implements both
* {@link ChannelUpstreamHandler} and {@link ChannelDownstreamHandler}, the * {@link ChannelInboundHandler} and {@link ChannelOutboundHandler}, the
* evaluation order of an upstream and a downstream event could be 125 and * evaluation order of an upstream and a downstream event could be 125 and
* 543 respectively.</li> * 543 respectively.</li>
* </ul> * </ul>
@ -164,7 +158,7 @@ import java.util.NoSuchElementException;
* and it could be represented as shown in the following example: * and it could be represented as shown in the following example:
* *
* <pre> * <pre>
* {@link ChannelPipeline} pipeline = {@link Channels#pipeline() Channels.pipeline()}; * {@link ChannelPipeline} pipeline = ...;
* pipeline.addLast("decoder", new MyProtocolDecoder()); * pipeline.addLast("decoder", new MyProtocolDecoder());
* pipeline.addLast("encoder", new MyProtocolEncoder()); * pipeline.addLast("encoder", new MyProtocolEncoder());
* pipeline.addLast("executor", new ExecutionHandler(...)); * pipeline.addLast("executor", new ExecutionHandler(...));
@ -178,27 +172,6 @@ import java.util.NoSuchElementException;
* encryption handler when sensitive information is about to be exchanged, * encryption handler when sensitive information is about to be exchanged,
* and remove it after the exchange. * and remove it after the exchange.
* *
* <h3>Pitfall</h3>
* <p>
* Due to the internal implementation detail of the current default
* {@link ChannelPipeline}, the following code does not work as expected if
* <tt>FirstHandler</tt> is the last handler in the pipeline:
* <pre>
* public class FirstHandler extends {@link SimpleChannelUpstreamHandler} {
*
* {@code @Override}
* public void messageReceived({@link ChannelHandlerContext} ctx, {@link MessageEvent} e) {
* // Remove this handler from the pipeline,
* ctx.getPipeline().remove(this);
* // And let SecondHandler handle the current event.
* ctx.getPipeline().addLast("2nd", new SecondHandler());
* ctx.sendUpstream(e);
* }
* }
* </pre>
* To implement the expected behavior, you have to add <tt>SecondHandler</tt>
* before the removal or make sure there is at least one more handler between
* <tt>FirstHandler</tt> and <tt>SecondHandler</tt>.
* @apiviz.landmark * @apiviz.landmark
* @apiviz.composedOf io.netty.channel.ChannelHandlerContext * @apiviz.composedOf io.netty.channel.ChannelHandlerContext
* @apiviz.owns io.netty.channel.ChannelHandler * @apiviz.owns io.netty.channel.ChannelHandler