コード例 #1
0
  private void replace0(
      DefaultChannelHandlerContext ctx,
      String newName,
      DefaultChannelHandlerContext newCtx,
      boolean forward) {
    boolean sameName = ctx.name().equals(newName);

    DefaultChannelHandlerContext prev = ctx.prev;
    DefaultChannelHandlerContext next = ctx.next;
    newCtx.prev = prev;
    newCtx.next = next;

    callBeforeRemove(ctx);
    callBeforeAdd(newCtx);

    prev.next = newCtx;
    next.prev = newCtx;

    if (!sameName) {
      name2ctx.remove(ctx.name());
    }
    name2ctx.put(newName, newCtx);

    ChannelPipelineException removeException = null;
    ChannelPipelineException addException = null;
    boolean removed = false;
    try {
      callAfterRemove(ctx, forward);
      removed = true;
    } catch (ChannelPipelineException e) {
      removeException = e;
    }

    boolean added = false;
    try {
      callAfterAdd(newCtx);
      added = true;
    } catch (ChannelPipelineException e) {
      addException = e;
    }

    if (!removed && !added) {
      logger.warn(removeException.getMessage(), removeException);
      logger.warn(addException.getMessage(), addException);
      throw new ChannelPipelineException(
          "Both "
              + ctx.handler().getClass().getName()
              + ".afterRemove() and "
              + newCtx.handler().getClass().getName()
              + ".afterAdd() failed; see logs.");
    } else if (!removed) {
      throw removeException;
    } else if (!added) {
      throw addException;
    }
  }
コード例 #2
0
  private void addLast0(final String name, DefaultChannelHandlerContext newCtx) {
    DefaultChannelHandlerContext prev = tail.prev;
    newCtx.prev = prev;
    newCtx.next = tail;

    callBeforeAdd(newCtx);

    prev.next = newCtx;
    tail.prev = newCtx;

    name2ctx.put(name, newCtx);

    callAfterAdd(newCtx);
  }
コード例 #3
0
  private void addBefore0(
      final String name, DefaultChannelHandlerContext ctx, DefaultChannelHandlerContext newCtx) {

    newCtx.prev = ctx.prev;
    newCtx.next = ctx;

    callBeforeAdd(newCtx);

    ctx.prev.next = newCtx;
    ctx.prev = newCtx;
    name2ctx.put(name, newCtx);

    callAfterAdd(newCtx);
  }
コード例 #4
0
  private void addFirst0(String name, DefaultChannelHandlerContext newCtx) {
    DefaultChannelHandlerContext nextCtx = head.next;
    newCtx.prev = head;
    newCtx.next = nextCtx;

    callBeforeAdd(newCtx);

    head.next = newCtx;
    nextCtx.prev = newCtx;

    name2ctx.put(name, newCtx);

    callAfterAdd(newCtx);
  }
コード例 #5
0
  private void addAfter0(
      final String name, DefaultChannelHandlerContext ctx, DefaultChannelHandlerContext newCtx) {
    checkDuplicateName(name);

    newCtx.prev = ctx;
    newCtx.next = ctx.next;

    callBeforeAdd(newCtx);

    ctx.next.prev = newCtx;
    ctx.next = newCtx;

    name2ctx.put(name, newCtx);

    callAfterAdd(newCtx);
  }