private void prepend(FrameBytes frameBytes) {
    Throwable failure;
    synchronized (queue) {
      failure = this.failure;
      if (failure == null) {
        int index = 0;
        while (index < queue.size()) {
          FrameBytes element = queue.get(index);
          if (element.compareTo(frameBytes) <= 0) break;
          ++index;
        }
        queue.add(index, frameBytes);
      }
    }

    if (failure != null) frameBytes.fail(new SPDYException(failure));
  }
  private void append(FrameBytes frameBytes) {
    Throwable failure;
    synchronized (queue) {
      failure = this.failure;
      if (failure == null) {
        // Frames containing headers must be send in the order the headers have been generated. We
        // don't need
        // to do this check in StandardSession.prepend() as no frames containing headers will be
        // prepended.
        if (frameBytes instanceof ControlFrameBytes) queue.addLast(frameBytes);
        else {
          int index = queue.size();
          while (index > 0) {
            FrameBytes element = queue.get(index - 1);
            if (element.compareTo(frameBytes) >= 0) break;
            --index;
          }
          queue.add(index, frameBytes);
        }
      }
    }

    if (failure != null) frameBytes.fail(new SPDYException(failure));
  }