public synchronized int forEach(PayloadQueue.ElementVisitor reader) throws IOException {
    int position = first.position;
    for (int i = 0; i < elementCount; i++) {
      Element current = readElement(position);
      boolean shouldContinue = reader.read(new ElementInputStream(current), current.length);
      if (!shouldContinue) {
        return i + 1;
      }
      position = wrapPosition(current.position + Element.HEADER_LENGTH + current.length);
    }
    return elementCount;
  }
public synchronized int forEach ( PayloadQueue . ElementVisitor reader ) throws IOException { int position = first . position ; for ( int i = 0 ; i < elementCount ; i ++ ) { Element current = readElement ( position ) ; boolean shouldContinue = reader . read ( new ElementInputStream ( current ) , current . length ) ; if ( ! shouldContinue ) { return i + 1 ; } position = wrapPosition ( current . position + Element . HEADER_LENGTH + current . length ) ; } return elementCount ; }
Invokes the given reader once for each element in the queue, from eldest to most recently
added. Continues until all elements are read or {@link PayloadQueue.ElementVisitor#read
reader.read()} returns {@code false}.

@return number of elements visited