You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by jc...@apache.org on 2013/10/10 04:45:25 UTC
git commit: CAMEL-4015: camel-hazelcast - Allow to specify operation
in uri instead of just as a header
Updated Branches:
refs/heads/master acc0eb8b0 -> 69998cb1f
CAMEL-4015: camel-hazelcast - Allow to specify operation in uri instead of just as a header
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/69998cb1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/69998cb1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/69998cb1
Branch: refs/heads/master
Commit: 69998cb1f1e2ef0896696166eab0f31099864d17
Parents: acc0eb8
Author: James Carman <jc...@apache.org>
Authored: Wed Oct 9 22:44:00 2013 -0400
Committer: James Carman <jc...@apache.org>
Committed: Wed Oct 9 22:44:14 2013 -0400
----------------------------------------------------------------------
.../hazelcast/HazelcastComponentHelper.java | 57 +++++++++++++-------
.../component/hazelcast/HazelcastConstants.java | 3 ++
.../hazelcast/HazelcastDefaultEndpoint.java | 14 +++++
.../hazelcast/HazelcastDefaultProducer.java | 39 ++++++++++++++
.../HazelcastAtomicnumberProducer.java | 24 ++-------
.../hazelcast/list/HazelcastListProducer.java | 16 ++----
.../hazelcast/map/HazelcastMapProducer.java | 19 ++-----
.../multimap/HazelcastMultimapProducer.java | 18 ++-----
.../hazelcast/queue/HazelcastQueueProducer.java | 28 +++-------
.../HazelcastAtomicnumberProducerTest.java | 24 +++++++++
.../hazelcast/HazelcastListProducerTest.java | 24 +++++++++
.../hazelcast/HazelcastMapProducerTest.java | 24 +++++++++
.../HazelcastMultimapProducerTest.java | 22 ++++++++
.../hazelcast/HazelcastQueueProducerTest.java | 24 +++++++++
14 files changed, 238 insertions(+), 98 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/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 24d47e0..b1e25ee 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
@@ -22,7 +22,7 @@ import java.util.Map;
import org.apache.camel.Exchange;
-public class HazelcastComponentHelper {
+public final class HazelcastComponentHelper {
private final HashMap<String, Integer> mapping = new HashMap<String, Integer>();
@@ -60,39 +60,58 @@ public class HazelcastComponentHelper {
ex.getIn().setHeader(HazelcastConstants.LISTENER_TIME, new Date().getTime());
}
+ public int lookupOperationNumber(Exchange exchange, int defaultOperation) {
+ return extractOperationNumber(exchange.getIn().getHeader(HazelcastConstants.OPERATION), defaultOperation);
+ }
+
+ public int extractOperationNumber(Object value, int defaultOperation) {
+ int operation = defaultOperation;
+ if (value instanceof String) {
+ operation = mapToOperationNumber((String) value);
+ } else if (value instanceof Integer) {
+ operation = (Integer)value;
+ }
+ return operation;
+ }
+
/**
* Allows the use of speaking operation names (e.g. for usage in Spring DSL)
*/
- public int lookupOperationNumber(String operation) {
- if (this.mapping.containsKey(operation)) {
- return this.mapping.get(operation);
+ private int mapToOperationNumber(String operationName) {
+ if (this.mapping.containsKey(operationName)) {
+ return this.mapping.get(operationName);
} else {
- throw new IllegalArgumentException(String.format("Operation '%s' is not supported by this component.", operation));
+ throw new IllegalArgumentException(String.format("Operation '%s' is not supported by this component.", operationName));
}
}
private void init() {
// fill map with values
- this.mapping.put("put", HazelcastConstants.PUT_OPERATION);
- this.mapping.put("delete", HazelcastConstants.DELETE_OPERATION);
- this.mapping.put("get", HazelcastConstants.GET_OPERATION);
- this.mapping.put("update", HazelcastConstants.UPDATE_OPERATION);
- this.mapping.put("query", HazelcastConstants.QUERY_OPERATION);
+ addMapping("put", HazelcastConstants.PUT_OPERATION);
+ addMapping("delete", HazelcastConstants.DELETE_OPERATION);
+ addMapping("get", HazelcastConstants.GET_OPERATION);
+ addMapping("update", HazelcastConstants.UPDATE_OPERATION);
+ addMapping("query", HazelcastConstants.QUERY_OPERATION);
// multimap
- this.mapping.put("removevalue", HazelcastConstants.REMOVEVALUE_OPERATION);
+ addMapping("removevalue", HazelcastConstants.REMOVEVALUE_OPERATION);
// atomic numbers
- this.mapping.put("increment", HazelcastConstants.INCREMENT_OPERATION);
- this.mapping.put("decrement", HazelcastConstants.DECREMENT_OPERATION);
- this.mapping.put("setvalue", HazelcastConstants.SETVALUE_OPERATION);
- this.mapping.put("destroy", HazelcastConstants.DESTROY_OPERATION);
+ addMapping("increment", HazelcastConstants.INCREMENT_OPERATION);
+ addMapping("decrement", HazelcastConstants.DECREMENT_OPERATION);
+ addMapping("setvalue", HazelcastConstants.SETVALUE_OPERATION);
+ addMapping("destroy", HazelcastConstants.DESTROY_OPERATION);
// queue
- this.mapping.put("add", HazelcastConstants.ADD_OPERATION);
- this.mapping.put("offer", HazelcastConstants.OFFER_OPERATION);
- this.mapping.put("peek", HazelcastConstants.PEEK_OPERATION);
- this.mapping.put("poll", HazelcastConstants.POLL_OPERATION);
+ addMapping("add", HazelcastConstants.ADD_OPERATION);
+ addMapping("offer", HazelcastConstants.OFFER_OPERATION);
+ addMapping("peek", HazelcastConstants.PEEK_OPERATION);
+ addMapping("poll", HazelcastConstants.POLL_OPERATION);
+ }
+
+ private void addMapping(String operationName, int operationNumber) {
+ this.mapping.put(operationName, operationNumber);
+ this.mapping.put(String.valueOf(operationNumber), operationNumber);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/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 e36225b..9f341fb 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
@@ -91,6 +91,9 @@ public final class HazelcastConstants {
public static final String INSTANCE_LISTENER = "instancelistener";
public static final String ITEM_LISTENER = "itemlistener";
+ // parameter names
+ public static final String OPERATION_PARAM = "operation";
+
private HazelcastConstants() {
}
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultEndpoint.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultEndpoint.java
index 74bdfa9..4f19906 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultEndpoint.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultEndpoint.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.component.hazelcast;
+import java.util.Map;
+
import com.hazelcast.core.HazelcastInstance;
import org.apache.camel.Component;
import org.apache.camel.Consumer;
@@ -27,6 +29,8 @@ public abstract class HazelcastDefaultEndpoint extends DefaultEndpoint {
protected final String cacheName;
protected HazelcastInstance hazelcastInstance;
+ private int defaultOperation = -1;
+ private final HazelcastComponentHelper helper = new HazelcastComponentHelper();
public HazelcastDefaultEndpoint(HazelcastInstance hazelcastInstance, String endpointUri, Component component) {
this(hazelcastInstance, endpointUri, component, null);
@@ -49,4 +53,14 @@ public abstract class HazelcastDefaultEndpoint extends DefaultEndpoint {
public HazelcastInstance getHazelcastInstance() {
return hazelcastInstance;
}
+
+ @Override
+ public void configureProperties(Map<String, Object> options) {
+ super.configureProperties(options);
+ defaultOperation = helper.extractOperationNumber(options.remove(HazelcastConstants.OPERATION_PARAM), -1);
+ }
+
+ public int getDefaultOperation() {
+ return defaultOperation;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultProducer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultProducer.java
new file mode 100644
index 0000000..43e7836
--- /dev/null
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/HazelcastDefaultProducer.java
@@ -0,0 +1,39 @@
+/**
+ * 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 org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+
+public abstract class HazelcastDefaultProducer extends DefaultProducer {
+
+ private final HazelcastComponentHelper helper = new HazelcastComponentHelper();
+
+ public HazelcastDefaultProducer(HazelcastDefaultEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public HazelcastDefaultEndpoint getEndpoint() {
+ return (HazelcastDefaultEndpoint)super.getEndpoint();
+ }
+
+ protected int lookupOperationNumber(Exchange exchange) {
+ return helper.lookupOperationNumber(exchange, getEndpoint().getDefaultOperation());
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/atomicnumber/HazelcastAtomicnumberProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/atomicnumber/HazelcastAtomicnumberProducer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/atomicnumber/HazelcastAtomicnumberProducer.java
index 2f4f454..08ee1d1 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/atomicnumber/HazelcastAtomicnumberProducer.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/atomicnumber/HazelcastAtomicnumberProducer.java
@@ -16,40 +16,26 @@
*/
package org.apache.camel.component.hazelcast.atomicnumber;
-import java.util.Map;
-
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IAtomicLong;
-import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.component.hazelcast.HazelcastComponentHelper;
import org.apache.camel.component.hazelcast.HazelcastConstants;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.component.hazelcast.HazelcastDefaultEndpoint;
+import org.apache.camel.component.hazelcast.HazelcastDefaultProducer;
-public class HazelcastAtomicnumberProducer extends DefaultProducer {
+public class HazelcastAtomicnumberProducer extends HazelcastDefaultProducer {
private final IAtomicLong atomicnumber;
- private final HazelcastComponentHelper helper = new HazelcastComponentHelper();
- public HazelcastAtomicnumberProducer(HazelcastInstance hazelcastInstance, Endpoint endpoint, String cacheName) {
+ public HazelcastAtomicnumberProducer(HazelcastInstance hazelcastInstance, HazelcastDefaultEndpoint endpoint, String cacheName) {
super(endpoint);
this.atomicnumber = hazelcastInstance.getAtomicLong(cacheName);
}
public void process(Exchange exchange) throws Exception {
- Map<String, Object> headers = exchange.getIn().getHeaders();
-
- // get header parameters
- int operation = -1;
-
- if (headers.containsKey(HazelcastConstants.OPERATION)) {
- if (headers.get(HazelcastConstants.OPERATION) instanceof String) {
- operation = this.helper.lookupOperationNumber((String) headers.get(HazelcastConstants.OPERATION));
- } else {
- operation = (Integer) headers.get(HazelcastConstants.OPERATION);
- }
- }
+ int operation = lookupOperationNumber(exchange);
switch (operation) {
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java
index 3ae6fd2..843455c 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/list/HazelcastListProducer.java
@@ -26,17 +26,18 @@ import org.apache.camel.Exchange;
import org.apache.camel.Producer;
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;
import org.apache.camel.impl.DefaultProducer;
/**
* Implementation of Hazelcast List {@link Producer}.
*/
-public class HazelcastListProducer extends DefaultProducer {
+public class HazelcastListProducer extends HazelcastDefaultProducer {
private final IList<Object> list;
- private final HazelcastComponentHelper helper = new HazelcastComponentHelper();
- public HazelcastListProducer(HazelcastInstance hazelcastInstance, Endpoint endpoint, String listName) {
+ public HazelcastListProducer(HazelcastInstance hazelcastInstance, HazelcastDefaultEndpoint endpoint, String listName) {
super(endpoint);
this.list = hazelcastInstance.getList(listName);
}
@@ -46,7 +47,6 @@ public class HazelcastListProducer extends DefaultProducer {
Map<String, Object> headers = exchange.getIn().getHeaders();
// get header parameters
- int operation = -1;
Integer pos = null;
if (headers.containsKey(HazelcastConstants.OBJECT_POS)) {
@@ -56,13 +56,7 @@ public class HazelcastListProducer extends DefaultProducer {
pos = (Integer) headers.get(HazelcastConstants.OBJECT_POS);
}
- if (headers.containsKey(HazelcastConstants.OPERATION)) {
- if (headers.get(HazelcastConstants.OPERATION) instanceof String) {
- operation = helper.lookupOperationNumber((String) headers.get(HazelcastConstants.OPERATION));
- } else {
- operation = (Integer) headers.get(HazelcastConstants.OPERATION);
- }
- }
+ final int operation = lookupOperationNumber(exchange);
switch (operation) {
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java
index 9d71243..7d4196d 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/map/HazelcastMapProducer.java
@@ -26,12 +26,11 @@ import com.hazelcast.query.SqlPredicate;
import org.apache.camel.Exchange;
import org.apache.camel.component.hazelcast.HazelcastComponentHelper;
import org.apache.camel.component.hazelcast.HazelcastConstants;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.component.hazelcast.HazelcastDefaultProducer;
-public class HazelcastMapProducer extends DefaultProducer {
+public class HazelcastMapProducer extends HazelcastDefaultProducer {
private final IMap<Object, Object> cache;
- private final HazelcastComponentHelper helper = new HazelcastComponentHelper();
public HazelcastMapProducer(HazelcastInstance hazelcastInstance, HazelcastMapEndpoint endpoint, String cacheName) {
super(endpoint);
@@ -44,27 +43,17 @@ public class HazelcastMapProducer extends DefaultProducer {
// get header parameters
Object oid = null;
- int operation = -1;
String query = null;
if (headers.containsKey(HazelcastConstants.OBJECT_ID)) {
oid = headers.get(HazelcastConstants.OBJECT_ID);
}
- if (headers.containsKey(HazelcastConstants.OPERATION)) {
-
- // producer allows int (HazelcastConstants) and string values
- if (headers.get(HazelcastConstants.OPERATION) instanceof String) {
- operation = helper.lookupOperationNumber((String) headers.get(HazelcastConstants.OPERATION));
- } else {
- operation = (Integer) headers.get(HazelcastConstants.OPERATION);
- }
- }
-
if (headers.containsKey(HazelcastConstants.QUERY)) {
query = (String) headers.get(HazelcastConstants.QUERY);
}
+ final int operation = lookupOperationNumber(exchange);
switch (operation) {
case HazelcastConstants.PUT_OPERATION:
@@ -135,4 +124,4 @@ public class HazelcastMapProducer extends DefaultProducer {
Object body = exchange.getIn().getBody();
this.cache.put(oid, body);
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/multimap/HazelcastMultimapProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/multimap/HazelcastMultimapProducer.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/multimap/HazelcastMultimapProducer.java
index 047c985..2bbe5f3 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/multimap/HazelcastMultimapProducer.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/multimap/HazelcastMultimapProducer.java
@@ -21,18 +21,17 @@ import java.util.Map;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.MultiMap;
-import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.component.hazelcast.HazelcastComponentHelper;
import org.apache.camel.component.hazelcast.HazelcastConstants;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.component.hazelcast.HazelcastDefaultEndpoint;
+import org.apache.camel.component.hazelcast.HazelcastDefaultProducer;
-public class HazelcastMultimapProducer extends DefaultProducer {
+public class HazelcastMultimapProducer extends HazelcastDefaultProducer {
private final MultiMap<Object, Object> cache;
- private final HazelcastComponentHelper helper = new HazelcastComponentHelper();
- public HazelcastMultimapProducer(HazelcastInstance hazelcastInstance, Endpoint endpoint, String cacheName) {
+ public HazelcastMultimapProducer(HazelcastInstance hazelcastInstance, HazelcastDefaultEndpoint endpoint, String cacheName) {
super(endpoint);
this.cache = hazelcastInstance.getMultiMap(cacheName);
}
@@ -43,19 +42,12 @@ public class HazelcastMultimapProducer extends DefaultProducer {
// get header parameters
Object oid = null;
- int operation = -1;
if (headers.containsKey(HazelcastConstants.OBJECT_ID)) {
oid = headers.get(HazelcastConstants.OBJECT_ID);
}
- if (headers.containsKey(HazelcastConstants.OPERATION)) {
- if (headers.get(HazelcastConstants.OPERATION) instanceof String) {
- operation = helper.lookupOperationNumber((String) headers.get(HazelcastConstants.OPERATION));
- } else {
- operation = (Integer) headers.get(HazelcastConstants.OPERATION);
- }
- }
+ final int operation = lookupOperationNumber(exchange);
switch (operation) {
case HazelcastConstants.PUT_OPERATION:
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/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 2edf49a..46c7488 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
@@ -16,49 +16,35 @@
*/
package org.apache.camel.component.hazelcast.queue;
-import java.util.Map;
-
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IQueue;
-import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.component.hazelcast.HazelcastComponentHelper;
import org.apache.camel.component.hazelcast.HazelcastConstants;
-import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.component.hazelcast.HazelcastDefaultEndpoint;
+import org.apache.camel.component.hazelcast.HazelcastDefaultProducer;
/**
*
*/
-public class HazelcastQueueProducer extends DefaultProducer {
+public class HazelcastQueueProducer extends HazelcastDefaultProducer {
private IQueue<Object> queue;
- private HazelcastComponentHelper helper = new HazelcastComponentHelper();
- public HazelcastQueueProducer(HazelcastInstance hazelcastInstance, Endpoint endpoint, String queueName) {
+ public HazelcastQueueProducer(HazelcastInstance hazelcastInstance, HazelcastDefaultEndpoint endpoint, String queueName) {
super(endpoint);
this.queue = hazelcastInstance.getQueue(queueName);
}
public void process(Exchange exchange) throws Exception {
- Map<String, Object> headers = exchange.getIn().getHeaders();
-
- // get header parameters
- int operation = -1;
-
- if (headers.containsKey(HazelcastConstants.OPERATION)) {
- if (headers.get(HazelcastConstants.OPERATION) instanceof String) {
- operation = helper.lookupOperationNumber((String) headers.get(HazelcastConstants.OPERATION));
- } else {
- operation = (Integer) headers.get(HazelcastConstants.OPERATION);
- }
- }
+ final int operation = lookupOperationNumber(exchange);
switch (operation) {
case -1:
- //If no operation is specified use ADD.
+ //If no operation is specified use ADD.
case HazelcastConstants.ADD_OPERATION:
this.add(exchange);
break;
@@ -123,4 +109,4 @@ public class HazelcastQueueProducer extends DefaultProducer {
this.queue.remove();
}
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java
index 84eb211..6768e66 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastAtomicnumberProducerTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IAtomicLong;
+import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.junit.After;
import org.junit.Test;
@@ -44,6 +45,11 @@ public class HazelcastAtomicnumberProducerTest extends HazelcastCamelTestSupport
verifyNoMoreInteractions(atomicNumber);
}
+ @Test(expected = CamelExecutionException.class)
+ public void testWithInvalidOperationName() {
+ template.sendBody("direct:setInvalid", 4711);
+ }
+
@Test
public void testSet() {
template.sendBody("direct:set", 4711);
@@ -80,12 +86,27 @@ public class HazelcastAtomicnumberProducerTest extends HazelcastCamelTestSupport
verify(atomicNumber).destroy();
}
+ @Test
+ public void testSetWithOperationNumber() {
+ template.sendBody("direct:setWithOperationNumber", 5711);
+ verify(atomicNumber).set(5711);
+ }
+
+ @Test
+ public void testSetWithOperationName() {
+ template.sendBody("direct:setWithOperationName", 5711);
+ verify(atomicNumber).set(5711);
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
+ from("direct:setInvalid").setHeader(HazelcastConstants.OPERATION, constant("invalid"))
+ .to(String.format("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX));
+
from("direct:set").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.SETVALUE_OPERATION))
.to(String.format("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX));
@@ -100,6 +121,9 @@ public class HazelcastAtomicnumberProducerTest extends HazelcastCamelTestSupport
from("direct:destroy").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DESTROY_OPERATION)).to(
String.format("hazelcast:%sfoo", HazelcastConstants.ATOMICNUMBER_PREFIX));
+ from("direct:setWithOperationNumber").toF("hazelcast:%sfoo?operation=%s", HazelcastConstants.ATOMICNUMBER_PREFIX, HazelcastConstants.SETVALUE_OPERATION);
+ from("direct:setWithOperationName").toF("hazelcast:%sfoo?operation=setvalue", HazelcastConstants.ATOMICNUMBER_PREFIX);
+
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java
index f367c11..7179504 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastListProducerTest.java
@@ -22,6 +22,7 @@ import java.util.List;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IList;
+import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.junit.After;
@@ -51,6 +52,11 @@ public class HazelcastListProducerTest extends HazelcastCamelTestSupport {
verifyNoMoreInteractions(list);
}
+ @Test(expected = CamelExecutionException.class)
+ public void testWithInvalidOperation() {
+ template.sendBody("direct:addInvalid", "bar");
+ }
+
@Test
public void addValue() throws InterruptedException {
template.sendBody("direct:add", "bar");
@@ -58,6 +64,18 @@ public class HazelcastListProducerTest extends HazelcastCamelTestSupport {
}
@Test
+ public void addValueWithOperationNumber() throws InterruptedException {
+ template.sendBody("direct:addWithOperationNumber", "bar");
+ verify(list).add("bar");
+ }
+
+ @Test
+ public void addValueWithOperationName() throws InterruptedException {
+ template.sendBody("direct:addWithOperationName", "bar");
+ verify(list).add("bar");
+ }
+
+ @Test
public void removeValue() throws InterruptedException {
template.sendBody("direct:removevalue", "foo2");
verify(list).remove("foo2");
@@ -94,6 +112,9 @@ public class HazelcastListProducerTest extends HazelcastCamelTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
+
+ from("direct:addInvalid").setHeader(HazelcastConstants.OPERATION, constant("bogus")).to(String.format("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX));
+
from("direct:add").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION)).to(String.format("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX));
from("direct:set").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.SETVALUE_OPERATION)).to(String.format("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX));
@@ -103,6 +124,9 @@ public class HazelcastListProducerTest extends HazelcastCamelTestSupport {
from("direct:removevalue").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION)).to(
String.format("hazelcast:%sbar", HazelcastConstants.LIST_PREFIX));
+
+ from("direct:addWithOperationNumber").toF("hazelcast:%sbar?operation=%s", HazelcastConstants.LIST_PREFIX, HazelcastConstants.ADD_OPERATION);
+ from("direct:addWithOperationName").toF("hazelcast:%sbar?operation=add", HazelcastConstants.LIST_PREFIX);
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java
index 669a38d..a834f76 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMapProducerTest.java
@@ -24,6 +24,7 @@ import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.query.SqlPredicate;
+import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.hazelcast.testutil.Dummy;
import org.junit.After;
@@ -52,6 +53,11 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport implemen
verifyNoMoreInteractions(map);
}
+ @Test(expected = CamelExecutionException.class)
+ public void testWithInvalidOperation() {
+ template.sendBody("direct:putInvalid", "my-foo");
+ }
+
@Test
public void testPut() throws InterruptedException {
template.sendBodyAndHeader("direct:put", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
@@ -59,6 +65,18 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport implemen
}
@Test
+ public void testPutWithOperationNumber() throws InterruptedException {
+ template.sendBodyAndHeader("direct:putWithOperationNumber", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
+ verify(map).put("4711", "my-foo");
+ }
+
+ @Test
+ public void testPutWithOperationName() throws InterruptedException {
+ template.sendBodyAndHeader("direct:putWithOperationName", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
+ verify(map).put("4711", "my-foo");
+ }
+
+ @Test
public void testUpdate() {
template.sendBodyAndHeader("direct:update", "my-fooo", HazelcastConstants.OBJECT_ID, "4711");
verify(map).lock("4711");
@@ -101,6 +119,8 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport implemen
@Override
public void configure() throws Exception {
+ from("direct:putInvalid").setHeader(HazelcastConstants.OPERATION, constant("bogus")).to(String.format("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX));
+
from("direct:put").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION)).to(String.format("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX));
from("direct:update").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.UPDATE_OPERATION)).to(String.format("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX));
@@ -113,6 +133,10 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport implemen
from("direct:query").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.QUERY_OPERATION)).to(String.format("hazelcast:%sfoo", HazelcastConstants.MAP_PREFIX))
.to("seda:out");
+ from("direct:putWithOperationNumber").toF("hazelcast:%sfoo?operation=%s", HazelcastConstants.MAP_PREFIX, HazelcastConstants.PUT_OPERATION);
+ from("direct:putWithOperationName").toF("hazelcast:%sfoo?operation=put", HazelcastConstants.MAP_PREFIX);
+
+
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java
index 3467c4b..1a01b68 100644
--- a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java
+++ b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastMultimapProducerTest.java
@@ -23,6 +23,7 @@ import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.MultiMap;
+import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.junit.After;
import org.junit.Test;
@@ -49,6 +50,11 @@ public class HazelcastMultimapProducerTest extends HazelcastCamelTestSupport {
verifyNoMoreInteractions(map);
}
+ @Test(expected = CamelExecutionException.class)
+ public void testWithInvalidOperation() {
+ template.sendBodyAndHeader("direct:putInvalid", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
+ }
+
@Test
public void testPut() throws InterruptedException {
template.sendBodyAndHeader("direct:put", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
@@ -56,6 +62,18 @@ public class HazelcastMultimapProducerTest extends HazelcastCamelTestSupport {
}
@Test
+ public void testPutWithOperationName() throws InterruptedException {
+ template.sendBodyAndHeader("direct:putWithOperationName", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
+ verify(map).put("4711", "my-foo");
+ }
+
+ @Test
+ public void testPutWithOperationNumber() throws InterruptedException {
+ template.sendBodyAndHeader("direct:putWithOperationNumber", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
+ verify(map).put("4711", "my-foo");
+ }
+
+ @Test
public void testRemoveValue() {
template.sendBodyAndHeader("direct:removevalue", "my-foo", HazelcastConstants.OBJECT_ID, "4711");
verify(map).remove("4711", "my-foo");
@@ -82,6 +100,8 @@ public class HazelcastMultimapProducerTest extends HazelcastCamelTestSupport {
@Override
public void configure() throws Exception {
+ from("direct:putInvalid").setHeader(HazelcastConstants.OPERATION, constant("bogus")).to(String.format("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX));
+
from("direct:put").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION)).to(String.format("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX));
from("direct:removevalue").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION)).to(
@@ -92,6 +112,8 @@ public class HazelcastMultimapProducerTest extends HazelcastCamelTestSupport {
from("direct:delete").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.DELETE_OPERATION)).to(String.format("hazelcast:%sbar", HazelcastConstants.MULTIMAP_PREFIX));
+ from("direct:putWithOperationNumber").toF("hazelcast:%sbar?operation=%s", HazelcastConstants.MULTIMAP_PREFIX, HazelcastConstants.PUT_OPERATION);
+ from("direct:putWithOperationName").toF("hazelcast:%sbar?operation=put", HazelcastConstants.MULTIMAP_PREFIX);
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/69998cb1/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 8877281..76e47ef 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
@@ -18,6 +18,7 @@ package org.apache.camel.component.hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IQueue;
+import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.junit.After;
import org.junit.Test;
@@ -45,6 +46,11 @@ public class HazelcastQueueProducerTest extends HazelcastCamelTestSupport {
verifyNoMoreInteractions(queue);
}
+ @Test(expected = CamelExecutionException.class)
+ public void testWithInvalidOperation() {
+ template.sendBody("direct:putInvalid", "foo");
+ }
+
@Test
public void put() throws InterruptedException {
template.sendBody("direct:put", "foo");
@@ -52,6 +58,18 @@ public class HazelcastQueueProducerTest extends HazelcastCamelTestSupport {
}
@Test
+ public void putWithOperationNumber() throws InterruptedException {
+ template.sendBody("direct:putWithOperationNumber", "foo");
+ verify(queue).put("foo");
+ }
+
+ @Test
+ public void putWithOperationName() throws InterruptedException {
+ template.sendBody("direct:putWithOperationName", "foo");
+ verify(queue).put("foo");
+ }
+
+ @Test
public void noOperation() {
template.sendBody("direct:no-operation", "bar");
verify(queue).add("bar");
@@ -104,6 +122,8 @@ public class HazelcastQueueProducerTest extends HazelcastCamelTestSupport {
public void configure() throws Exception {
from("direct:no-operation").to(String.format("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX));
+ from("direct:putInvalid").setHeader(HazelcastConstants.OPERATION, constant("bogus")).to(String.format("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX));
+
from("direct:put").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.PUT_OPERATION)).to(String.format("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX));
from("direct:add").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.ADD_OPERATION)).to(String.format("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX));
@@ -116,6 +136,10 @@ public class HazelcastQueueProducerTest extends HazelcastCamelTestSupport {
from("direct:removevalue").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REMOVEVALUE_OPERATION)).to(
String.format("hazelcast:%sbar", HazelcastConstants.QUEUE_PREFIX));
+
+ from("direct:putWithOperationNumber").toF(String.format("hazelcast:%sbar?operation=%s", HazelcastConstants.QUEUE_PREFIX, HazelcastConstants.PUT_OPERATION));
+
+ from("direct:putWithOperationName").toF(String.format("hazelcast:%sbar?operation=put", HazelcastConstants.QUEUE_PREFIX));
}
};
}