View Javadoc

1   /*
2    * Copyright 2009 Red Hat, Inc.
3    *
4    * Red Hat licenses this file to you under the Apache License, version 2.0
5    * (the "License"); you may not use this file except in compliance with the
6    * License.  You may obtain a copy of the License at:
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package org.jboss.netty.channel;
17  
18  /**
19   * Handles or intercepts a downstream {@link ChannelEvent}, and sends a
20   * {@link ChannelEvent} to the next handler in a {@link ChannelPipeline}.
21   * <p>
22   * The most common use case of this interface is to intercept an I/O request
23   * such as {@link Channel#write(Object)} and {@link Channel#close()}.
24   *
25   * <h3>{@link SimpleChannelDownstreamHandler}</h3>
26   * <p>
27   * In most cases, you will get to use a {@link SimpleChannelDownstreamHandler}
28   * to implement a downstream handler because it provides an individual handler
29   * method for each event type.  You might want to implement this interface
30   * directly though if you want to handle various types of events in more
31   * generic way.
32   *
33   * <h3>Firing an event to the next handler</h3>
34   * <p>
35   * You can forward the received event downstream or upstream.  In most cases,
36   * {@link ChannelDownstreamHandler} will send the event downstream
37   * (i.e. outbound) although it is legal to send the event upstream (i.e. inbound):
38   *
39   * <pre>
40   * // Sending the event downstream (outbound)
41   * void handleDownstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
42   *     ...
43   *     ctx.sendDownstream(e);
44   *     ...
45   * }
46   *
47   * // Sending the event upstream (inbound)
48   * void handleDownstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
49   *     ...
50   *     ctx.sendUpstream(new {@link UpstreamChannelStateEvent}(...));
51   *     ...
52   * }
53   * </pre>
54   *
55   * <h4>Using the helper class to send an event</h4>
56   * <p>
57   * You will also find various helper methods in {@link Channels} to be useful
58   * to generate and send an artificial or manipulated event.
59   *
60   * <h3>State management</h3>
61   *
62   * Please refer to {@link ChannelHandler}.
63   *
64   * <h3>Thread safety</h3>
65   * <p>
66   * {@link #handleDownstream(ChannelHandlerContext, ChannelEvent) handleDownstream}
67   * may be invoked by more than one thread simultaneously.  If the handler
68   * accesses a shared resource or stores stateful information, you might need
69   * proper synchronization in the handler implementation.
70   *
71   * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
72   * @author <a href="http://gleamynode.net/">Trustin Lee</a>
73   *
74   * @version $Rev: 2122 $, $Date: 2010-02-02 11:00:04 +0900 (Tue, 02 Feb 2010) $
75   *
76   * @apiviz.exclude ^org\.jboss\.netty\.handler\..*$
77   */
78  public interface ChannelDownstreamHandler extends ChannelHandler {
79  
80      /**
81       * Handles the specified downstream event.
82       *
83       * @param ctx  the context object for this handler
84       * @param e    the downstream event to process or intercept
85       */
86      void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception;
87  }