CAMEL-11694 - Camel-Hazelcast: Add more operation to queue - Retain All operation
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a9f4c55e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a9f4c55e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a9f4c55e Branch: refs/heads/master Commit: a9f4c55e00c7d5999945428a84c51ee93ca4a72d Parents: 04a8a84 Author: Andrea Cosentino <anco...@gmail.com> Authored: Wed Aug 23 10:35:50 2017 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Wed Aug 23 10:35:50 2017 +0200 ---------------------------------------------------------------------- .../hazelcast/queue/HazelcastQueueProducer.java | 9 +++++++++ .../component/hazelcast/HazelcastQueueProducerTest.java | 11 +++++++++++ 2 files changed, 20 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a9f4c55e/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java index b8350d3..7649362 100644 --- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java +++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/queue/HazelcastQueueProducer.java @@ -100,6 +100,10 @@ public class HazelcastQueueProducer extends HazelcastDefaultProducer { case TAKE: this.take(exchange); break; + + case RETAIN_ALL: + this.retainAll(exchange); + break; default: throw new IllegalArgumentException(String.format("The value '%s' is not allowed for parameter '%s' on the QUEUE cache.", operation, HazelcastConstants.OPERATION)); @@ -164,4 +168,9 @@ public class HazelcastQueueProducer extends HazelcastDefaultProducer { private void take(Exchange exchange) throws InterruptedException { exchange.getOut().setBody(this.queue.take()); } + + private void retainAll(Exchange exchange) { + Collection body = exchange.getIn().getBody(Collection.class); + this.queue.retainAll(body); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a9f4c55e/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java index b88aa18..60b3c2a 100644 --- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java +++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueProducerTest.java @@ -153,6 +153,14 @@ public class HazelcastQueueProducerTest extends HazelcastCamelTestSupport { } @Test + public void retainAll() throws InterruptedException { + Collection c = new HashSet<>(); + c.add("foo2"); + template.sendBody("direct:retainAll", c); + verify(queue).retainAll(c); + } + + @Test public void drainTo() throws InterruptedException { Map<String, Object> headers = new HashMap<String, Object>(); Collection l = new ArrayList<>(); @@ -197,6 +205,9 @@ public class HazelcastQueueProducerTest extends HazelcastCamelTestSupport { from("direct:take").setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.TAKE)).to( String.format("hazelcast-%sbar", HazelcastConstants.QUEUE_PREFIX)); + from("direct:retainAll").setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.RETAIN_ALL)).to( + String.format("hazelcast-%sbar", HazelcastConstants.QUEUE_PREFIX)); + from("direct:drainTo").setHeader(HazelcastConstants.OPERATION, constant(HazelcastOperation.DRAIN_TO)).to( String.format("hazelcast-%sbar", HazelcastConstants.QUEUE_PREFIX));