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 2015/09/25 11:20:12 UTC

[1/2] camel git commit: Fixed CS. fixes #619.

Repository: camel
Updated Branches:
  refs/heads/master e84b46d75 -> 357653a6e


Fixed CS. fixes #619.


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

Branch: refs/heads/master
Commit: 357653a6e246fe518723043b7819644b4a427932
Parents: cadb1bd
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Sep 25 11:21:37 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 25 11:21:49 2015 +0200

----------------------------------------------------------------------
 .../RedisStringIdempotentRepository.java        | 145 ++++++++++---------
 1 file changed, 79 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/357653a6/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
index 04e585a..43b6623 100644
--- a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
+++ b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
@@ -1,5 +1,27 @@
+/**
+ * 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.redis.processor.idempotent;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.api.management.ManagedOperation;
+import org.apache.camel.api.management.ManagedResource;
 import org.springframework.dao.DataAccessException;
 import org.springframework.data.redis.connection.RedisConnection;
 import org.springframework.data.redis.core.Cursor;
@@ -8,84 +30,75 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.ScanOptions;
 import org.springframework.data.redis.core.ValueOperations;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
+@ManagedResource(description = "Spring Redis based message id repository")
 public class RedisStringIdempotentRepository extends RedisIdempotentRepository {
 
-  private final ValueOperations<String, String> valueOperations;
+    private final ValueOperations<String, String> valueOperations;
 
-  /*
-  The expiry time frame for the item in seconds
-   */
-  private Long expiry;
+    private long expiry;
 
-  public RedisStringIdempotentRepository(
-      RedisTemplate<String, String> redisTemplate,
-      String processorName) {
-    super(redisTemplate, processorName);
-    this.valueOperations = redisTemplate.opsForValue();
-  }
+    public RedisStringIdempotentRepository(RedisTemplate<String, String> redisTemplate, String processorName) {
+        super(redisTemplate, processorName);
+        this.valueOperations = redisTemplate.opsForValue();
+    }
 
-  @Override
-  public boolean contains(String key) {
-    String value = valueOperations.get(createRedisKey(key));
-    if (value != null) {
-      return true;
-    } else {
-      return false;
+    @ManagedOperation(description = "Does the store contain the given key")
+    @Override
+    public boolean contains(String key) {
+        String value = valueOperations.get(createRedisKey(key));
+        return value != null;
     }
-  }
 
-  @Override
-  public boolean add(String key) {
-    boolean added = valueOperations.setIfAbsent(createRedisKey(key), key);
-    if (expiry != null) {
-      valueOperations.getOperations().expire(createRedisKey(key), expiry, TimeUnit.SECONDS);
+    @ManagedOperation(description = "Adds the key to the store")
+    @Override
+    public boolean add(String key) {
+        boolean added = valueOperations.setIfAbsent(createRedisKey(key), key);
+        if (expiry > 0) {
+            valueOperations.getOperations().expire(createRedisKey(key), expiry, TimeUnit.SECONDS);
+        }
+        return added;
     }
-    return added;
-  }
 
-  @Override
-  public boolean remove(String key) {
-    valueOperations.getOperations().delete(createRedisKey(key));
-    return true;
-  }
+    @ManagedOperation(description = "Remove the key from the store")
+    @Override
+    public boolean remove(String key) {
+        valueOperations.getOperations().delete(createRedisKey(key));
+        return true;
+    }
 
-  public void clear() {
-    valueOperations.getOperations().execute(new RedisCallback<List<byte[]>>() {
-      @Override
-      public List<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
-        List<byte[]> binaryKeys = new ArrayList<>();
-        Cursor<byte[]>
-            cursor =
-            connection.scan(ScanOptions.scanOptions().match("*" + createRedisKey("*")).build());
+    @ManagedOperation(description = "Clear the store")
+    @Override
+    public void clear() {
+        valueOperations.getOperations().execute(new RedisCallback<List<byte[]>>() {
+            @Override
+            public List<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
+                List<byte[]> binaryKeys = new ArrayList<>();
+                Cursor<byte[]> cursor = connection.scan(ScanOptions.scanOptions().match("*" + createRedisKey("*")).build());
 
-        while (cursor.hasNext()) {
-          byte[] key = cursor.next();
-          binaryKeys.add(key);
-        }
-        if (binaryKeys.size() > 0) {
-          connection.del(binaryKeys.toArray(new byte[][]{}));
-        }
-        return binaryKeys;
-      }
-    });
-  }
+                while (cursor.hasNext()) {
+                    byte[] key = cursor.next();
+                    binaryKeys.add(key);
+                }
+                if (binaryKeys.size() > 0) {
+                    connection.del(binaryKeys.toArray(new byte[][]{}));
+                }
+                return binaryKeys;
+            }
+        });
+    }
 
-  public String createRedisKey(String key) {
-    return new StringBuilder(getProcessorName()).append(":").append(key).toString();
-  }
+    protected String createRedisKey(String key) {
+        return getProcessorName() + ":" + key;
+    }
 
-  public Long getExpiry() {
-    return expiry;
-  }
+    public long getExpiry() {
+        return expiry;
+    }
 
-  /**
-   * Exire all newly added items after the given number of seconds
-   */
-  public void setExpiry(Long expiry) {
-    this.expiry = expiry;
-  }
+    /**
+     * Expire all newly added items after the given number of seconds (0 means never expire)
+     */
+    public void setExpiry(long expiry) {
+        this.expiry = expiry;
+    }
 }


[2/2] camel git commit: ADDED Redis String based idempotent repository to support expiration, refs https://issues.apache.org/jira/browse/CAMEL-9023

Posted by da...@apache.org.
ADDED Redis String based idempotent repository to support expiration, refs https://issues.apache.org/jira/browse/CAMEL-9023


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

Branch: refs/heads/master
Commit: cadb1bda94f2f4db026122716a4bcfcde2a5aa8c
Parents: e84b46d
Author: Marco Zapletal <ma...@edistream.com>
Authored: Thu Sep 24 16:52:16 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 25 11:21:49 2015 +0200

----------------------------------------------------------------------
 .../RedisStringIdempotentRepository.java        | 91 ++++++++++++++++++++
 parent/pom.xml                                  |  2 +-
 2 files changed, 92 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cadb1bda/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
new file mode 100644
index 0000000..04e585a
--- /dev/null
+++ b/components/camel-spring-redis/src/main/java/org/apache/camel/component/redis/processor/idempotent/RedisStringIdempotentRepository.java
@@ -0,0 +1,91 @@
+package org.apache.camel.component.redis.processor.idempotent;
+
+import org.springframework.dao.DataAccessException;
+import org.springframework.data.redis.connection.RedisConnection;
+import org.springframework.data.redis.core.Cursor;
+import org.springframework.data.redis.core.RedisCallback;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ScanOptions;
+import org.springframework.data.redis.core.ValueOperations;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+public class RedisStringIdempotentRepository extends RedisIdempotentRepository {
+
+  private final ValueOperations<String, String> valueOperations;
+
+  /*
+  The expiry time frame for the item in seconds
+   */
+  private Long expiry;
+
+  public RedisStringIdempotentRepository(
+      RedisTemplate<String, String> redisTemplate,
+      String processorName) {
+    super(redisTemplate, processorName);
+    this.valueOperations = redisTemplate.opsForValue();
+  }
+
+  @Override
+  public boolean contains(String key) {
+    String value = valueOperations.get(createRedisKey(key));
+    if (value != null) {
+      return true;
+    } else {
+      return false;
+    }
+  }
+
+  @Override
+  public boolean add(String key) {
+    boolean added = valueOperations.setIfAbsent(createRedisKey(key), key);
+    if (expiry != null) {
+      valueOperations.getOperations().expire(createRedisKey(key), expiry, TimeUnit.SECONDS);
+    }
+    return added;
+  }
+
+  @Override
+  public boolean remove(String key) {
+    valueOperations.getOperations().delete(createRedisKey(key));
+    return true;
+  }
+
+  public void clear() {
+    valueOperations.getOperations().execute(new RedisCallback<List<byte[]>>() {
+      @Override
+      public List<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
+        List<byte[]> binaryKeys = new ArrayList<>();
+        Cursor<byte[]>
+            cursor =
+            connection.scan(ScanOptions.scanOptions().match("*" + createRedisKey("*")).build());
+
+        while (cursor.hasNext()) {
+          byte[] key = cursor.next();
+          binaryKeys.add(key);
+        }
+        if (binaryKeys.size() > 0) {
+          connection.del(binaryKeys.toArray(new byte[][]{}));
+        }
+        return binaryKeys;
+      }
+    });
+  }
+
+  public String createRedisKey(String key) {
+    return new StringBuilder(getProcessorName()).append(":").append(key).toString();
+  }
+
+  public Long getExpiry() {
+    return expiry;
+  }
+
+  /**
+   * Exire all newly added items after the given number of seconds
+   */
+  public void setExpiry(Long expiry) {
+    this.expiry = expiry;
+  }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/cadb1bda/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 5e99df9..cc1763a 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -456,7 +456,7 @@
     <spring-boot-version>1.2.6.RELEASE</spring-boot-version>
     <spring-castor-bundle-version>1.2.0</spring-castor-bundle-version>
     <spring-data-commons-version>1.6.5.RELEASE</spring-data-commons-version>
-    <spring-data-redis-version>1.3.6.RELEASE</spring-data-redis-version>
+    <spring-data-redis-version>1.6.0.RELEASE</spring-data-redis-version>
     <spring-integration-version>2.2.6.RELEASE</spring-integration-version>
     <spring-javaconfig-version>1.0.0-20090215</spring-javaconfig-version>
     <spring-ldap-version>2.0.3.RELEASE</spring-ldap-version>