Package org.jboss.netty.channel
Class SimpleChannelDownstreamHandler
- java.lang.Object
-
- org.jboss.netty.channel.SimpleChannelDownstreamHandler
-
- All Implemented Interfaces:
ChannelDownstreamHandler,ChannelHandler
- Direct Known Subclasses:
WriteTimeoutHandler
public class SimpleChannelDownstreamHandler extends java.lang.Object implements ChannelDownstreamHandler
AChannelDownstreamHandlerwhich 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
SimpleChannelHandlerif you need to implement bothChannelUpstreamHandlerandChannelDownstreamHandler.Overriding the
handleDownstreammethodYou can override the
handleDownstreammethod just like overriding an ordinary Java method. Please make sure to callsuper.handleDownstream()so that other handler methods are invoked properly:public class MyChannelHandler extends
SimpleChannelDownstreamHandler{@Overridepublic void handleDownstream(ChannelHandlerContextctx,ChannelEvente) throws Exception { // Log all channel state changes. if (e instanceofMessageEvent) { logger.info("Writing:: " + e); } super.handleDownstream(ctx, e); } }Caution:
Use the *Later(..) methods of the
Channelsclass if you want to send an upstream event from aChannelDownstreamHandlerotherwise you may run into threading issues.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description SimpleChannelDownstreamHandler()
-
Method Summary
-
-
-
Method Detail
-
handleDownstream
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws java.lang.Exception
Handles the specified downstream event. Down-casts the received downstream event into more meaningful sub-type event and calls an appropriate handler method with the down-casted event.- Specified by:
handleDownstreamin interfaceChannelDownstreamHandler- Parameters:
ctx- the context object for this handlere- the downstream event to process or intercept- Throws:
java.lang.Exception
-
writeRequested
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
Invoked whenChannel.write(Object)is called.- Throws:
java.lang.Exception
-
bindRequested
public void bindRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Invoked whenChannel.bind(SocketAddress)was called.- Throws:
java.lang.Exception
-
connectRequested
public void connectRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Invoked whenChannel.connect(SocketAddress)was called.- Throws:
java.lang.Exception
-
setInterestOpsRequested
public void setInterestOpsRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Invoked whenChannel.setInterestOps(int)was called.- Throws:
java.lang.Exception
-
disconnectRequested
public void disconnectRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Invoked whenChannel.disconnect()was called.- Throws:
java.lang.Exception
-
unbindRequested
public void unbindRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Invoked whenChannel.unbind()was called.- Throws:
java.lang.Exception
-
closeRequested
public void closeRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Invoked whenChannel.close()was called.- Throws:
java.lang.Exception
-
-