Package org.jboss.netty.channel
Class SimpleChannelDownstreamHandler
java.lang.Object
org.jboss.netty.channel.SimpleChannelDownstreamHandler
- All Implemented Interfaces:
ChannelDownstreamHandler
,ChannelHandler
- Direct Known Subclasses:
WriteTimeoutHandler
A Overriding the
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 extendsSimpleChannelDownstreamHandler
{@Override
public void handleDownstream(ChannelHandlerContext
ctx,ChannelEvent
e) 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 Channels
class if you want to send an upstream event
from a ChannelDownstreamHandler
otherwise 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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked whenChannel.bind(SocketAddress)
was called.void
Invoked whenChannel.close()
was called.void
Invoked whenChannel.connect(SocketAddress)
was called.void
Invoked whenChannel.disconnect()
was called.void
Handles the specified downstream event.void
Invoked whenChannel.setInterestOps(int)
was called.void
Invoked whenChannel.unbind()
was called.void
Invoked whenChannel.write(Object)
is called.
-
Constructor Details
-
SimpleChannelDownstreamHandler
public SimpleChannelDownstreamHandler()
-
-
Method Details
-
handleDownstream
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:
handleDownstream
in interfaceChannelDownstreamHandler
- Parameters:
ctx
- the context object for this handlere
- the downstream event to process or intercept- Throws:
Exception
-
writeRequested
Invoked whenChannel.write(Object)
is called.- Throws:
Exception
-
bindRequested
Invoked whenChannel.bind(SocketAddress)
was called.- Throws:
Exception
-
connectRequested
Invoked whenChannel.connect(SocketAddress)
was called.- Throws:
Exception
-
setInterestOpsRequested
public void setInterestOpsRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception Invoked whenChannel.setInterestOps(int)
was called.- Throws:
Exception
-
disconnectRequested
Invoked whenChannel.disconnect()
was called.- Throws:
Exception
-
unbindRequested
Invoked whenChannel.unbind()
was called.- Throws:
Exception
-
closeRequested
Invoked whenChannel.close()
was called.- Throws:
Exception
-