@Override
  public List peek(int batchSize, int timeToWait) {
    long start = System.currentTimeMillis();
    long end = start + timeToWait;
    if (logger.isTraceEnabled()) {
      logger.trace("{}: Peek start time={} end time={} time to wait={}", this, start, end,
          timeToWait);
    }

    // If we're full, just return the results.
    List result = doReturn(batchSize, batchSize);
    if (result != null) {
      return result;
    }

    // Need to wait for a while.
    for (;;) {
      region.getCache().getCancelCriterion().checkCancelInProgress(null);
      result = doReturn(batchSize, batchSize);
      if (result != null) {
        return result; // full now
      }

      // If time to wait is -1 (don't wait) or time interval has elapsed
      long currentTime = System.currentTimeMillis();
      if (logger.isTraceEnabled()) {
        logger.trace("{}: Peek current time: {}", this, currentTime);
      }
      if (timeToWait == -1 || currentTime >= end) {
        if (logger.isTraceEnabled()) {
          logger.trace("{}: Peek timed out", this);
        }
        // Return whatever's there.
        result = doReturn(0, batchSize);
        Assert.assertTrue(result != null);
        return result;
      }

      // Sleep a bit before trying again.
      if (logger.isTraceEnabled()) {
        logger.trace("{}: Peek continuing", this);
      }
      boolean interrupted = Thread.interrupted();
      try {
        Thread.sleep(50); // TODO this seems kinda busy IMNSHO -- jason
      } catch (InterruptedException ignore) {
        interrupted = true;
        region.getCancelCriterion().checkCancelInProgress(null);
      } finally {
        if (interrupted) {
          Thread.currentThread().interrupt();
        }
      }
    } // for
  }
Peeks either a batchSize number of elements from the queue or until timeToWait milliseconds
have elapsed (whichever comes first). If it has peeked batchSize number of elements from the
queue before timeToWait milliseconds have elapsed, it stops peeking. If timeToWait milliseconds
elapse before batchSize number of elements has been peeked, it stops. All the counters peeked
for the batch are added to the thread-context, so that upon calling of remove(), all the peeked
events of the batch are removed from the queue.

If the Queue is non blocking multiple peek operations can proceed but if it is of type non
blocking only one peek operation will proceed as the blocking queue does not use ReadWriteLock

@param batchSize The number of objects to peek from the queue
@param timeToWait The number of milliseconds to attempt to peek

@return The list of events peeked
geode-core/src/main/java/org/apache/geode/internal/cache/ha/HARegionQueue.java