Source:
<code>public void emitImmediately(Map<AbstractKafkaPartitioner.PartitionMeta, Pair<Long, Long>> windowData) { for (Map.Entry<AbstractKafkaPartitioner.PartitionMeta, Pair<Long, Long>> windowEntry : windowData.entrySet()) { AbstractKafkaPartitioner.PartitionMeta meta = windowEntry.getKey(); Pair<Long, Long> replayOffsetSize = windowEntry.getValue(); KafkaConsumer<byte[], byte[]> kc = consumers.get(meta.getCluster()); if (kc == null && kc.assignment().contains(windowEntry.getKey().getTopicPartition())) { throw new RuntimeException("Coundn't find consumer to replay the message PartitionMeta : " + meta); } for (TopicPartition tp : kc.assignment()) { if (meta.getTopicPartition().equals(tp)) { kc.resume(tp); } else { <START> try { <END> kc.position(tp); } catch (NoOffsetForPartitionException e) { kc.seekToBeginning(tp); } kc.pause(tp); } } kc.seek(meta.getTopicPartition(), replayOffsetSize.getLeft()); long windowCount = replayOffsetSize.getRight(); while (windowCount > 0) { try { ConsumerRecords<byte[], byte[]> records = kc.poll(ownerOperator.getConsumerTimeout()); for (Iterator<ConsumerRecord<byte[], byte[]>> cri = records.iterator(); cri.hasNext() && windowCount > 0;) { ownerOperator.emitTuple(meta.getCluster(), cri.next()); windowCount--; } } catch (NoOffsetForPartitionException e) { throw new RuntimeException("Couldn't replay the offset", e); } } kc.seek(meta.getTopicPartition(), replayOffsetSize.getLeft() + replayOffsetSize.getRight()); } for (KafkaConsumer<byte[], byte[]> kc : consumers.values()) { kc.resume(Iterables.toArray(kc.assignment(), TopicPartition.class)); } }</code><technical_language>do need catch exception here? reposition some partition beginning is correct</technical_language>

Target:
public void emitImmediately(Map<AbstractKafkaPartitioner.PartitionMeta, Pair<Long, Long>> windowData) { for (Map.Entry<AbstractKafkaPartitioner.PartitionMeta, Pair<Long, Long>> windowEntry : windowData.entrySet()) { AbstractKafkaPartitioner.PartitionMeta meta = windowEntry.getKey(); Pair<Long, Long> replayOffsetSize = windowEntry.getValue(); KafkaConsumer<byte[], byte[]> kc = consumers.get(meta.getCluster()); if (kc == null && kc.assignment().contains(windowEntry.getKey().getTopicPartition())) { throw new RuntimeException("Coundn't find consumer to replay the message PartitionMeta : " + meta); } for (TopicPartition tp : kc.assignment()) { if (meta.getTopicPartition().equals(tp)) { kc.resume(tp); } else { try { kc.position(tp); } catch (NoOffsetForPartitionException e) { handleNoOffsetForPartitionException(e, kc); } kc.pause(tp); } } kc.seek(meta.getTopicPartition(), replayOffsetSize.getLeft()); long windowCount = replayOffsetSize.getRight(); while (windowCount > 0) { try { ConsumerRecords<byte[], byte[]> records = kc.poll(ownerOperator.getConsumerTimeout()); for (Iterator<ConsumerRecord<byte[], byte[]>> cri = records.iterator(); cri.hasNext() && windowCount > 0;) { ownerOperator.emitTuple(meta.getCluster(), cri.next()); windowCount--; } } catch (NoOffsetForPartitionException e) { throw new RuntimeException("Couldn't replay the offset", e); } } kc.seek(meta.getTopicPartition(), replayOffsetSize.getLeft() + replayOffsetSize.getRight()); } for (KafkaConsumer<byte[], byte[]> kc : consumers.values()) { kc.resume(Iterables.toArray(kc.assignment(), TopicPartition.class)); } }