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{@Overridepublic void handleUpstream(ChannelHandlerContextctx,ChannelEvente) throws Exception { // Log all channel state changes. if (e instanceofChannelStateEvent) { logger.info("Channel state changed: " + e); } super.handleUpstream(ctx, e); }@Overridepublic void handleDownstream(ChannelHandlerContextctx,ChannelEvente) 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 ChannelHandler
ChannelHandler.Sharable -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInvoked whenChannel.bind(SocketAddress)was called.voidInvoked when aChannelis open and bound to a local address, but not connected.voidInvoked when aChannelwas closed and all its related resources were released.voidInvoked when aChannelis open, bound to a local address, and connected to a remote address.voidInvoked when aChannelwas disconnected from its remote peer.voidInvoked when aChannel'sinterestOpswas changed.voidInvoked when aChannelis open, but not bound nor connected.voidInvoked when aChannelwas unbound from the current local address.voidInvoked when a childChannelwas closed.voidInvoked when a childChannelwas open.voidInvoked whenChannel.close()was called.voidInvoked whenChannel.connect(SocketAddress)was called.voidInvoked whenChannel.disconnect()was called.voidInvoked when an exception was raised by an I/O thread or aChannelHandler.voidHandles the specified downstream event.voidHandles the specified upstream event.voidInvoked when a message object (e.g:ChannelBuffer) was received from a remote peer.voidInvoked whenChannel.setInterestOps(int)was called.voidInvoked whenChannel.unbind()was called.voidInvoked when something was written into aChannel.voidInvoked 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:
handleUpstreamin 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
-
channelBound
-
channelConnected
-
channelInterestChanged
Invoked when aChannel'sinterestOpswas changed.- Throws:
Exception
-
channelDisconnected
-
channelUnbound
-
channelClosed
-
writeComplete
-
childChannelOpen
-
childChannelClosed
public void childChannelClosed(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception Invoked when a childChannelwas 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:
handleDownstreamin 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
-