netty5/transport/src/main/java/io/netty/channel/ChannelUpstreamHandler.java

89 lines
3.3 KiB
Java
Raw Normal View History

/*
* Copyright 2011 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
2009-08-28 07:15:49 +00:00
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
2009-08-28 07:15:49 +00:00
* License for the specific language governing permissions and limitations
* under the License.
*/
2011-12-09 12:38:59 +09:00
package io.netty.channel;
/**
* Handles or intercepts an upstream {@link ChannelEvent}, and sends a
* {@link ChannelEvent} to the next handler in a {@link ChannelPipeline}.
* <p>
2009-10-30 07:51:33 +00:00
* The most common use case of this interface is to intercept an I/O event
* generated by I/O workers to transform the received messages or execute
* the relevant business logic.
2008-09-02 14:12:56 +00:00
*
2009-10-30 07:51:33 +00:00
* <h3>{@link SimpleChannelUpstreamHandler}</h3>
2008-09-01 14:29:17 +00:00
* <p>
2009-10-30 07:51:33 +00:00
* In most cases, you will get to use a {@link SimpleChannelUpstreamHandler} to
2008-11-14 08:02:42 +00:00
* implement an upstream handler because it provides an individual handler
* method for each event type. You might want to implement this interface
* directly though if you want to handle various types of events in more
2008-09-01 14:29:17 +00:00
* generic way.
*
* <h3>Firing an event to the next handler</h3>
2008-09-01 15:19:34 +00:00
* <p>
* You can forward the received event upstream or downstream. In most cases,
* {@link ChannelUpstreamHandler} will send the event upstream (i.e. inbound)
* although it is legal to send the event downstream (i.e. outbound):
2008-09-01 15:19:34 +00:00
*
* <pre>
* // Sending the event upstream (inbound)
2008-09-02 14:12:56 +00:00
* void handleUpstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
2008-09-01 15:19:34 +00:00
* ...
* ctx.sendUpstream(e);
* ...
* }
*
* // Sending the event downstream (outbound)
2008-09-02 14:12:56 +00:00
* void handleDownstream({@link ChannelHandlerContext} ctx, {@link ChannelEvent} e) throws Exception {
2008-09-01 15:19:34 +00:00
* ...
2010-02-02 02:00:04 +00:00
* ctx.sendDownstream(new {@link DownstreamMessageEvent}(...));
2008-09-01 15:19:34 +00:00
* ...
* }
* </pre>
2008-09-02 14:12:56 +00:00
*
* <h4>Using the helper class to send an event</h4>
2008-09-01 15:19:34 +00:00
* <p>
* You will also find various helper methods in {@link Channels} to be useful
* to generate and send an artificial or manipulated event.
2008-09-01 15:19:34 +00:00
*
* <h3>State management</h3>
*
* Please refer to {@link ChannelHandler}.
*
2008-09-01 14:29:17 +00:00
* <h3>Thread safety</h3>
* <p>
* {@link #handleUpstream(ChannelHandlerContext, ChannelEvent) handleUpstream}
* will be invoked sequentially by the same thread (i.e. an I/O thread) and
* therefore a handler does not need to worry about being invoked with a new
* upstream event before the previous upstream event is finished.
2008-09-01 14:29:17 +00:00
* <p>
* 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 of other
* transports can serve only one (e.g. OIO transport).
*
2011-12-09 13:59:41 +09:00
* @apiviz.exclude ^io\.netty\.handler\..*$
*/
public interface ChannelUpstreamHandler extends ChannelHandler {
2008-09-01 14:29:17 +00:00
/**
* Handles the specified upstream event.
*
* @param ctx the context object for this handler
* @param e the upstream event to process or intercept
*/
void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception;
}