private List getBatchAndUpdateThreadContext(int batchSize) {
    Iterator<Long> itr = idsAvailable.iterator();
    int currSize = idsAvailable.size();
    int limit = Math.min(currSize, batchSize);
    List batch = new ArrayList<>(limit);

    List<Long> peekedEventsThreadContext;
    if ((peekedEventsThreadContext =
        (List<Long>) HARegionQueue.peekedEventsContext.get()) == null) {
      peekedEventsThreadContext = new LinkedList<>();
    }
    for (int i = 0; i < limit; i++) {
      Long counter = itr.next();
      Object eventOrWrapper = region.get(counter);
      Object event;
      if (eventOrWrapper instanceof HAEventWrapper) {
        event = haContainer.get(eventOrWrapper);
        if (event == null) {
          event = ((HAEventWrapper) eventOrWrapper).getClientUpdateMessage();
        }
      } else {
        event = eventOrWrapper;
      }
      if (event != null) {
        batch.add(event);
      }
      peekedEventsThreadContext.add(counter);
    }

    HARegionQueue.peekedEventsContext.set(peekedEventsThreadContext);
    return batch;
  }
This method prepares the batch of events and updates the thread-context with corresponding
counters, so that when remove is called by this thread, these events are destroyed from the
queue.This method should always be invoked within the {@code rwLock}.

@param batchSize - number of events to be peeked
@return - list of events peeked
geode-core/src/main/java/org/apache/geode/internal/cache/ha/HARegionQueue.java