code: List<List<BlockInfo>> chooseUnderReplicatedBlocks(int blocksToProcess) {
      // initialize data structure for the return value
      List<List<BlockInfo>> blocksToReplicate =
        new ArrayList<List<BlockInfo>>(UnderReplicatedBlocks.LEVEL);
      for (int i = 0; i < UnderReplicatedBlocks.LEVEL; i++) {
        blocksToReplicate.add(new ArrayList<BlockInfo>());
      }
  
      writeLock();
      try {
        synchronized (neededReplications) {
          if (neededReplications.size() == 0) {
            return blocksToReplicate;
          }
  
          for (int priority = 0; priority<UnderReplicatedBlocks.LEVEL; priority++) {
          // Go through all blocks that need replications of priority
          BlockIterator neededReplicationsIterator = neededReplications.iterator(priority);
          int numBlocks = neededReplications.size(priority);
          if (replIndex[priority] > numBlocks) {
            replIndex[priority] = 0;
          }
          // skip to the first unprocessed block, which is at replIndex
          for (int i = 0; i < replIndex[priority] && neededReplicationsIterator.hasNext(); i++) {
            neededReplicationsIterator.next();
          }
          // # of blocks to process for this priority
          int blocksToProcessIter = getQuotaForThisPriority(blocksToProcess,
              numBlocks, neededReplications.getSize(priority+1));
          blocksToProcess -= blocksToProcessIter;
  
          for (int blkCnt = 0; blkCnt < blocksToProcessIter; blkCnt++, replIndex[priority]++) {
            if (!neededReplicationsIterator.hasNext()) {
              // start from the beginning
              replIndex[priority] = 0;
              neededReplicationsIterator = neededReplications.iterator(priority);
              assert neededReplicationsIterator.hasNext() :
                "neededReplications should not be empty.";
            }
  
            BlockInfo block = neededReplicationsIterator.next();
            blocksToReplicate.get(priority).add(block);
          } // end for
          }
        } // end try
        return blocksToReplicate;
      } finally {
        writeUnlock();
      }
    }
docs: Get a list of block lists to be replicated
  The index of block lists represents the
  
  @param blocksToProcess
  @return Return a list of block lists to be replicated.
  The block list index represents its replication priority.