@Override
  public synchronized void remove() throws CacheException {
    if (peekedIds.isEmpty()) {
      return;
    }
    boolean wasEmpty = lastDispatchedKey == lastDestroyedKey;
    Long key = peekedIds.remove();
    boolean isExtraPeekedId = extraPeekedIds.contains(key);
    if (!isExtraPeekedId) {
      updateHeadKey(key);
      lastDispatchedKey = key;
    } else {
      extraPeekedIdsRemovedButPreviousIdNotRemoved.add(key);
    }
    removeIndex(key);
    // Remove the entry at that key with a callback arg signifying it is
    // a WAN queue so that AbstractRegionEntry.destroy can get the value
    // even if it has been evicted to disk. In the normal case, the
    // AbstractRegionEntry.destroy only gets the value in the VM.
    try {
      region.localDestroy(key, WAN_QUEUE_TOKEN);
      stats.decQueueSize();
    } catch (EntryNotFoundException ok) {
      // this is acceptable because the conflation can remove entries
      // out from underneath us.
      if (logger.isDebugEnabled()) {
        logger.debug(
            "{}: Did not destroy entry at {} it was not there. It should have been removed by conflation.",
            this, key);
      }
    }

    // For those extraPeekedIds removed that are consecutive to lastDispatchedKey:
    // - Update lastDispatchedKey with them so that they are removed
    // by the batch removal thread.
    // - Update the head key with them.
    // - Remove them from extraPeekedIds.
    long tmpKey = lastDispatchedKey;
    while (extraPeekedIdsRemovedButPreviousIdNotRemoved.contains(tmpKey = inc(tmpKey))) {
      extraPeekedIdsRemovedButPreviousIdNotRemoved.remove(tmpKey);
      extraPeekedIds.remove(tmpKey);
      updateHeadKey(tmpKey);
      lastDispatchedKey = tmpKey;
    }

    if (wasEmpty) {
      synchronized (this) {
        notifyAll();
      }
    }

    if (logger.isDebugEnabled()) {
      logger.debug(
          "{}: Destroyed entry at key {} setting the lastDispatched Key to {}. The last destroyed entry was {}",
          this, key, lastDispatchedKey, lastDestroyedKey);
    }
  }
This method removes the last entry. However, it will only let the user remove entries that they
have peeked. If the entry was not peeked, this method will silently return.
geode-core/src/main/java/org/apache/geode/internal/cache/wan/serial/SerialGatewaySenderQueue.java