@VisibleForTesting
  public KeyAndEventPair peekAhead() throws CacheException {
    AsyncEvent<?, ?> object = null;
    Long currentKey = getCurrentKey();
    if (currentKey == null) {
      return null;
    }

    // It's important here that we check where the current key
    // is in relation to the tail key before we check to see if the
    // object exists. The reason is that the tail key is basically
    // the synchronization between this thread and the putter thread.
    // The tail key will not be incremented until the object is put in the
    // region
    // If we check for the object, and then check the tail key, we could
    // skip objects.

    // TODO: don't do a get which updates the lru, instead just get the value
    // w/o modifying the LRU.
    // Note: getting the serialized form here (if it has overflowed to disk)
    // does not save anything since GatewayBatchOp needs to GatewayEventImpl
    // in object form.
    while (before(currentKey, getTailKey())) {
      if (!extraPeekedIds.contains(currentKey)) {
        object = getObjectInSerialSenderQueue(currentKey);
        if (object != null) {
          break;
        }
      }
      if (logger.isTraceEnabled()) {
        logger.trace("{}: Trying head key + offset: {}", this, currentKey);
      }
      currentKey = inc(currentKey);
      // When mustGroupTransactionEvents is true, conflation cannot be enabled.
      // Therefore, if we reach here, it would not be due to a conflated event
      // but rather to an extra peeked event already sent.
      if (!mustGroupTransactionEvents() && stats != null) {
        stats.incEventsNotQueuedConflated();
      }
    }

    if (logger.isDebugEnabled()) {
      logger.debug("{}: Peeked {}->{}", this, currentKey, object);
    }

    if (object != null) {
      peekedIds.add(currentKey);
      lastPeekedId.set(currentKey);
      return new KeyAndEventPair(currentKey, object);
    }
    return null;
  }
Finds the next object after the last key peeked
geode-core/src/main/java/org/apache/geode/internal/cache/wan/serial/SerialGatewaySenderQueue.java