You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2026/04/07 09:43:17 UTC
(james-project) 02/02: JAMES-4199 refactor ActiveMQ browsing code for better readability
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 9dc05da10b3c5720ea8f0c0cac871283cb1c24cf
Author: ouvtam <ou...@8n4.pw>
AuthorDate: Tue Apr 7 08:37:31 2026 +0200
JAMES-4199 refactor ActiveMQ browsing code for better readability
---
.../james/queue/jms/JMSCacheableMailQueue.java | 73 ++++++++++++----------
1 file changed, 39 insertions(+), 34 deletions(-)
diff --git a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSCacheableMailQueue.java b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSCacheableMailQueue.java
index aaec36ea11..cba434d514 100644
--- a/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSCacheableMailQueue.java
+++ b/server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSCacheableMailQueue.java
@@ -675,52 +675,57 @@ public class JMSCacheableMailQueue implements ManageableMailQueue, JMSSupport, M
QueueBrowser browser = null;
try {
browser = session.createBrowser(queue);
-
Enumeration<Message> messages = browser.getEnumeration();
- QueueBrowser myBrowser = browser;
+ return new BrowsingMailQueueIterator(browser, messages);
+ } catch (Exception e) {
+ closeBrowser(browser);
- return new MailQueueIterator() {
+ LOGGER.error("Unable to browse queue {}", queueName, e);
+ throw new MailQueueException("Unable to browse queue " + queueName.asString(), e);
+ }
+ }
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Read-only");
- }
+ private final class BrowsingMailQueueIterator implements MailQueueIterator {
+ private final QueueBrowser browser;
+ private final Enumeration<Message> messages;
- @Override
- public MailQueueItemView next() {
- while (hasNext()) {
- try {
- Message m = messages.nextElement();
- return new DefaultMailQueueItemView(createMail(m), nextDeliveryDate(m));
- } catch (MessagingException | JMSException e) {
- LOGGER.error("Unable to browse queue", e);
- }
- }
+ private BrowsingMailQueueIterator(QueueBrowser browser, Enumeration<Message> messages) {
+ this.browser = browser;
+ this.messages = messages;
+ }
- throw new NoSuchElementException();
- }
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException("Read-only");
+ }
- private ZonedDateTime nextDeliveryDate(Message m) throws JMSException {
- long nextDeliveryTimestamp = m.getLongProperty(JAMES_NEXT_DELIVERY);
- return Instant.ofEpochMilli(nextDeliveryTimestamp).atZone(ZoneId.systemDefault());
+ @Override
+ public MailQueueItemView next() {
+ while (hasNext()) {
+ try {
+ Message m = messages.nextElement();
+ return new DefaultMailQueueItemView(createMail(m), nextDeliveryDate(m));
+ } catch (MessagingException | JMSException e) {
+ LOGGER.error("Unable to browse queue", e);
}
+ }
- @Override
- public boolean hasNext() {
- return messages.hasMoreElements();
- }
+ throw new NoSuchElementException();
+ }
- @Override
- public void close() {
- closeBrowser(myBrowser);
- }
- };
+ @Override
+ public boolean hasNext() {
+ return messages.hasMoreElements();
+ }
- } catch (Exception e) {
+ @Override
+ public void close() {
closeBrowser(browser);
+ }
- LOGGER.error("Unable to browse queue {}", queueName, e);
- throw new MailQueueException("Unable to browse queue " + queueName.asString(), e);
+ private ZonedDateTime nextDeliveryDate(Message m) throws JMSException {
+ long nextDeliveryTimestamp = m.getLongProperty(JAMES_NEXT_DELIVERY);
+ return Instant.ofEpochMilli(nextDeliveryTimestamp).atZone(ZoneId.systemDefault());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org