You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by er...@apache.org on 2013/02/06 07:45:09 UTC
svn commit: r1442850 -
/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
Author: eric
Date: Wed Feb 6 06:45:09 2013
New Revision: 1442850
URL: http://svn.apache.org/viewvc?rev=1442850&view=rev
Log:
More effective implementation of StoreMessageResultIterator, patch contributed by Peter Kvokacka (MAILBOX-191)
Modified:
james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java?rev=1442850&r1=1442849&r2=1442850&view=diff
==============================================================================
--- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java (original)
+++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java Wed Feb 6 06:45:09 2013
@@ -49,7 +49,6 @@ public class StoreMessageResultIterator<
private long to;
private int batchSize;
private Type type;
- private boolean done = false;
private MessageMapper<Id> mapper;
private FetchType ftype;
@@ -112,15 +111,19 @@ public class StoreMessageResultIterator<
@Override
public boolean hasNext() {
- if (!done && (next == null || !next.hasNext())) {
+ if (cursor > to)
+ return false;
+
+ if (next == null || !next.hasNext()) {
try {
readBatch();
} catch (MailboxException e) {
this.exception = e;
- done = true;
+ return false;
}
}
- return !done;
+
+ return next.hasNext();
}
private void readBatch() throws MailboxException {
@@ -142,33 +145,24 @@ public class StoreMessageResultIterator<
break;
}
next = mapper.findInMailbox(mailbox, range, ftype, batchSize);
- if (!next.hasNext()) {
- done = true;
- }
}
@Override
public MessageResult next() {
- if (hasNext()) {
- final Message<Id> message = next.next();
- MessageResult result;
- try {
- result = ResultUtils.loadMessageResult(message, group);
- cursor = result.getUid();
- } catch (MailboxException e) {
- result = new UnloadedMessageResult<Id>(message, e);
- }
-
- cursor++;
- // move the start UID behind the last fetched message UID if needed
- if (hasNext()) {
- if (cursor > to) {
- done = true;
- }
- }
- return result;
+ if (next == null || !next.hasNext())
+ throw new NoSuchElementException();
+
+ final Message<Id> message = next.next();
+ MessageResult result;
+ try {
+ result = ResultUtils.loadMessageResult(message, group);
+ cursor = result.getUid();
+ } catch (MailboxException e) {
+ result = new UnloadedMessageResult<Id>(message, e);
}
- throw new NoSuchElementException();
+
+ cursor++;
+ return result;
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org