コード例 #1
0
ファイル: Publication.java プロジェクト: krisskross/Aeron
  private long newPosition(
      final int activeTermId,
      final int activeIndex,
      final int currentTail,
      final long position,
      final int nextOffset) {
    long newPosition = BACK_PRESSURED;
    if (nextOffset > 0) {
      newPosition = (position - currentTail) + nextOffset;
    } else if (nextOffset == TermAppender.TRIPPED) {
      final int newTermId = activeTermId + 1;
      final int nextIndex = nextPartitionIndex(activeIndex);
      final int nextNextIndex = nextPartitionIndex(nextIndex);

      defaultHeaderTermId(logMetaDataBuffer, nextIndex, newTermId);

      // Need to advance the term id in case a publication takes an interrupt
      // between reading the active term and incrementing the tail.
      // This covers the case of an interrupt taking longer than
      // the time taken to complete the current term.
      defaultHeaderTermId(logMetaDataBuffer, nextNextIndex, newTermId + 1);

      termAppenders[nextNextIndex].statusOrdered(NEEDS_CLEANING);
      LogBufferDescriptor.activeTermId(logMetaDataBuffer, newTermId);

      newPosition = ADMIN_ACTION;
    }

    return newPosition;
  }