示例#1
0
  private void cleanBufferTo(final long newCleanPosition) {
    final long cleanPosition = this.cleanPosition;
    final int bytesForCleaning = (int) (newCleanPosition - cleanPosition);
    final UnsafeBuffer dirtyTerm = termBuffers[indexByPosition(cleanPosition, positionBitsToShift)];
    final int termOffset = (int) cleanPosition & termLengthMask;
    final int length = Math.min(bytesForCleaning, dirtyTerm.capacity() - termOffset);

    if (length > 0) {
      dirtyTerm.setMemory(termOffset, length, (byte) 0);
      this.cleanPosition = cleanPosition + length;
    }
  }
示例#2
0
  private static void roundTripMessages(
      final FragmentHandler fragmentHandler,
      final Publication pingPublication,
      final Subscription pongSubscription,
      final int numMessages) {
    final IdleStrategy idleStrategy = new BusySpinIdleStrategy();

    for (int i = 0; i < numMessages; i++) {
      do {
        ATOMIC_BUFFER.putLong(0, System.nanoTime());
      } while (pingPublication.offer(ATOMIC_BUFFER, 0, MESSAGE_LENGTH) < 0L);

      idleStrategy.reset();
      while (pongSubscription.poll(fragmentHandler, FRAGMENT_COUNT_LIMIT) <= 0) {
        idleStrategy.idle();
      }
    }
  }
示例#3
0
 private boolean isHeartbeat(final UnsafeBuffer packet, final int length) {
   return length == DataHeaderFlyweight.HEADER_LENGTH && packet.getInt(0) == 0;
 }