public class SimpleChannelHandler extends java.lang.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
构造器和说明 |
---|
SimpleChannelHandler() |
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws java.lang.Exception
handleUpstream
在接口中 ChannelUpstreamHandler
ctx
- the context object for this handlere
- the upstream event to process or interceptjava.lang.Exception
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
ChannelBuffer
) was received
from a remote peer.java.lang.Exception
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws java.lang.Exception
ChannelHandler
.java.lang.Exception
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel
is open, but not bound nor connected.java.lang.Exception
public void channelBound(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel
is open and bound to a local address,
but not connected.java.lang.Exception
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel
is open, bound to a local address, and
connected to a remote address.java.lang.Exception
public void channelInterestChanged(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel
's interestOps
was changed.java.lang.Exception
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel
was disconnected from its remote peer.java.lang.Exception
public void channelUnbound(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel
was unbound from the current local address.java.lang.Exception
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel
was closed and all its related resources
were released.java.lang.Exception
public void writeComplete(ChannelHandlerContext ctx, WriteCompletionEvent e) throws java.lang.Exception
Channel
.java.lang.Exception
public void childChannelOpen(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws java.lang.Exception
Channel
was open.
(e.g. a server channel accepted a connection)java.lang.Exception
public void childChannelClosed(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws java.lang.Exception
Channel
was closed.
(e.g. the accepted connection was closed)java.lang.Exception
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws java.lang.Exception
handleDownstream
在接口中 ChannelDownstreamHandler
ctx
- the context object for this handlere
- the downstream event to process or interceptjava.lang.Exception
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
Channel.write(Object)
is called.java.lang.Exception
public void bindRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel.bind(SocketAddress)
was called.java.lang.Exception
public void connectRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel.connect(SocketAddress)
was called.java.lang.Exception
public void setInterestOpsRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel.setInterestOps(int)
was called.java.lang.Exception
public void disconnectRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel.disconnect()
was called.java.lang.Exception
public void unbindRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel.unbind()
was called.java.lang.Exception
public void closeRequested(ChannelHandlerContext ctx, ChannelStateEvent e) throws java.lang.Exception
Channel.close()
was called.java.lang.Exception