Exemplo n.º 1
0
  public static void pingHandler(
      final Publication pongPublication,
      final DirectBuffer buffer,
      final int offset,
      final int length) {
    if (pongPublication.offer(buffer, offset, length) < 0L) {
      return;
    }

    PING_HANDLER_IDLE_STRATEGY.reset();

    while (pongPublication.offer(buffer, offset, length) < 0L) {
      PING_HANDLER_IDLE_STRATEGY.idle();
    }
  }
Exemplo n.º 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();
      }
    }
  }