Class SimpleChannelDownstreamHandler

java.lang.Object
org.jboss.netty.channel.SimpleChannelDownstreamHandler
All Implemented Interfaces:
ChannelDownstreamHandler, ChannelHandler
Direct Known Subclasses:
WriteTimeoutHandler

public class SimpleChannelDownstreamHandler extends Object implements ChannelDownstreamHandler
A ChannelDownstreamHandler which provides an individual handler method for each event type. This handler down-casts the received downstream event into more meaningful sub-type event and calls an appropriate handler method with the down-cast event. The names of the methods starts with the name of the operation and ends with "Requested" (e.g. writeRequested.)

Please use SimpleChannelHandler if you need to implement both ChannelUpstreamHandler and ChannelDownstreamHandler.

Overriding the handleDownstream method

You can override the handleDownstream method just like overriding an ordinary Java method. Please make sure to call super.handleDownstream() so that other handler methods are invoked properly:

public class MyChannelHandler extends SimpleChannelDownstreamHandler {

     @Override
     public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {

         // Log all channel state changes.
         if (e instanceof MessageEvent) {
             logger.info("Writing:: " + e);
         }

         super.handleDownstream(ctx, e);
     }
 }

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.