コード例 #1
0
  private void callAfterAdd(ChannelHandlerContext ctx) {
    try {
      ctx.handler().afterAdd(ctx);
    } catch (Throwable t) {
      boolean removed = false;
      try {
        remove((DefaultChannelHandlerContext) ctx, false);
        removed = true;
      } catch (Throwable t2) {
        if (logger.isWarnEnabled()) {
          logger.warn("Failed to remove a handler: " + ctx.name(), t2);
        }
      }

      if (removed) {
        throw new ChannelPipelineException(
            ctx.handler().getClass().getName() + ".afterAdd() has thrown an exception; removed.",
            t);
      } else {
        throw new ChannelPipelineException(
            ctx.handler().getClass().getName()
                + ".afterAdd() has thrown an exception; also failed to remove.",
            t);
      }
    }
  }
コード例 #2
0
 private static void callBeforeRemove(ChannelHandlerContext ctx) {
   try {
     ctx.handler().beforeRemove(ctx);
   } catch (Throwable t) {
     throw new ChannelPipelineException(
         ctx.handler().getClass().getName()
             + ".beforeRemove() has thrown an exception; not removing.",
         t);
   }
 }
コード例 #3
0
 @Override
 public ChannelHandler get(String name) {
   ChannelHandlerContext ctx = context(name);
   if (ctx == null) {
     return null;
   } else {
     return ctx.handler();
   }
 }
コード例 #4
0
 @SuppressWarnings("unchecked")
 @Override
 public <T extends ChannelHandler> T get(Class<T> handlerType) {
   ChannelHandlerContext ctx = context(handlerType);
   if (ctx == null) {
     return null;
   } else {
     return (T) ctx.handler();
   }
 }
コード例 #5
0
 private static void callBeforeAdd(ChannelHandlerContext ctx) {
   ChannelHandler handler = ctx.handler();
   if (handler instanceof ChannelStateHandlerAdapter) {
     ChannelStateHandlerAdapter h = (ChannelStateHandlerAdapter) handler;
     if (!h.isSharable() && h.added) {
       throw new ChannelPipelineException(
           h.getClass().getName()
               + " is not a @Sharable handler, so can't be added or removed multiple times.");
     }
     h.added = true;
   }
   try {
     handler.beforeAdd(ctx);
   } catch (Throwable t) {
     throw new ChannelPipelineException(
         handler.getClass().getName() + ".beforeAdd() has thrown an exception; not adding.", t);
   }
 }