public interface ChannelDownstreamHandler 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 request
such as Channel.write(Object)
and Channel.close()
.
SimpleChannelDownstreamHandler
In most cases, you will get to use a SimpleChannelDownstreamHandler
to implement a downstream 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 downstream or upstream. In most cases,
ChannelDownstreamHandler
will send the event downstream
(i.e. outbound) although it is legal to send the event upstream (i.e. inbound):
// Sending the event downstream (outbound) void handleDownstream(ChannelHandlerContext
ctx,ChannelEvent
e) throws Exception { ... ctx.sendDownstream(e); ... } // Sending the event upstream (inbound) void handleDownstream(ChannelHandlerContext
ctx,ChannelEvent
e) throws Exception { ... ctx.sendUpstream(newUpstreamChannelStateEvent
(...)); ... }
You will also find various helper methods in Channels
to be useful
to generate and send an artificial or manipulated event.
Caution:
Use the *Later(..) methods of the Channels
class if you want to send an upstream event
from a ChannelDownstreamHandler
otherwise you may run into threading issues.
ChannelHandler
.
handleDownstream
may be invoked by more than one thread simultaneously. If the handler
accesses a shared resource or stores stateful information, you might need
proper synchronization in the handler implementation.
ChannelHandler.Sharable
Modifier and Type | Method and Description |
---|---|
void |
handleDownstream(ChannelHandlerContext ctx,
ChannelEvent e)
Handles the specified downstream event.
|
void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception
ctx
- the context object for this handlere
- the downstream event to process or interceptException
Copyright © 2008-2015 The Netty Project. All Rights Reserved.