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