Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AEE71CA32 for ; Tue, 12 Aug 2014 08:38:50 +0000 (UTC) Received: (qmail 48025 invoked by uid 500); 12 Aug 2014 08:38:50 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 47883 invoked by uid 500); 12 Aug 2014 08:38:50 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 47867 invoked by uid 99); 12 Aug 2014 08:38:50 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Aug 2014 08:38:50 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 47D838A71EF; Tue, 12 Aug 2014 08:38:50 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Tue, 12 Aug 2014 08:38:51 -0000 Message-Id: <6930a3f4664d4d67aabfd2c8aa7adaae@git.apache.org> In-Reply-To: <2f45287492a7479989105de4909e1c3d@git.apache.org> References: <2f45287492a7479989105de4909e1c3d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] git commit: CAMEL-7649: camel-jms - The QueueBrowseStrategy need support for JMS Selector CAMEL-7649: camel-jms - The QueueBrowseStrategy need support for JMS Selector Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a73ea67f Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a73ea67f Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a73ea67f Branch: refs/heads/camel-2.12.x Commit: a73ea67f0ff4463cd8f187f13970dcbb31864128 Parents: ef824f2 Author: Claus Ibsen Authored: Wed Jul 30 16:43:16 2014 +0200 Committer: Claus Ibsen Committed: Tue Aug 12 10:38:38 2014 +0200 ---------------------------------------------------------------------- .../jms/DefaultQueueBrowseStrategy.java | 23 ++++++++++++++++++++ .../camel/component/jms/JmsQueueEndpoint.java | 6 ++++- .../component/jms/QueueBrowseStrategy.java | 2 ++ .../camel/component/jms/JmsSelectorInTest.java | 6 ++++- 4 files changed, 35 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a73ea67f/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java index e337e4f..f5cb164 100644 --- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java +++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/DefaultQueueBrowseStrategy.java @@ -57,4 +57,27 @@ public class DefaultQueueBrowseStrategy implements QueueBrowseStrategy { } }); } + + @Override + public List browseSelected(final String selector, final JmsOperations template, final String queue, final JmsQueueEndpoint endpoint) { + return template.browseSelected(queue, selector, new BrowserCallback>() { + public List doInJms(Session session, QueueBrowser browser) throws JMSException { + int size = endpoint.getMaximumBrowseSize(); + if (size <= 0) { + size = Integer.MAX_VALUE; + } + + // not the best implementation in the world as we have to browse + // the entire queue, which could be massive + List answer = new ArrayList(); + Enumeration iter = browser.getEnumeration(); + for (int i = 0; i < size && iter.hasMoreElements(); i++) { + Message message = (Message) iter.nextElement(); + Exchange exchange = endpoint.createExchange(message); + answer.add(exchange); + } + return answer; + } + }); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/a73ea67f/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java index cafc1c1..e71c577 100644 --- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java +++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsQueueEndpoint.java @@ -95,7 +95,11 @@ public class JmsQueueEndpoint extends JmsEndpoint implements BrowsableEndpoint { } String queue = getDestinationName(); JmsOperations template = getConfiguration().createInOnlyTemplate(this, false, queue); - return queueBrowseStrategy.browse(template, queue, this); + if (getSelector() != null) { + return queueBrowseStrategy.browseSelected(getSelector(), template, queue, this); + } else { + return queueBrowseStrategy.browse(template, queue, this); + } } @ManagedOperation(description = "Current number of Exchanges in Queue") http://git-wip-us.apache.org/repos/asf/camel/blob/a73ea67f/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java b/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java index d973206..44727a2 100644 --- a/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java +++ b/components/camel-jms/src/main/java/org/apache/camel/component/jms/QueueBrowseStrategy.java @@ -28,4 +28,6 @@ public interface QueueBrowseStrategy { List browse(JmsOperations template, String queue, JmsQueueEndpoint endpoint); + List browseSelected(String selector, JmsOperations template, String queue, JmsQueueEndpoint endpoint); + } http://git-wip-us.apache.org/repos/asf/camel/blob/a73ea67f/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java index 183cc57..00f3482 100644 --- a/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java +++ b/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSelectorInTest.java @@ -41,6 +41,10 @@ public class JmsSelectorInTest extends CamelTestSupport { template.sendBodyAndHeader("activemq:queue:foo", "Santa Rita", "drink", "wine"); mock.assertIsSatisfied(); + + // and there should also only be 2 if browsing as the selector was configured in the route builder + JmsQueueEndpoint endpoint = context.getEndpoint("activemq:queue:foo", JmsQueueEndpoint.class); + assertEquals(2, endpoint.getExchanges().size()); } protected CamelContext createCamelContext() throws Exception { @@ -58,7 +62,7 @@ public class JmsSelectorInTest extends CamelTestSupport { JmsEndpoint endpoint = context.getEndpoint("activemq:queue:foo", JmsEndpoint.class); endpoint.setSelector("drink IN ('beer', 'wine')"); - from(endpoint).to("mock:result"); + from(endpoint).to("log:drink").to("mock:result"); } }; }