int count = 0;
List<Long> inTransactionMsgIds = new ArrayList<Long>();
while (it.hasNext()) {
final int prevOffset = it.getOffset();
try {
final Message msg = it.next();
// If the message is processed before,don't process it
// again.
if (this.isProcessed(msg.getId(), group)) {
continue;
}
MessageAccessor.setPartition(msg, partition);
boolean accept = this.isAcceptable(request, filter, group, msg);
if (accept) {
currentTopicRegInfo.set(request.getTopicPartitionRegInfo().clone(it));
try {
listener.recieveMessages(msg);
}
finally {
currentTopicRegInfo.remove();
}
}
// rollback message if it is in rollback only state.
if (MessageAccessor.isRollbackOnly(msg)) {
it.setOffset(prevOffset);
break;
}
if (partition.isAutoAck()) {
count++;
this.markProcessed(msg.getId(), group);
}
else {
// �ύ���ع�����������ѭ��
if (partition.isAcked()) {
count++;
// mark all in transaction messages were processed.
for (Long msgId : inTransactionMsgIds) {
this.markProcessed(msgId, group);
}
this.markProcessed(msg.getId(), group);
break;
}
else if (partition.isRollback()) {
break;
}
else {
inTransactionMsgIds.add(msg.getId());
// �����ύҲ���ǻع�������������
count++;
}
}
}