ing the event forward (upstream) void handleUpstream( {@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {... ctx.sendUpstream(e); ... } // Sending the event backward (downstream) void handleDownstream( {@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {... ctx.sendDownstream(new MessageEvent(...)); ... }
Using the helper class to send an event
You will also find various helper methods in {@link Channels} to be usefulto generate and send an artificial or manipulated event.
Thread safety
If there's no {@link ExecutionHandler} in the {@link ChannelPipeline}, {@link #handleUpstream(ChannelHandlerContext,ChannelEvent) handleUpstream}will be invoked sequentially by the same thread (i.e. an I/O thread). Please note that this does not necessarily mean that there's a dedicated thread per {@link Channel}; the I/O thread of some transport can serve more than one {@link Channel} (e.g. NIO transport), while the I/O thread ofother transports can serve only one (e.g. OIO transport).
If an {@link ExecutionHandler} is added in the {@link ChannelPipeline}, {@link #handleUpstream(ChannelHandlerContext,ChannelEvent) handleUpstream}may be invoked by different threads at the same time, depending on what {@link Executor} implementation is used with the {@link ExecutionHandler}.
{@link OrderedMemoryAwareThreadPoolExecutor} is provided to guarantee theorder of {@link ChannelEvent}s. It does not guarantee that the invocation will be made by the same thread for the same channel, but it does guarantee that the invocation will be made sequentially for the events of the same channel. For example, the events can be processed as depicted below:
-----------------------------------> Timeline -----------------------------------> Thread X: --- Channel A (Event 1) --. .-- Channel B (Event 2) --- Channel B (Event 3) ---> \ / X / \ Thread Y: --- Channel B (Event 1) --' '-- Channel A (Event 2) --- Channel A (Event 3) --->
Also, please refer to the {@link ChannelPipelineCoverage} annotation tounderstand the relationship between a handler and its stateful properties.
@author The Netty Project (netty-dev@lists.jboss.org)
@author Trustin Lee (tlee@redhat.com)
@version $Rev: 473 $, $Date: 2008-11-14 17:02:42 +0900 (Fri, 14 Nov 2008) $