public class SimpleChannelHandler extends Object implements ChannelUpstreamHandler, ChannelDownstreamHandler
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.
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); } }
ChannelHandler.Sharable| Constructor and Description |
|---|
SimpleChannelHandler() |
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception
handleUpstream in interface ChannelUpstreamHandlerctx - the context object for this handlere - the upstream event to process or interceptExceptionpublic void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
ChannelBuffer) was received
from a remote peer.Exceptionpublic void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception
ChannelHandler.Exceptionpublic void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel is open, but not bound nor connected.Exceptionpublic void channelBound(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel is open and bound to a local address,
but not connected.Exceptionpublic void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel is open, bound to a local address, and
connected to a remote address.Exceptionpublic void channelInterestChanged(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel's interestOps
was changed.Exceptionpublic void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel was disconnected from its remote peer.Exceptionpublic void channelUnbound(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel was unbound from the current local address.Exceptionpublic void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel was closed and all its related resources
were released.Exceptionpublic void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) throws Exception
Channel.Exceptionpublic void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception
Channel was open.
(e.g. a server channel accepted a connection)Exceptionpublic void childChannelClosed(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception
Channel was closed.
(e.g. the accepted connection was closed)Exceptionpublic void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception
handleDownstream in interface ChannelDownstreamHandlerctx - the context object for this handlere - the downstream event to process or interceptExceptionpublic void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception
Channel.write(Object) is called.Exceptionpublic void bindRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel.bind(SocketAddress) was called.Exceptionpublic void connectRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel.connect(SocketAddress) was called.Exceptionpublic void setInterestOpsRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel.setInterestOps(int) was called.Exceptionpublic void disconnectRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel.disconnect() was called.Exceptionpublic void unbindRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel.unbind() was called.Exceptionpublic void closeRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception
Channel.close() was called.ExceptionCopyright © 2008-2015 The Netty Project. All Rights Reserved.