You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/12/03 20:01:49 UTC

[1/4] camel git commit: topic consumers support added.

Repository: camel
Updated Branches:
  refs/heads/master 9ecc0cc48 -> 4a5666d46


topic consumers support added.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/69138a10
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/69138a10
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/69138a10

Branch: refs/heads/master
Commit: 69138a105661775ca9f2362fb9d479832baa5a09
Parents: 9e5968c
Author: juanjovazquez <jv...@tecsisa.com>
Authored: Thu Aug 28 14:06:33 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 19:57:21 2014 +0100

----------------------------------------------------------------------
 .../component/hazelcast/HazelcastConstants.java |  3 +
 .../listener/CamelMessageListener.java          | 37 ++++++++
 .../hazelcast/topic/HazelcastTopicConsumer.java | 40 +++++++++
 .../hazelcast/topic/HazelcastTopicEndpoint.java |  5 +-
 .../hazelcast/HazelcastTopicConsumerTest.java   | 91 ++++++++++++++++++++
 .../hazelcast/HazelcastTopicProducerTest.java   |  2 +-
 6 files changed, 175 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/69138a10/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
index ebd20f6..e1a6304 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
@@ -84,6 +84,9 @@ public final class HazelcastConstants {
     public static final String UPDATED = "updated";
     public static final String ADDED = "added";
 
+    // message listener actions (topic)
+    public static final String RECEIVED = "received";
+
     // storage types (map, queue, topic, multimap)
     public static final String MAP = "map";
     public static final String MULTIMAP = "multimap";

http://git-wip-us.apache.org/repos/asf/camel/blob/69138a10/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/listener/CamelMessageListener.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/listener/CamelMessageListener.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/listener/CamelMessageListener.java
new file mode 100644
index 0000000..1a6f60a
--- /dev/null
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/listener/CamelMessageListener.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hazelcast.listener;
+
+import com.hazelcast.core.Message;
+import com.hazelcast.core.MessageListener;
+import org.apache.camel.component.hazelcast.HazelcastConstants;
+import org.apache.camel.component.hazelcast.HazelcastDefaultConsumer;
+
+/**
+ *
+ */
+public class CamelMessageListener extends CamelListener implements MessageListener<Object> {
+
+    public CamelMessageListener(HazelcastDefaultConsumer consumer, String cacheName) {
+        super(consumer, cacheName);
+    }
+
+    public void onMessage(Message<Object> objectMessage) {
+        this.sendExchange(HazelcastConstants.RECEIVED, null, objectMessage);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/69138a10/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicConsumer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicConsumer.java
new file mode 100644
index 0000000..958f0bd
--- /dev/null
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicConsumer.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hazelcast.topic;
+
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.IQueue;
+import com.hazelcast.core.ITopic;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.component.hazelcast.HazelcastDefaultConsumer;
+import org.apache.camel.component.hazelcast.listener.CamelItemListener;
+import org.apache.camel.component.hazelcast.listener.CamelMessageListener;
+
+/**
+ *
+ */
+public class HazelcastTopicConsumer extends HazelcastDefaultConsumer {
+
+    public HazelcastTopicConsumer(HazelcastInstance hazelcastInstance, Endpoint endpoint, Processor processor, String cacheName) {
+        super(hazelcastInstance, endpoint, processor, cacheName);
+
+        ITopic<Object> topic = hazelcastInstance.getTopic(cacheName);
+        topic.addMessageListener(new CamelMessageListener(this, cacheName));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/69138a10/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
index 34a801e..920be2e 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
@@ -34,8 +34,9 @@ public class HazelcastTopicEndpoint extends HazelcastDefaultEndpoint {
 
     @Override
     public Consumer createConsumer(Processor processor) throws Exception {
-        // TODO
-        return null;
+        HazelcastTopicConsumer answer = new HazelcastTopicConsumer(hazelcastInstance, this, processor, cacheName);
+        configureConsumer(answer);
+        return answer;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/69138a10/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicConsumerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicConsumerTest.java
new file mode 100644
index 0000000..57531f6
--- /dev/null
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicConsumerTest.java
@@ -0,0 +1,91 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hazelcast;
+
+import com.hazelcast.core.*;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class HazelcastTopicConsumerTest extends HazelcastCamelTestSupport {
+
+    @Mock
+    private ITopic<String> topic;
+
+    private ArgumentCaptor<MessageListener> argument;
+
+    @Override
+    @SuppressWarnings("unchecked")
+    protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) {
+        when(hazelcastInstance.<String>getTopic("foo")).thenReturn(topic);
+        argument = ArgumentCaptor.forClass(MessageListener.class);
+        when(topic.addMessageListener(argument.capture())).thenReturn("foo");
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) {
+        verify(hazelcastInstance).getTopic("foo");
+        verify(topic).addMessageListener(any(MessageListener.class));
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void receive() throws InterruptedException {
+        MockEndpoint out = getMockEndpoint("mock:received");
+        out.expectedMessageCount(1);
+
+        final Message<String> msg = new Message<String>("foo", "foo", new java.util.Date().getTime(), null);
+        argument.getValue().onMessage(msg);
+
+        assertMockEndpointsSatisfied(2000, TimeUnit.MILLISECONDS);
+
+        this.checkHeaders(out.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.RECEIVED);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from(String.format("hazelcast:%sfoo", HazelcastConstants.TOPIC_PREFIX)).log("object...")
+                        .choice()
+                            .when(header(HazelcastConstants.LISTENER_ACTION).isEqualTo(HazelcastConstants.RECEIVED))
+                                .log("...received").to("mock:received")
+                        .otherwise()
+                            .log("fail!");
+            }
+        };
+    }
+
+    private void checkHeaders(Map<String, Object> headers, String action) {
+        assertEquals(action, headers.get(HazelcastConstants.LISTENER_ACTION));
+        assertEquals(HazelcastConstants.CACHE_LISTENER, headers.get(HazelcastConstants.LISTENER_TYPE));
+        assertEquals(null, headers.get(HazelcastConstants.OBJECT_ID));
+        assertNotNull(headers.get(HazelcastConstants.LISTENER_TIME));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/69138a10/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicProducerTest.java
index 240f5c6..37f1750 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicProducerTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicProducerTest.java
@@ -58,7 +58,7 @@ public class HazelcastTopicProducerTest extends HazelcastCamelTestSupport {
     }
 
     @Test
-    public void add() {
+    public void publish() {
         template.sendBody("direct:publish", "bar");
         verify(topic).publish("bar");
     }


[3/4] camel git commit: Added support for multiple consumers at HazelcastTopicEndPoint

Posted by da...@apache.org.
Added support for multiple consumers at HazelcastTopicEndPoint


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a97d8b95
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a97d8b95
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a97d8b95

Branch: refs/heads/master
Commit: a97d8b95eb038a61d4aaeaf47fd9d5670cb169c0
Parents: 69138a1
Author: JSantosP <ja...@gmail.com>
Authored: Fri Aug 29 14:25:01 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 19:57:22 2014 +0100

----------------------------------------------------------------------
 .../component/hazelcast/topic/HazelcastTopicEndpoint.java    | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a97d8b95/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
index 920be2e..d74d780 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
@@ -21,12 +21,13 @@ import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.MultipleConsumersSupport;
 import org.apache.camel.component.hazelcast.HazelcastDefaultEndpoint;
 
 /**
  *
  */
-public class HazelcastTopicEndpoint extends HazelcastDefaultEndpoint {
+public class HazelcastTopicEndpoint extends HazelcastDefaultEndpoint implements MultipleConsumersSupport {
 
     public HazelcastTopicEndpoint(HazelcastInstance hazelcastInstance, String endpointUri, Component component, String cacheName) {
         super(hazelcastInstance, endpointUri, component, cacheName);
@@ -44,4 +45,9 @@ public class HazelcastTopicEndpoint extends HazelcastDefaultEndpoint {
         return new HazelcastTopicProducer(hazelcastInstance, this, cacheName);
     }
 
+    @Override
+    public boolean isMultipleConsumersSupported() {
+        return true;
+    }
+
 }


[2/4] camel git commit: publish topic operation support added.

Posted by da...@apache.org.
publish topic operation support added.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9e5968c3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9e5968c3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9e5968c3

Branch: refs/heads/master
Commit: 9e5968c3adeacde3fad5b5a9a11572ef83b3538e
Parents: 9ecc0cc
Author: juanjovazquez <jv...@tecsisa.com>
Authored: Wed Aug 27 19:36:31 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 19:57:21 2014 +0100

----------------------------------------------------------------------
 .../component/hazelcast/HazelcastComponent.java |  7 ++
 .../hazelcast/HazelcastComponentHelper.java     |  3 +
 .../component/hazelcast/HazelcastConstants.java |  4 +
 .../hazelcast/topic/HazelcastTopicEndpoint.java | 46 +++++++++++
 .../hazelcast/topic/HazelcastTopicProducer.java | 64 ++++++++++++++++
 .../hazelcast/HazelcastTopicProducerTest.java   | 80 ++++++++++++++++++++
 6 files changed, 204 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9e5968c3/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java
index a95ccda..fe21892 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponent.java
@@ -32,6 +32,7 @@ import org.apache.camel.component.hazelcast.multimap.HazelcastMultimapEndpoint;
 import org.apache.camel.component.hazelcast.queue.HazelcastQueueEndpoint;
 import org.apache.camel.component.hazelcast.seda.HazelcastSedaConfiguration;
 import org.apache.camel.component.hazelcast.seda.HazelcastSedaEndpoint;
+import org.apache.camel.component.hazelcast.topic.HazelcastTopicEndpoint;
 import org.apache.camel.impl.DefaultComponent;
 
 import static org.apache.camel.util.ObjectHelper.removeStartingCharacters;
@@ -93,6 +94,12 @@ public class HazelcastComponent extends DefaultComponent {
             endpoint = new HazelcastQueueEndpoint(hzInstance, uri, this, remaining);
         }
 
+        if (remaining.startsWith(HazelcastConstants.TOPIC_PREFIX)) {
+            // remaining is anything (name it foo ;)
+            remaining = removeStartingCharacters(remaining.substring(HazelcastConstants.TOPIC_PREFIX.length()), '/');
+            endpoint = new HazelcastTopicEndpoint(hzInstance, uri, this, remaining);
+        }
+
         if (remaining.startsWith(HazelcastConstants.SEDA_PREFIX)) {
             final HazelcastSedaConfiguration config = new HazelcastSedaConfiguration();
             setProperties(config, parameters);

http://git-wip-us.apache.org/repos/asf/camel/blob/9e5968c3/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java
index b1e25ee..f6057c5 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastComponentHelper.java
@@ -107,6 +107,9 @@ public final class HazelcastComponentHelper {
         addMapping("offer", HazelcastConstants.OFFER_OPERATION);
         addMapping("peek", HazelcastConstants.PEEK_OPERATION);
         addMapping("poll", HazelcastConstants.POLL_OPERATION);
+
+        // topic
+        addMapping("publish", HazelcastConstants.PUBLISH_OPERATION);
     }
 
     private void addMapping(String operationName, int operationNumber) {

http://git-wip-us.apache.org/repos/asf/camel/blob/9e5968c3/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
index fa94b01..ebd20f6 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastConstants.java
@@ -26,6 +26,7 @@ public final class HazelcastConstants {
     public static final String ATOMICNUMBER_PREFIX = "atomicvalue:";
     public static final String INSTANCE_PREFIX = "instance:";
     public static final String QUEUE_PREFIX = "queue:";
+    public static final String TOPIC_PREFIX = "topic:";
     public static final String SEDA_PREFIX = "seda:";
     public static final String LIST_PREFIX = "list:";
 
@@ -70,6 +71,9 @@ public final class HazelcastConstants {
     public static final int PEEK_OPERATION = 33;
     public static final int POLL_OPERATION = 34;
 
+    // topic
+    public static final int PUBLISH_OPERATION = 35;
+
     /*
      * header values
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/9e5968c3/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
new file mode 100644
index 0000000..34a801e
--- /dev/null
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hazelcast.topic;
+
+import com.hazelcast.core.HazelcastInstance;
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.hazelcast.HazelcastDefaultEndpoint;
+
+/**
+ *
+ */
+public class HazelcastTopicEndpoint extends HazelcastDefaultEndpoint {
+
+    public HazelcastTopicEndpoint(HazelcastInstance hazelcastInstance, String endpointUri, Component component, String cacheName) {
+        super(hazelcastInstance, endpointUri, component, cacheName);
+    }
+
+    @Override
+    public Consumer createConsumer(Processor processor) throws Exception {
+        // TODO
+        return null;
+    }
+
+    @Override
+    public Producer createProducer() throws Exception {
+        return new HazelcastTopicProducer(hazelcastInstance, this, cacheName);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9e5968c3/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicProducer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicProducer.java
new file mode 100644
index 0000000..6111c59
--- /dev/null
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicProducer.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hazelcast.topic;
+
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.ITopic;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.hazelcast.HazelcastComponentHelper;
+import org.apache.camel.component.hazelcast.HazelcastConstants;
+import org.apache.camel.component.hazelcast.HazelcastDefaultEndpoint;
+import org.apache.camel.component.hazelcast.HazelcastDefaultProducer;
+
+/**
+ *
+ */
+public class HazelcastTopicProducer extends HazelcastDefaultProducer {
+
+    private ITopic<Object> topic;
+
+    public HazelcastTopicProducer(HazelcastInstance hazelcastInstance, HazelcastDefaultEndpoint endpoint, String topicName) {
+        super(endpoint);
+        this.topic = hazelcastInstance.getTopic(topicName);
+    }
+
+    public void process(Exchange exchange) throws Exception {
+
+        final int operation = lookupOperationNumber(exchange);
+
+        switch (operation) {
+
+            case -1:
+                // default operation to publish
+            case HazelcastConstants.PUBLISH_OPERATION:
+                this.publish(exchange);
+                break;
+            default:
+                throw new IllegalArgumentException(String.format("The value '%s' is not allowed for parameter '%s' on the TOPIC cache.", operation, HazelcastConstants.OPERATION));
+
+        }
+
+        // finally copy headers
+        HazelcastComponentHelper.copyHeaders(exchange);
+
+    }
+
+    private void publish(Exchange exchange) {
+        Object body = exchange.getIn().getBody();
+        this.topic.publish(body);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9e5968c3/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicProducerTest.java
new file mode 100644
index 0000000..240f5c6
--- /dev/null
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicProducerTest.java
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.hazelcast;
+
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.ITopic;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.After;
+import org.junit.Test;
+import org.mockito.Mock;
+
+import static org.mockito.Mockito.*;
+
+public class HazelcastTopicProducerTest extends HazelcastCamelTestSupport {
+
+    @Mock
+    private ITopic<String> topic;
+
+    @Override
+    protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) {
+        when(hazelcastInstance.<String>getTopic("bar")).thenReturn(topic);
+    }
+
+    @Override
+    protected void verifyHazelcastInstance(HazelcastInstance hazelcastInstance) {
+        verify(hazelcastInstance, atLeastOnce()).getTopic("bar");
+    }
+
+    @After
+    public void verifyQueueMock() {
+        verifyNoMoreInteractions(topic);
+    }
+
+    @Test(expected = CamelExecutionException.class)
+    public void testWithInvalidOperation() {
+        template.sendBody("direct:publishInvalid", "foo");
+    }
+
+    @Test
+    public void noOperation() {
+        template.sendBody("direct:no-operation", "bar");
+        verify(topic).publish("bar");
+    }
+
+    @Test
+    public void add() {
+        template.sendBody("direct:publish", "bar");
+        verify(topic).publish("bar");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:no-operation").to(String.format("hazelcast:%sbar", HazelcastConstants.TOPIC_PREFIX));
+
+                from("direct:publishInvalid").setHeader(HazelcastConstants.OPERATION, constant("bogus")).to(String.format("hazelcast:%sbar", HazelcastConstants.TOPIC_PREFIX));
+
+                from("direct:publish").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUBLISH_OPERATION)).to(String.format("hazelcast:%sbar", HazelcastConstants.TOPIC_PREFIX));
+            }
+        };
+    }
+
+}


[4/4] camel git commit: CAMEL-7794: Fixed CS

Posted by da...@apache.org.
CAMEL-7794: Fixed CS


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4a5666d4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4a5666d4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4a5666d4

Branch: refs/heads/master
Commit: 4a5666d46c9c6fd99afd4d2aa17dd6a2f95a5cea
Parents: a97d8b9
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Dec 3 20:01:40 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Dec 3 20:01:40 2014 +0100

----------------------------------------------------------------------
 .../hazelcast/topic/HazelcastTopicEndpoint.java   |  2 +-
 .../hazelcast/topic/HazelcastTopicProducer.java   | 18 +++++++-----------
 .../hazelcast/HazelcastTopicConsumerTest.java     | 11 +++++++----
 3 files changed, 15 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4a5666d4/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
index d74d780..3e57529 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicEndpoint.java
@@ -19,9 +19,9 @@ package org.apache.camel.component.hazelcast.topic;
 import com.hazelcast.core.HazelcastInstance;
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
+import org.apache.camel.MultipleConsumersSupport;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
-import org.apache.camel.MultipleConsumersSupport;
 import org.apache.camel.component.hazelcast.HazelcastDefaultEndpoint;
 
 /**

http://git-wip-us.apache.org/repos/asf/camel/blob/4a5666d4/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicProducer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicProducer.java
index 6111c59..4cb08fe 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicProducer.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/topic/HazelcastTopicProducer.java
@@ -37,24 +37,20 @@ public class HazelcastTopicProducer extends HazelcastDefaultProducer {
     }
 
     public void process(Exchange exchange) throws Exception {
-
         final int operation = lookupOperationNumber(exchange);
 
         switch (operation) {
-
-            case -1:
-                // default operation to publish
-            case HazelcastConstants.PUBLISH_OPERATION:
-                this.publish(exchange);
-                break;
-            default:
-                throw new IllegalArgumentException(String.format("The value '%s' is not allowed for parameter '%s' on the TOPIC cache.", operation, HazelcastConstants.OPERATION));
-
+        case -1:
+            // default operation to publish
+        case HazelcastConstants.PUBLISH_OPERATION:
+            this.publish(exchange);
+            break;
+        default:
+            throw new IllegalArgumentException(String.format("The value '%s' is not allowed for parameter '%s' on the TOPIC cache.", operation, HazelcastConstants.OPERATION));
         }
 
         // finally copy headers
         HazelcastComponentHelper.copyHeaders(exchange);
-
     }
 
     private void publish(Exchange exchange) {

http://git-wip-us.apache.org/repos/asf/camel/blob/4a5666d4/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicConsumerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicConsumerTest.java
index 57531f6..c833f88 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicConsumerTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastTopicConsumerTest.java
@@ -16,16 +16,19 @@
  */
 package org.apache.camel.component.hazelcast;
 
-import com.hazelcast.core.*;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.ITopic;
+import com.hazelcast.core.Message;
+import com.hazelcast.core.MessageListener;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;