This commit is contained in:
Trustin Lee 2009-06-17 09:13:10 +00:00
parent 35eac01e40
commit 843b530c64
4 changed files with 50 additions and 21 deletions

View File

@ -33,7 +33,9 @@ import java.util.EventListener;
* *
* {@link #operationComplete(ChannelFuture)} is directly called by an I/O * {@link #operationComplete(ChannelFuture)} is directly called by an I/O
* thread. Therefore, performing a time consuming task or a blocking operation * thread. Therefore, performing a time consuming task or a blocking operation
* in the handler method can cause an unexpected pause during I/O. * in the handler method can cause an unexpected pause during I/O. If you need
* to perform a blocking operation on I/O completion, try to execute the
* operation in a different thread using a thread pool.
* *
* @author The Netty Project (netty-dev@lists.jboss.org) * @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com) * @author Trustin Lee (tlee@redhat.com)

View File

@ -45,17 +45,17 @@ package org.jboss.netty.channel;
* <h3>The context object</h3> * <h3>The context object</h3>
* <p> * <p>
* A {@link ChannelHandler} is provided with a {@link ChannelHandlerContext} * A {@link ChannelHandler} is provided with a {@link ChannelHandlerContext}
* object. The {@link ChannelHandler} is supposed to interact with the * object. A {@link ChannelHandler} is supposed to interact with the
* {@link ChannelPipeline} it belongs to via the context object. Using the * {@link ChannelPipeline} it belongs to via a context object. Using the
* context object, the {@link ChannelHandler} can pass events to the next * context object, the {@link ChannelHandler} can pass events to the next
* or the previous handler or modify the behavior of the pipeline by adding or * or the previous handler or modify the behavior of the pipeline, or store the
* removing a handler for example. * information (attachment) which is specific to the handler.
* *
* <h3>Additional resources worth reading</h3> * <h3>Additional resources worth reading</h3>
* <p> * <p>
* Please refer to the {@link ChannelEvent} and {@link ChannelPipeline} * Please refer to the {@link ChannelEvent} and {@link ChannelPipeline} to find
* documentation to find out what a upstream event and a downstream event are, * out what a upstream event and a downstream event are, what fundamental
* what fundamental differences they have, and how they flow in a pipeline. * differences they have, and how they flow in a pipeline.
* *
* @author The Netty Project (netty-dev@lists.jboss.org) * @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com) * @author Trustin Lee (tlee@redhat.com)

View File

@ -23,27 +23,33 @@
package org.jboss.netty.channel; package org.jboss.netty.channel;
/** /**
* Provides the properties and operations which are specific to the * Provides the properties and operations which are specific to a
* {@link ChannelHandler} and the {@link ChannelPipeline} it belongs to. * {@link ChannelHandler} and the {@link ChannelPipeline} it belongs to.
* Via a {@link ChannelHandlerContext}, a {@link ChannelHandler} can send * Via a {@link ChannelHandlerContext}, a {@link ChannelHandler} can send
* an upstream or downstream {@link ChannelEvent} to the next or previous * an upstream or downstream {@link ChannelEvent} to the next or previous
* {@link ChannelHandler} in a {@link ChannelPipeline}. * {@link ChannelHandler} in a pipeline, modify the behavior of the pipeline,
* * or store the information (attachment) which is specific to the handler.
* <pre> * <pre>
* <b>n</b> = the number of the handler entries in a pipeline
*
* +---------+ 1 .. 1 +----------+ 1 n +---------+ n m +---------+ * +---------+ 1 .. 1 +----------+ 1 n +---------+ n m +---------+
* | Channel |--------| Pipeline |--------| Context |--------| Handler | * | Channel |--------| Pipeline |--------| Context |--------| Handler |
* +---------+ +----------+ +---------+ +---------+ * +---------+ +----------+ +----+----+ +----+----+
* n = the number of the handler entries in a pipeline * | 1..1 |
* +-----+------+ |
* | Attachment |<----------+
* +------------+ stores
* </pre> * </pre>
*
* Please note that a {@link ChannelHandler} instance can be added to more than * Please note that a {@link ChannelHandler} instance can be added to more than
* one {@link ChannelPipeline}. It means a single {@link ChannelHandler} * one {@link ChannelPipeline}. It means a single {@link ChannelHandler}
* instance can have more than one {@link ChannelHandlerContext} and therefore * instance can have more than one {@link ChannelHandlerContext} and therefore
* can be invoked with different {@link ChannelHandlerContext}s if it is added * the single instance can be invoked with different
* to one or more {@link ChannelPipeline}s more than once. For example, the * {@link ChannelHandlerContext}s if it is added to one or more
* following handler will have as many independent attachments as how many * {@link ChannelPipeline}s more than once.
* times it is added to pipelines, regardless if it is added to the same * <p>
* pipeline multiple times or added to different pipelines multiple times: * For example, the following handler will have as many independent attachments
* as how many times it is added to pipelines, regardless if it is added to the
* same pipeline multiple times or added to different pipelines multiple times:
* <pre> * <pre>
* public class FactorialHandler extends SimpleUpstreamChannelHandler { * public class FactorialHandler extends SimpleUpstreamChannelHandler {
* *
@ -76,6 +82,13 @@ package org.jboss.netty.channel;
* p2.addLast("f4", fh); * p2.addLast("f4", fh);
* </pre> * </pre>
* *
* <h3>Additional resources worth reading</h3>
* <p>
* Please refer to the {@link ChannelHandler}, {@link ChannelEvent}, and
* {@link ChannelPipeline} to find out what a upstream event and a downstream
* event are, what fundamental differences they have, and how they flow in a
* pipeline.
*
* @author The Netty Project (netty-dev@lists.jboss.org) * @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com) * @author Trustin Lee (tlee@redhat.com)
* *
@ -137,6 +150,19 @@ public interface ChannelHandlerContext {
*/ */
void sendDownstream(ChannelEvent e); void sendDownstream(ChannelEvent e);
/**
* Retrieves an object which is {@link #setAttachment(Object) attached} to
* this context.
*
* @return {@code null} if no object was attached or
* {@code null} was attached
*/
Object getAttachment(); Object getAttachment();
/**
* Attaches an object to this context to store a stateful information
* specific to the {@link ChannelHandler} which is associated with this
* context.
*/
void setAttachment(Object attachment); void setAttachment(Object attachment);
} }

View File

@ -23,8 +23,9 @@
package org.jboss.netty.channel; package org.jboss.netty.channel;
/** /**
* A {@link RuntimeException} which is thrown when a {@link LifeCycleAwareChannelHandler} * A {@link RuntimeException} which is thrown when a
* throws an {@link Exception} in its handler methods. * {@link LifeCycleAwareChannelHandler} throws an {@link Exception}
* in its handler methods.
* *
* @author The Netty Project (netty-dev@lists.jboss.org) * @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com) * @author Trustin Lee (tlee@redhat.com)