camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-8730 Camel-Hazelcast: Add replace operation to map producer
Date Sun, 03 May 2015 08:14:06 GMT
Repository: camel
Updated Branches:
  refs/heads/master 9c628c284 -> 8af7e6517


CAMEL-8730 Camel-Hazelcast: Add replace operation to map producer


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

Branch: refs/heads/master
Commit: 8af7e65170f6fe70969f0a75484269186b85cbc1
Parents: 9c628c2
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Sun May 3 10:12:25 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Sun May 3 10:12:25 2015 +0200

----------------------------------------------------------------------
 .../component/hazelcast/HazelcastConstants.java |  3 +-
 .../hazelcast/map/HazelcastMapProducer.java     | 42 ++++++++------------
 .../hazelcast/HazelcastMapProducerTest.java     | 14 ++-----
 3 files changed, 21 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8af7e651/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 84521c3..dcdcf6f 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
@@ -57,8 +57,7 @@ public final class HazelcastConstants {
     public static final int UPDATE_OPERATION = 4;
     public static final int QUERY_OPERATION = 5;
     public static final int GET_ALL_OPERATION = 6;
-    public static final int REPLACE_OPERATION = 7;
-    public static final int CLEAR_OPERATION = 8;
+    public static final int CLEAR_OPERATION = 7;
 
     // multimap
     public static final int REMOVEVALUE_OPERATION = 10;

http://git-wip-us.apache.org/repos/asf/camel/blob/8af7e651/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 ab59a6a..dfc917c 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
@@ -80,21 +80,17 @@ public class HazelcastMapProducer extends HazelcastDefaultProducer {
             break;
 
         case HazelcastConstants.UPDATE_OPERATION:
-            this.update(oid, exchange);
-            break;
-
-        case HazelcastConstants.QUERY_OPERATION:
-            this.query(query, exchange);
-            break;
-
-        case HazelcastConstants.REPLACE_OPERATION:
             if (ObjectHelper.isEmpty(ovalue)) {
-                this.replace(oid, exchange);
+                this.update(oid, exchange);
             } else {
-                this.replace(oid, ovalue, exchange);
+                this.update(oid, ovalue, exchange);
             }
             break;
 
+        case HazelcastConstants.QUERY_OPERATION:
+            this.query(query, exchange);
+            break;
+            
         case HazelcastConstants.CLEAR_OPERATION:
             this.clear(exchange);
             break;
@@ -130,6 +126,16 @@ public class HazelcastMapProducer extends HazelcastDefaultProducer {
         this.cache.replace(oid, body);
         this.cache.unlock(oid);
     }
+    
+    /**
+     * Replaces the entry for given id with a specific value in the body, only if currently
mapped to a given value
+     */
+    private void update(Object oid, Object ovalue, Exchange exchange) {
+        Object body = exchange.getIn().getBody();
+        this.cache.lock(oid);
+        this.cache.replace(oid, ovalue, body);
+        this.cache.unlock(oid);
+    }
 
     /**
      * remove an object from the cache
@@ -162,22 +168,6 @@ public class HazelcastMapProducer extends HazelcastDefaultProducer {
     }
     
     /**
-     * replace a value related to a specific key
-     */
-    private void replace(Object oid, Exchange exchange) {
-        Object body = exchange.getIn().getBody();
-        this.cache.replace(oid, body);
-    }
-    
-    /**
-     * Replaces the entry for given id with a specific value in the body, only if currently
mapped to a given value
-     */
-    private void replace(Object oid, Object ovalue, Exchange exchange) {
-        Object body = exchange.getIn().getBody();
-        this.cache.replace(oid, ovalue, body);
-    }
-    
-    /**
      * Clear all the entries
      */
     private void clear(Exchange exchange) {

http://git-wip-us.apache.org/repos/asf/camel/blob/8af7e651/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 ff11057..e820420 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
@@ -158,18 +158,14 @@ public class HazelcastMapProducerTest extends HazelcastCamelTestSupport
implemen
     }
     
     @Test
-    public void testReplace() throws InterruptedException {
-        template.sendBodyAndHeader("direct:replace", "replaced", HazelcastConstants.OBJECT_ID,
"4711");
-        verify(map).replace("4711", "replaced");
-    }
-    
-    @Test
-    public void testReplaceOldValue() throws InterruptedException {
+    public void testUpdateOldValue() throws InterruptedException {
         Map<String, Object> headers = new HashMap<String, Object>();
         headers.put(HazelcastConstants.OBJECT_ID, "4711");
         headers.put(HazelcastConstants.OBJECT_VALUE, "my-foo");
-        template.sendBodyAndHeaders("direct:replace", "replaced", headers);
+        template.sendBodyAndHeaders("direct:update", "replaced", headers);
+        verify(map).lock("4711");
         verify(map).replace("4711", "my-foo", "replaced");
+        verify(map).unlock("4711");
     }
     
     @Test
@@ -200,8 +196,6 @@ 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:replace").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.REPLACE_OPERATION)).to(String.format("hazelcast:%sfoo",
HazelcastConstants.MAP_PREFIX));
 
                 from("direct:clear").setHeader(HazelcastConstants.OPERATION, constant(HazelcastConstants.CLEAR_OPERATION)).to(String.format("hazelcast:%sfoo",
HazelcastConstants.MAP_PREFIX));
                 


Mime
View raw message