Source:
<code>public Map<SystemStreamPartition, List<IncomingMessageEnvelope>> poll(Set<SystemStreamPartition> systemStreamPartitions, long timeout) throws InterruptedException { long stopTime = clock.currentTimeMillis() + timeout; Map<SystemStreamPartition, List<IncomingMessageEnvelope>> messagesToReturn = new HashMap<SystemStreamPartition, List<IncomingMessageEnvelope>>(); metrics.incPoll(); for (SystemStreamPartition systemStreamPartition : systemStreamPartitions) { BlockingQueue<IncomingMessageEnvelope> queue = bufferedMessages.get(systemStreamPartition); List<IncomingMessageEnvelope> outgoingList = new ArrayList<IncomingMessageEnvelope>(queue.size()); if (queue.size() > 0) { queue.drainTo(outgoingList); } else if (timeout != 0) { IncomingMessageEnvelope envelope = null; long timeRemaining = stopTime - clock.currentTimeMillis(); if (timeout == SystemConsumer.BLOCK_ON_OUTSTANDING_MESSAGES) { <START> while (envelope == null && !isAtHead(systemStreamPartition) && !isConsumerFailed()) { <END> metrics.incBlockingPoll(systemStreamPartition); envelope = queue.poll(1000, TimeUnit.MILLISECONDS); } } else if (timeout > 0 && timeRemaining > 0) { metrics.incBlockingTimeoutPoll(systemStreamPartition); envelope = queue.poll(timeRemaining, TimeUnit.MILLISECONDS); } if (envelope != null) { outgoingList.add(envelope); queue.drainTo(outgoingList); } } if (outgoingList.size() > 0) { messagesToReturn.put(systemStreamPartition, outgoingList); subtractSizeOnQDrain(systemStreamPartition, outgoingList); } } return messagesToReturn; }</code><technical_language>Nitpick: Reverse order of isConsumerFailed isAtHead</technical_language>

Target:
public Map<SystemStreamPartition, List<IncomingMessageEnvelope>> poll(Set<SystemStreamPartition> systemStreamPartitions, long timeout) throws InterruptedException { long stopTime = clock.currentTimeMillis() + timeout; Map<SystemStreamPartition, List<IncomingMessageEnvelope>> messagesToReturn = new HashMap<SystemStreamPartition, List<IncomingMessageEnvelope>>(); metrics.incPoll(); for (SystemStreamPartition systemStreamPartition : systemStreamPartitions) { BlockingQueue<IncomingMessageEnvelope> queue = bufferedMessages.get(systemStreamPartition); List<IncomingMessageEnvelope> outgoingList = new ArrayList<IncomingMessageEnvelope>(queue.size()); if (queue.size() > 0) { queue.drainTo(outgoingList); } else if (timeout != 0) { IncomingMessageEnvelope envelope = null; long timeRemaining = stopTime - clock.currentTimeMillis(); if (timeout == SystemConsumer.BLOCK_ON_OUTSTANDING_MESSAGES) { while (envelope == null && !isAtHead(systemStreamPartition)) { if (this.failureCause != null) { String message = String.format("%s: Consumer has stopped.", this); throw new SamzaException(message, this.failureCause); } metrics.incBlockingPoll(systemStreamPartition); envelope = queue.poll(1000, TimeUnit.MILLISECONDS); } } else if (timeout > 0 && timeRemaining > 0) { metrics.incBlockingTimeoutPoll(systemStreamPartition); envelope = queue.poll(timeRemaining, TimeUnit.MILLISECONDS); } if (envelope != null) { outgoingList.add(envelope); queue.drainTo(outgoingList); } } if (outgoingList.size() > 0) { messagesToReturn.put(systemStreamPartition, outgoingList); subtractSizeOnQDrain(systemStreamPartition, outgoingList); } } return messagesToReturn; }