public interface ChannelUpstreamHandler extends ChannelHandler
ChannelEvent
, and sends a
ChannelEvent
to the next handler in a ChannelPipeline
.
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.
SimpleChannelUpstreamHandler
In most cases, you will get to use a SimpleChannelUpstreamHandler
to
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
generic way.
You can forward the received event upstream or downstream. In most cases,
ChannelUpstreamHandler
will send the event upstream (i.e. inbound)
although it is legal to send the event downstream (i.e. outbound):
// Sending the event upstream (inbound) void handleUpstream(ChannelHandlerContext
ctx,ChannelEvent
e) throws Exception { ... ctx.sendUpstream(e); ... } // Sending the event downstream (outbound) void handleDownstream(ChannelHandlerContext
ctx,ChannelEvent
e) throws Exception { ... ctx.sendDownstream(newDownstreamMessageEvent
(...)); ... }
You will also find various helper methods in Channels
to be useful
to generate and send an artificial or manipulated event.
ChannelHandler
.
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.
This does not necessarily mean that there's a dedicated thread per
Channel
; the I/O thread of some transport can serve more than one
Channel
(e.g. NIO transport), while the I/O thread of other
transports can serve only one (e.g. OIO transport).
However, if you add an ExecutionHandler
to a ChannelPipeline
,
this behavior changes depending on what Executor
was employed to
dispatch the events. Please refer to ExecutionHandler
for more
information.
ChannelHandler.Sharable
Modifier and Type | Method and Description |
---|---|
void |
handleUpstream(ChannelHandlerContext ctx,
ChannelEvent e)
Handles the specified upstream event.
|
void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception
ctx
- the context object for this handlere
- the upstream event to process or interceptException
Copyright © 2008-2014 The Netty Project. All Rights Reserved.