(1)ChannelInboundHandlerAdapter
ChannelInboundHandlerAdapter主要用于实现ChannelInboundHandler接口的所有方法,这样我们在继承它编写自己的ChannelHandler时就不需要实现ChannelHandler里的每种方法了,从而避免了直接实现ChannelHandler时需要实现其所有方法而导致代码显得冗余和臃肿。
[code]//Handles an I/O event or intercepts an I/O operation, and forwards it to its next handler in its ChannelPipeline.public interface ChannelHandler { //Gets called after the ChannelHandler was added to the actual context and it's ready to handle events. void handlerAdded(ChannelHandlerContext ctx) throws Exception; //Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore. void handlerRemoved(ChannelHandlerContext ctx) throws Exception; //Gets called if a Throwable was thrown. @Deprecated void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception; //Indicates that the same instance of the annotated ChannelHandler can be added to one or more ChannelPipelines multiple times without a race condition. @Inherited @Documented @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @interface Sharable { // no value }}//Skeleton implementation of a ChannelHandler.public abstract class ChannelHandlerAdapter implements ChannelHandler { // Not using volatile because it's used only for a sanity check. boolean added; //Return true if the implementation is Sharable and so can be added to different ChannelPipelines. public boolean isSharable() { Class clazz = getClass(); Map