Package org.jboss.netty.channel
Class SimpleChannelHandler
java.lang.Object
org.jboss.netty.channel.SimpleChannelHandler
- All Implemented Interfaces:
ChannelDownstreamHandler
,ChannelHandler
,ChannelUpstreamHandler
- Direct Known Subclasses:
AbstractTrafficShapingHandler
,BufferedWriteHandler
,HttpContentEncoder
,IdleStateAwareChannelHandler
,SpdyHttpResponseStreamIdHandler
public class SimpleChannelHandler
extends Object
implements ChannelUpstreamHandler, ChannelDownstreamHandler
A Overriding the
ChannelHandler
which provides an individual handler method
for each event type. This handler down-casts the received upstream or
or downstream event into more meaningful sub-type event and calls an
appropriate handler method with the down-cast event. For an upstream
event, the names of the methods are identical to the upstream event names,
as introduced in the ChannelEvent
documentation. For a
downstream event, the names of the methods starts with the name of the
operation and ends with "Requested"
(e.g. writeRequested
.)
Please use SimpleChannelUpstreamHandler
or
SimpleChannelDownstreamHandler
if you want to intercept only
upstream or downstream events.
Overriding the handleUpstream
and handleDownstream
method
You can override the handleUpstream
and handleDownstream
method just like overriding an ordinary Java method. Please make sure to
call super.handleUpstream()
or super.handleDownstream()
so
that other handler methods are invoked properly:
public class MyChannelHandler extendsSimpleChannelHandler
{@Override
public void handleUpstream(ChannelHandlerContext
ctx,ChannelEvent
e) throws Exception { // Log all channel state changes. if (e instanceofChannelStateEvent
) { logger.info("Channel state changed: " + e); } super.handleUpstream(ctx, e); }@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); } }
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Invoked whenChannel.bind(SocketAddress)
was called.void
Invoked when aChannel
is open and bound to a local address, but not connected.void
Invoked when aChannel
was closed and all its related resources were released.void
Invoked when aChannel
is open, bound to a local address, and connected to a remote address.void
Invoked when aChannel
was disconnected from its remote peer.void
Invoked when aChannel
'sinterestOps
was changed.void
Invoked when aChannel
is open, but not bound nor connected.void
Invoked when aChannel
was unbound from the current local address.void
Invoked when a childChannel
was closed.void
Invoked when a childChannel
was open.void
Invoked whenChannel.close()
was called.void
Invoked whenChannel.connect(SocketAddress)
was called.void
Invoked whenChannel.disconnect()
was called.void
Invoked when an exception was raised by an I/O thread or aChannelHandler
.void
Handles the specified downstream event.void
Handles the specified upstream event.void
Invoked when a message object (e.g:ChannelBuffer
) was received from a remote peer.void
Invoked whenChannel.setInterestOps(int)
was called.void
Invoked whenChannel.unbind()
was called.void
Invoked when something was written into aChannel
.void
Invoked whenChannel.write(Object)
is called.
-
Field Details
-
logger
-
-
Constructor Details
-
SimpleChannelHandler
public SimpleChannelHandler()
-
-
Method Details
-
handleUpstream
Handles the specified upstream event. Down-casts the received upstream event into more meaningful sub-type event and calls an appropriate handler method with the down-casted event.- Specified by:
handleUpstream
in interfaceChannelUpstreamHandler
- Parameters:
ctx
- the context object for this handlere
- the upstream event to process or intercept- Throws:
Exception
-
messageReceived
Invoked when a message object (e.g:ChannelBuffer
) was received from a remote peer.- Throws:
Exception
-
exceptionCaught
Invoked when an exception was raised by an I/O thread or aChannelHandler
.- Throws:
Exception
-
channelOpen
Invoked when aChannel
is open, but not bound nor connected.- Throws:
Exception
-
channelBound
Invoked when aChannel
is open and bound to a local address, but not connected.- Throws:
Exception
-
channelConnected
Invoked when aChannel
is open, bound to a local address, and connected to a remote address.- Throws:
Exception
-
channelInterestChanged
Invoked when aChannel
'sinterestOps
was changed.- Throws:
Exception
-
channelDisconnected
Invoked when aChannel
was disconnected from its remote peer.- Throws:
Exception
-
channelUnbound
Invoked when aChannel
was unbound from the current local address.- Throws:
Exception
-
channelClosed
Invoked when aChannel
was closed and all its related resources were released.- Throws:
Exception
-
writeComplete
Invoked when something was written into aChannel
.- Throws:
Exception
-
childChannelOpen
Invoked when a childChannel
was open. (e.g. a server channel accepted a connection)- Throws:
Exception
-
childChannelClosed
public void childChannelClosed(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception Invoked when a childChannel
was closed. (e.g. the accepted connection was closed)- Throws:
Exception
-
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
-