james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/6] james-project git commit: JAMES-2332 Slightly improve JMSMailQueue :: getSize
Date Thu, 08 Feb 2018 09:05:23 GMT
JAMES-2332 Slightly improve JMSMailQueue :: getSize


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/67d6b677
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/67d6b677
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/67d6b677

Branch: refs/heads/master
Commit: 67d6b6779f7fa4ae70e96ce30c21c8f53500571e
Parents: b8229df
Author: benwa <btellier@linagora.com>
Authored: Tue Feb 6 10:37:18 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Feb 6 10:38:15 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/queue/jms/JMSMailQueue.java | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/67d6b677/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
index c6d17d8..dd545a6 100644
--- a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
+++ b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
@@ -50,6 +50,7 @@ import javax.mail.MessagingException;
 import javax.mail.internet.AddressException;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.commons.collections.iterators.EnumerationIterator;
 import org.apache.james.core.MailAddress;
 import org.apache.james.lifecycle.api.Disposable;
 import org.apache.james.metrics.api.Metric;
@@ -67,6 +68,7 @@ import org.slf4j.LoggerFactory;
 import org.threeten.extra.Temporals;
 
 import com.google.common.base.Throwables;
+import com.google.common.collect.Iterators;
 
 /**
  * <p>
@@ -481,21 +483,13 @@ public class JMSMailQueue implements ManageableMailQueue, JMSSupport,
MailPriori
         return JAMES_NEXT_DELIVERY + " <= " + System.currentTimeMillis() + " OR " + FORCE_DELIVERY
+ " = true";
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public long getSize() throws MailQueueException {
         QueueBrowser browser = null;
-        int size = 0;
         try {
             browser = session.createBrowser(queue);
-
-            Enumeration<Message> messages = browser.getEnumeration();
-
-            while (messages.hasMoreElements()) {
-                messages.nextElement();
-                size++;
-            }
-            return size;
+            Enumeration enumeration = browser.getEnumeration();
+            return Iterators.size(new EnumerationIterator(enumeration));
         } catch (Exception e) {
             LOGGER.error("Unable to get size of queue {}", queueName, e);
             throw new MailQueueException("Unable to get size of queue " + queueName, e);


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message