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 2012/03/31 16:32:45 UTC

svn commit: r1307815 [1/3] - in /camel/trunk: apache-camel/ apache-camel/src/main/descriptors/ components/ components/camel-leveldb/ components/camel-leveldb/src/ components/camel-leveldb/src/main/ components/camel-leveldb/src/main/java/ components/cam...

Author: davsclaus
Date: Sat Mar 31 14:32:43 2012
New Revision: 1307815

URL: http://svn.apache.org/viewvc?rev=1307815&view=rev
Log:
CAMEL-5050: Added camel-leveldb component. Thanks to Jason Sherman for the patch.

Added:
    camel/trunk/components/camel-leveldb/   (with props)
    camel/trunk/components/camel-leveldb/pom.xml   (with props)
    camel/trunk/components/camel-leveldb/src/
    camel/trunk/components/camel-leveldb/src/main/
    camel/trunk/components/camel-leveldb/src/main/java/
    camel/trunk/components/camel-leveldb/src/main/java/org/
    camel/trunk/components/camel-leveldb/src/main/java/org/apache/
    camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/
    camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/
    camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/
    camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java   (with props)
    camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBCamelCodec.java   (with props)
    camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java   (with props)
    camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/package.html   (with props)
    camel/trunk/components/camel-leveldb/src/main/resources/
    camel/trunk/components/camel-leveldb/src/main/resources/META-INF/
    camel/trunk/components/camel-leveldb/src/main/resources/META-INF/LICENSE.txt   (with props)
    camel/trunk/components/camel-leveldb/src/main/resources/META-INF/NOTICE.txt   (with props)
    camel/trunk/components/camel-leveldb/src/test/
    camel/trunk/components/camel-leveldb/src/test/java/
    camel/trunk/components/camel-leveldb/src/test/java/org/
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/BigPayload.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateCompletionIntervalTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentDifferentGroupsTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentSameGroupTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateDiscardOnTimeoutTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateForceCompletionHeaderTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateLoadAndRecoverTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateLoadConcurrentTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateLoadTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateNotLostRemovedWhenConfirmedTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateNotLostTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateRecoverDeadLetterChannelFailedTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateRecoverDeadLetterChannelTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateRecoverTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateRecoverWithRedeliveryPolicyTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateRecoverWithSedaTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateTimeoutCompletionRestartTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregationRepositoryAlotDataTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregationRepositoryLoadExistingTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregationRepositoryMultipleRepoTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregationRepositoryRecoverExistingTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregationRepositoryTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBBigPayloadTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBExchangeSerializationTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBGetNotFoundTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSpringAggregateRecoverWithRedeliveryPolicyTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSpringAggregateTest.java   (with props)
    camel/trunk/components/camel-leveldb/src/test/resources/
    camel/trunk/components/camel-leveldb/src/test/resources/jndi.properties   (with props)
    camel/trunk/components/camel-leveldb/src/test/resources/log4j.properties   (with props)
    camel/trunk/components/camel-leveldb/src/test/resources/org/
    camel/trunk/components/camel-leveldb/src/test/resources/org/apache/
    camel/trunk/components/camel-leveldb/src/test/resources/org/apache/camel/
    camel/trunk/components/camel-leveldb/src/test/resources/org/apache/camel/component/
    camel/trunk/components/camel-leveldb/src/test/resources/org/apache/camel/component/leveldb/
    camel/trunk/components/camel-leveldb/src/test/resources/org/apache/camel/component/leveldb/LevelDBSpringAggregateRecoverWithRedeliveryPolicyTest.xml   (with props)
    camel/trunk/components/camel-leveldb/src/test/resources/org/apache/camel/component/leveldb/LevelDBSpringAggregateTest.xml   (with props)
Modified:
    camel/trunk/apache-camel/pom.xml
    camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
    camel/trunk/components/pom.xml
    camel/trunk/parent/pom.xml

Modified: camel/trunk/apache-camel/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/pom.xml?rev=1307815&r1=1307814&r2=1307815&view=diff
==============================================================================
--- camel/trunk/apache-camel/pom.xml (original)
+++ camel/trunk/apache-camel/pom.xml Sat Mar 31 14:32:43 2012
@@ -308,6 +308,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-leveldb</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-mail</artifactId>
     </dependency>
     <dependency>

Modified: camel/trunk/apache-camel/src/main/descriptors/common-bin.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/src/main/descriptors/common-bin.xml?rev=1307815&r1=1307814&r2=1307815&view=diff
==============================================================================
--- camel/trunk/apache-camel/src/main/descriptors/common-bin.xml (original)
+++ camel/trunk/apache-camel/src/main/descriptors/common-bin.xml Sat Mar 31 14:32:43 2012
@@ -97,6 +97,7 @@
         <include>org.apache.camel:camel-kestrel</include>
         <include>org.apache.camel:camel-krati</include>
         <include>org.apache.camel:camel-ldap</include>
+        <include>org.apache.camel:camel-leveldb</include>
         <include>org.apache.camel:camel-lucene</include>
         <include>org.apache.camel:camel-mail</include>
         <include>org.apache.camel:camel-mina</include>

Propchange: camel/trunk/components/camel-leveldb/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Mar 31 14:32:43 2012
@@ -0,0 +1,17 @@
+.pmd
+.checkstyle
+.ruleset
+target
+.settings
+.classpath
+.project
+.wtpmodules
+prj.el
+.jdee_classpath
+.jdee_sources
+velocity.log
+eclipse-classes
+*.ipr
+*.iml
+*.iws
+*.idea

Added: camel/trunk/components/camel-leveldb/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/pom.xml?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/pom.xml (added)
+++ camel/trunk/components/camel-leveldb/pom.xml Sat Mar 31 14:32:43 2012
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-parent</artifactId>
+        <version>2.10-SNAPSHOT</version>
+        <relativePath>../../parent</relativePath>
+    </parent>
+
+    <artifactId>camel-leveldb</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: LevelDB</name>
+    <description>Camel LevelDB Support</description>
+
+    <properties>
+        <camel.osgi.export.pkg>org.apache.camel.component.leveldb.*</camel.osgi.export.pkg>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.fusesource.leveldbjni</groupId>
+            <artifactId>leveldbjni-all</artifactId>
+            <version>${leveldbjni-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.fusesource.hawtbuf</groupId>
+            <artifactId>hawtbuf</artifactId>
+            <version>${hawtbuf-version}</version>
+        </dependency>
+
+        <!-- testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-spring</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <!-- use per test fork mode to avoid side effects -->
+            <plugin>
+              <artifactId>maven-surefire-plugin</artifactId>
+              <configuration>
+                <forkMode>pertest</forkMode>
+              </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Propchange: camel/trunk/components/camel-leveldb/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-leveldb/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java (added)
+++ camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java Sat Mar 31 14:32:43 2012
@@ -0,0 +1,434 @@
+/**
+ * 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.leveldb;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.RecoverableAggregationRepository;
+import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
+import org.fusesource.hawtbuf.Buffer;
+import org.iq80.leveldb.DBIterator;
+import org.iq80.leveldb.WriteBatch;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.fusesource.leveldbjni.JniDBFactory.asString;
+
+/**
+ * An instance of {@link org.apache.camel.spi.AggregationRepository} which is backed by a {@link LevelDBFile}.
+ */
+public class LevelDBAggregationRepository extends ServiceSupport implements RecoverableAggregationRepository {
+
+    private static final transient Logger LOG = LoggerFactory.getLogger(LevelDBAggregationRepository.class);
+    private LevelDBFile levelDBFile;
+    private String persistentFileName;
+    private String repositoryName;
+    private boolean returnOldExchange;
+    private LevelDBCamelCodec codec = new LevelDBCamelCodec();
+    private long recoveryInterval = 5000;
+    private boolean useRecovery = true;
+    private int maximumRedeliveries;
+    private String deadLetterUri;
+
+    /**
+     * Creates an aggregation repository
+     */
+    public LevelDBAggregationRepository() {
+    }
+
+    /**
+     * Creates an aggregation repository
+     *
+     * @param repositoryName the repository name
+     */
+    public LevelDBAggregationRepository(String repositoryName) {
+        ObjectHelper.notEmpty(repositoryName, "repositoryName");
+        this.repositoryName = repositoryName;
+    }
+
+    /**
+     * Creates an aggregation repository using a new {@link LevelDBFile}
+     * that persists using the provided file.
+     *
+     * @param repositoryName     the repository name
+     * @param persistentFileName the persistent store filename
+     */
+    public LevelDBAggregationRepository(String repositoryName, String persistentFileName) {
+        ObjectHelper.notEmpty(repositoryName, "repositoryName");
+        ObjectHelper.notEmpty(persistentFileName, "persistentFileName");
+        this.repositoryName = repositoryName;
+        this.persistentFileName = persistentFileName;
+    }
+
+    /**
+     * Creates an aggregation repository using the provided {@link LevelDBFile}.
+     *
+     * @param repositoryName the repository name
+     * @param levelDBFile    the leveldb file to use as persistent store
+     */
+    public LevelDBAggregationRepository(String repositoryName, LevelDBFile levelDBFile) {
+        ObjectHelper.notEmpty(repositoryName, "repositoryName");
+        ObjectHelper.notNull(levelDBFile, "levelDBFile");
+        this.levelDBFile = levelDBFile;
+        this.repositoryName = repositoryName;
+    }
+
+    public Exchange add(final CamelContext camelContext, final String key, final Exchange exchange) {
+        LOG.debug("Adding key [{}] -> {}", key, exchange);
+        try {
+            byte[] lDbKey = keyBuilder(repositoryName, key);
+            final Buffer exchangeBuffer = codec.marshallExchange(camelContext, exchange);
+
+            byte[] rc = null;
+            if (isReturnOldExchange()) {
+                rc = levelDBFile.getDb().get(lDbKey);
+            }
+
+            LOG.trace("Adding key index {} for repository {}", key, repositoryName);
+            levelDBFile.getDb().put(lDbKey, exchangeBuffer.toByteArray(), levelDBFile.getWriteOptions());
+            LOG.trace("Added key index {}", key);
+
+            if (rc == null) {
+                return null;
+            }
+
+            // only return old exchange if enabled
+            if (isReturnOldExchange()) {
+                return codec.unmarshallExchange(camelContext, new Buffer(rc));
+            }
+        } catch (IOException e) {
+            throw new RuntimeException("Error adding to repository " + repositoryName + " with key " + key, e);
+        }
+
+        return null;
+    }
+
+    public Exchange get(final CamelContext camelContext, final String key) {
+        Exchange answer = null;
+
+        try {
+            byte[] lDbKey = keyBuilder(repositoryName, key);
+            LOG.trace("Getting key index {}", key);
+            byte[] rc = levelDBFile.getDb().get(lDbKey);
+
+            if (rc != null) {
+                answer = codec.unmarshallExchange(camelContext, new Buffer(rc));
+            }
+        } catch (IOException e) {
+            throw new RuntimeException("Error getting key " + key + " from repository " + repositoryName, e);
+        }
+
+        LOG.debug("Getting key  [{}] -> {}", key, answer);
+        return answer;
+    }
+
+    public void remove(final CamelContext camelContext, final String key, final Exchange exchange) {
+        LOG.debug("Removing key [{}]", key);
+
+        try {
+            byte[] lDbKey = keyBuilder(repositoryName, key);
+            final String exchangeId = exchange.getExchangeId();
+            final Buffer exchangeBuffer = codec.marshallExchange(camelContext, exchange);
+
+            // remove the exchange
+            byte[] rc = levelDBFile.getDb().get(lDbKey);
+
+            if (rc != null) {
+                WriteBatch batch = levelDBFile.getDb().createWriteBatch();
+                try {
+                    batch.delete(lDbKey);
+                    LOG.trace("Removed key index {} -> {}", key, new Buffer(rc));
+
+                    // add exchange to confirmed index
+                    byte[] confirmedLDBKey = keyBuilder(getRepositoryNameCompleted(), exchangeId);
+                    batch.put(confirmedLDBKey, exchangeBuffer.toByteArray());
+                    LOG.trace("Added confirm index {} for repository {}", exchangeId, getRepositoryNameCompleted());
+
+                    levelDBFile.getDb().write(batch, levelDBFile.getWriteOptions());
+                } finally {
+                    batch.close();
+                }
+            } else {
+                LOG.warn("Unable to remove key {} from repository {}: Not Found", key, repositoryName);
+            }
+
+        } catch (IOException e) {
+            throw new RuntimeException("Error removing key " + key + " from repository " + repositoryName, e);
+        }
+    }
+
+    public void confirm(final CamelContext camelContext, final String exchangeId) {
+        LOG.debug("Confirming exchangeId [{}]", exchangeId);
+
+        byte[] confirmedLDBKey = keyBuilder(getRepositoryNameCompleted(), exchangeId);
+
+        byte[] rc = levelDBFile.getDb().get(confirmedLDBKey);
+
+        if (rc != null) {
+            levelDBFile.getDb().delete(confirmedLDBKey);
+            LOG.trace("Removed confirm index {} -> {}", exchangeId, new Buffer(rc));
+        } else {
+            LOG.warn("Unable to confirm exchangeId [{}]", exchangeId + " from repository " + repositoryName + ": Not Found");
+        }
+    }
+
+    public Set<String> getKeys() {
+        final Set<String> keys = new LinkedHashSet<String>();
+
+        // interval task could potentially be running while we are shutting down so check for that
+        if (!isRunAllowed()) {
+            return null;
+        }
+
+        DBIterator it = levelDBFile.getDb().iterator();
+
+        String keyBuffer = null;
+        try {
+            String prefix = repositoryName + '\0';
+            for (it.seek(keyBuilder(repositoryName, "")); it.hasNext(); it.next()) {
+                if (!isRunAllowed()) {
+                    break;
+                }
+                keyBuffer = asString(it.peekNext().getKey());
+
+                if (!keyBuffer.startsWith(prefix)) {
+                    break;
+                }
+
+                String key = keyBuffer.substring(prefix.length());
+
+                if (key != null) {
+                    LOG.trace("getKey [{}]", key);
+                    keys.add(key);
+                }
+            }
+        } finally {
+            // Make sure you close the iterator to avoid resource leaks.
+            it.close();
+        }
+
+        return Collections.unmodifiableSet(keys);
+    }
+
+    public Set<String> scan(CamelContext camelContext) {
+        final Set<String> answer = new LinkedHashSet<String>();
+
+        if (!isRunAllowed()) {
+            return null;
+        }
+
+        DBIterator it = levelDBFile.getDb().iterator();
+
+        String keyBuffer = null;
+        try {
+            String prefix = getRepositoryNameCompleted() + '\0';
+
+            for (it.seek(keyBuilder(getRepositoryNameCompleted(), "")); it.hasNext(); it.next()) {
+                keyBuffer = asString(it.peekNext().getKey());
+
+                if (!keyBuffer.startsWith(prefix)) {
+                    break;
+                }
+                String exchangeId = keyBuffer.substring(prefix.length());
+
+                if (exchangeId != null) {
+                    LOG.trace("Scan exchangeId [{}]", exchangeId);
+                    answer.add(exchangeId);
+                }
+
+            }
+        } finally {
+            // Make sure you close the iterator to avoid resource leaks.
+            it.close();
+        }
+
+        if (answer.size() == 0) {
+            LOG.trace("Scanned and found no exchange to recover.");
+        } else {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Scanned and found {} exchange(s) to recover (note some of them may already be in progress).", answer.size());
+            }
+        }
+        return answer;
+
+    }
+
+    public Exchange recover(CamelContext camelContext, final String exchangeId) {
+        Exchange answer = null;
+
+        try {
+            byte[] completedLDBKey = keyBuilder(getRepositoryNameCompleted(), exchangeId);
+
+            byte[] rc = levelDBFile.getDb().get(completedLDBKey);
+
+            if (rc != null) {
+                answer = codec.unmarshallExchange(camelContext, new Buffer(rc));
+            }
+        } catch (IOException e) {
+            throw new RuntimeException("Error recovering exchangeId " + exchangeId + " from repository " + repositoryName, e);
+        }
+
+        LOG.debug("Recovering exchangeId [{}] -> {}", exchangeId, answer);
+        return answer;
+    }
+
+    private int size(final String repositoryName) {
+        DBIterator it = levelDBFile.getDb().iterator();
+
+        String prefix = repositoryName + '\0';
+        int count = 0;
+        try {
+            for (it.seek(keyBuilder(repositoryName, "")); it.hasNext(); it.next()) {
+                if (!asString(it.peekNext().getKey()).startsWith(prefix)) {
+                    break;
+                }
+                count++;
+            }
+        } finally {
+            // Make sure you close the iterator to avoid resource leaks.
+            it.close();
+        }
+
+        LOG.debug("Size of repository [{}] -> {}", repositoryName, count);
+        return count;
+    }
+
+    public LevelDBFile getLevelDBFile() {
+        return levelDBFile;
+    }
+
+    public void setLevelDBFile(LevelDBFile levelDBFile) {
+        this.levelDBFile = levelDBFile;
+    }
+
+    public String getRepositoryName() {
+        return repositoryName;
+    }
+
+    private String getRepositoryNameCompleted() {
+        return repositoryName + "-completed";
+    }
+
+    public void setRepositoryName(String repositoryName) {
+        this.repositoryName = repositoryName;
+    }
+
+    public boolean isReturnOldExchange() {
+        return returnOldExchange;
+    }
+
+    public void setReturnOldExchange(boolean returnOldExchange) {
+        this.returnOldExchange = returnOldExchange;
+    }
+
+    public void setRecoveryInterval(long interval, TimeUnit timeUnit) {
+        this.recoveryInterval = timeUnit.toMillis(interval);
+    }
+
+    public void setRecoveryInterval(long interval) {
+        this.recoveryInterval = interval;
+    }
+
+    public long getRecoveryIntervalInMillis() {
+        return recoveryInterval;
+    }
+
+    public boolean isUseRecovery() {
+        return useRecovery;
+    }
+
+    public void setUseRecovery(boolean useRecovery) {
+        this.useRecovery = useRecovery;
+    }
+
+    public int getMaximumRedeliveries() {
+        return maximumRedeliveries;
+    }
+
+    public void setMaximumRedeliveries(int maximumRedeliveries) {
+        this.maximumRedeliveries = maximumRedeliveries;
+    }
+
+    public String getDeadLetterUri() {
+        return deadLetterUri;
+    }
+
+    public void setDeadLetterUri(String deadLetterUri) {
+        this.deadLetterUri = deadLetterUri;
+    }
+
+    public String getPersistentFileName() {
+        return persistentFileName;
+    }
+
+    public void setPersistentFileName(String persistentFileName) {
+        this.persistentFileName = persistentFileName;
+    }
+
+
+    @Override
+    protected void doStart() throws Exception {
+        // either we have a LevelDB configured or we use a provided fileName
+        if (levelDBFile == null && persistentFileName != null) {
+            levelDBFile = new LevelDBFile();
+            levelDBFile.setFileName(persistentFileName);
+        }
+
+        ObjectHelper.notNull(levelDBFile, "Either set a persistentFileName or a levelDBFile");
+        ObjectHelper.notNull(repositoryName, "repositoryName");
+
+        ServiceHelper.startService(levelDBFile);
+
+        // log number of existing exchanges
+        int current = size(getRepositoryName());
+        int completed = size(getRepositoryNameCompleted());
+
+        if (current > 0) {
+            LOG.info("On startup there are " + current + " aggregate exchanges (not completed) in repository: " + getRepositoryName());
+        } else {
+            LOG.info("On startup there are no existing aggregate exchanges (not completed) in repository: " + getRepositoryName());
+        }
+        if (completed > 0) {
+            LOG.warn("On startup there are " + completed + " completed exchanges to be recovered in repository: " + getRepositoryNameCompleted());
+        } else {
+            LOG.info("On startup there are no completed exchanges to be recovered in repository: " + getRepositoryNameCompleted());
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        ServiceHelper.stopService(levelDBFile);
+    }
+
+    public static byte[] keyBuilder(String repo, String key) {
+        try {
+            return (repo + '\0' + key).getBytes("UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBCamelCodec.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBCamelCodec.java?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBCamelCodec.java (added)
+++ camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBCamelCodec.java Sat Mar 31 14:32:43 2012
@@ -0,0 +1,88 @@
+/**
+ * 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.leveldb;
+
+import java.io.IOException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.DefaultExchangeHolder;
+import org.fusesource.hawtbuf.Buffer;
+import org.fusesource.hawtbuf.DataByteArrayInputStream;
+import org.fusesource.hawtbuf.DataByteArrayOutputStream;
+import org.fusesource.hawtbuf.codec.Codec;
+import org.fusesource.hawtbuf.codec.ObjectCodec;
+import org.fusesource.hawtbuf.codec.StringCodec;
+
+/**
+ * @version 
+ */
+public final class LevelDBCamelCodec {
+
+    private Codec<String> keyCodec = new StringCodec();
+    private Codec<DefaultExchangeHolder> exchangeCodec = new ObjectCodec<DefaultExchangeHolder>();
+
+    public Buffer marshallKey(String key) throws IOException {
+        DataByteArrayOutputStream baos = new DataByteArrayOutputStream();
+        keyCodec.encode(key, baos);
+        return baos.toBuffer();
+    }
+
+    public String unmarshallKey(Buffer buffer) throws IOException {
+        DataByteArrayInputStream bais = new DataByteArrayInputStream(buffer);
+        String key = keyCodec.decode(bais);
+        return key;
+    }
+
+    public Buffer marshallExchange(CamelContext camelContext, Exchange exchange) throws IOException {
+        DataByteArrayOutputStream baos = new DataByteArrayOutputStream();
+        // use DefaultExchangeHolder to marshal to a serialized object
+        DefaultExchangeHolder pe = DefaultExchangeHolder.marshal(exchange, false);
+        // add the aggregated size and timeout property as the only properties we want to retain
+        DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_SIZE, exchange.getProperty(Exchange.AGGREGATED_SIZE, Integer.class));
+        DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_TIMEOUT, exchange.getProperty(Exchange.AGGREGATED_TIMEOUT, Long.class));
+        // add the aggregated completed by property to retain
+        DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_COMPLETED_BY, exchange.getProperty(Exchange.AGGREGATED_COMPLETED_BY, String.class));
+        // add the aggregated correlation key property to retain
+        DefaultExchangeHolder.addProperty(pe, Exchange.AGGREGATED_CORRELATION_KEY, exchange.getProperty(Exchange.AGGREGATED_CORRELATION_KEY, String.class));
+        // persist the from endpoint as well
+        if (exchange.getFromEndpoint() != null) {
+            DefaultExchangeHolder.addProperty(pe, "CamelAggregatedFromEndpoint", exchange.getFromEndpoint().getEndpointUri());
+        }
+        exchangeCodec.encode(pe, baos);
+        return baos.toBuffer();
+    }
+
+    public Exchange unmarshallExchange(CamelContext camelContext, Buffer buffer) throws IOException {
+        DataByteArrayInputStream bais = new DataByteArrayInputStream(buffer);
+        DefaultExchangeHolder pe = exchangeCodec.decode(bais);
+        Exchange answer = new DefaultExchange(camelContext);
+        DefaultExchangeHolder.unmarshal(answer, pe);
+        // restore the from endpoint
+        String fromEndpointUri = (String) answer.removeProperty("CamelAggregatedFromEndpoint");
+        if (fromEndpointUri != null) {
+            Endpoint fromEndpoint = camelContext.hasEndpoint(fromEndpointUri);
+            if (fromEndpoint != null) {
+                answer.setFromEndpoint(fromEndpoint);
+            }
+        }
+        return answer;
+    }
+
+}

Propchange: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBCamelCodec.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBCamelCodec.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java (added)
+++ camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java Sat Mar 31 14:32:43 2012
@@ -0,0 +1,189 @@
+/**
+ * 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.leveldb;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.camel.Service;
+import org.iq80.leveldb.CompressionType;
+import org.iq80.leveldb.DB;
+import org.iq80.leveldb.Options;
+import org.iq80.leveldb.WriteOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.fusesource.leveldbjni.JniDBFactory.factory;
+
+/**
+ * Manages access to a shared <a href="https://github.com/fusesource/leveldbjni/">LevelDB</a> file.
+ * <p/>
+ * Will by default not sync writes which allows it to be faster.
+ * You can force syncing by setting the sync option to <tt>true</tt>.
+ */
+public class LevelDBFile implements Service {
+
+    private static final transient Logger LOG = LoggerFactory.getLogger(LevelDBFile.class);
+
+    private DB db;
+    private File file;
+    private int writeBufferSize = 4 << 20;
+    private int maxOpenFiles = 1000;
+    private int blockRestartInterval = 16;
+    private int blockSize = 4 * 1024;
+    private String compressionType;
+    private boolean verifyChecksums = true;
+    private boolean paranoidChecks;
+    private long cacheSize = 32 << 20;
+    private boolean sync;
+
+    public DB getDb() {
+        return db;
+    }
+
+    public void setFile(File file) throws IOException {
+        this.file = file;
+    }
+
+    public File getFile() {
+        return file;
+    }
+
+    public void setFileName(String fileName) {
+        this.file = new File(fileName);
+    }
+
+    public String getFileName() throws IOException {
+        return file.getCanonicalPath();
+    }
+
+    public int getWriteBufferSize() {
+        return writeBufferSize;
+    }
+
+    public void setWriteBufferSize(int writeBufferSize) {
+        this.writeBufferSize = writeBufferSize;
+    }
+
+    public int getMaxOpenFiles() {
+        return maxOpenFiles;
+    }
+
+    public void setMaxOpenFiles(int maxOpenFiles) {
+        this.maxOpenFiles = maxOpenFiles;
+    }
+
+    public int getBlockRestartInterval() {
+        return blockRestartInterval;
+    }
+
+    public void setBlockRestartInterval(int blockRestartInterval) {
+        this.blockRestartInterval = blockRestartInterval;
+    }
+
+    public int getBlockSize() {
+        return blockSize;
+    }
+
+    public void setBlockSize(int blockSize) {
+        this.blockSize = blockSize;
+    }
+
+    public String getCompressionType() {
+        return compressionType;
+    }
+
+    public void setCompressionType(String compressionType) {
+        this.compressionType = compressionType;
+    }
+
+    public boolean isVerifyChecksums() {
+        return verifyChecksums;
+    }
+
+    public void setVerifyChecksums(boolean verifyChecksums) {
+        this.verifyChecksums = verifyChecksums;
+    }
+
+    public boolean isParanoidChecks() {
+        return paranoidChecks;
+    }
+
+    public void setParanoidChecks(boolean paranoidChecks) {
+        this.paranoidChecks = paranoidChecks;
+    }
+
+    public long getCacheSize() {
+        return cacheSize;
+    }
+
+    public void setCacheSize(long cacheSize) {
+        this.cacheSize = cacheSize;
+    }
+
+    public boolean isSync() {
+        return sync;
+    }
+
+    public void setSync(boolean sync) {
+        this.sync = sync;
+    }
+
+    public WriteOptions getWriteOptions() {
+        WriteOptions options = new WriteOptions();
+        options.sync(sync);
+        return options;
+    }
+
+    public void start() {
+        if (getFile() == null) {
+            throw new IllegalArgumentException("A file must be configured");
+        }
+
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Starting LevelDB using file: {}", getFile());
+        }
+
+        Options options = new Options().writeBufferSize(writeBufferSize).maxOpenFiles(maxOpenFiles)
+                .blockRestartInterval(blockRestartInterval).blockSize(blockSize).verifyChecksums(verifyChecksums)
+                .paranoidChecks(paranoidChecks).cacheSize(cacheSize);
+
+        if ("snappy".equals(compressionType)) {
+            options.compressionType(CompressionType.SNAPPY);
+        } else {
+            options.compressionType(CompressionType.NONE);
+        }
+
+        options.createIfMissing(true);
+        try {
+            getFile().getParentFile().mkdirs();
+            db = factory.open(getFile(), options);
+        } catch (IOException ioe) {
+            throw new RuntimeException("Error opening LevelDB with file " + getFile(), ioe);
+        }
+    }
+
+    public void stop() {
+        File file = getFile();
+
+        LOG.debug("Stopping LevelDB using file: {}", file);
+        if (db != null) {
+            db.close();
+            db = null;
+        }
+    }
+}

Propchange: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/package.html
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/package.html?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/package.html (added)
+++ camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/package.html Sat Mar 31 14:32:43 2012
@@ -0,0 +1,24 @@
+<!--
+    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.
+-->
+<html>
+<head>
+</head>
+<body>
+Camel <a href="https://github.com/fusesource/leveldbjni">LevelDB</a> support
+
+</body>
+</html>

Propchange: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/package.html
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: camel/trunk/components/camel-leveldb/src/main/resources/META-INF/LICENSE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/main/resources/META-INF/LICENSE.txt?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/main/resources/META-INF/LICENSE.txt (added)
+++ camel/trunk/components/camel-leveldb/src/main/resources/META-INF/LICENSE.txt Sat Mar 31 14:32:43 2012
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

Propchange: camel/trunk/components/camel-leveldb/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
    svn:executable = *

Propchange: camel/trunk/components/camel-leveldb/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/components/camel-leveldb/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/main/resources/META-INF/NOTICE.txt?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/main/resources/META-INF/NOTICE.txt (added)
+++ camel/trunk/components/camel-leveldb/src/main/resources/META-INF/NOTICE.txt Sat Mar 31 14:32:43 2012
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

Propchange: camel/trunk/components/camel-leveldb/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/BigPayload.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/BigPayload.java?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/BigPayload.java (added)
+++ camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/BigPayload.java Sat Mar 31 14:32:43 2012
@@ -0,0 +1,34 @@
+/**
+ * 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.leveldb;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Handler;
+
+/**
+ * a 3mb payload
+ */
+public class BigPayload {
+
+    private int bodySize = 3 * 1024 * 1024;
+
+    @Handler
+    public void process(Exchange exchange) {
+        exchange.getIn().setBody(new byte[bodySize]);
+    }
+
+}

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/BigPayload.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/BigPayload.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateCompletionIntervalTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateCompletionIntervalTest.java?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateCompletionIntervalTest.java (added)
+++ camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateCompletionIntervalTest.java Sat Mar 31 14:32:43 2012
@@ -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.leveldb;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class LevelDBAggregateCompletionIntervalTest extends CamelTestSupport {
+
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/data");
+        super.setUp();
+    }
+
+    @Test
+    public void testLevelDBAggregateCompletionInterval() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:aggregated");
+        mock.setResultWaitTime(30 * 1000L);
+        mock.expectedBodiesReceived("ABCD", "E");
+
+        // wait a bit so we complete on the next poll
+        Thread.sleep(2000);
+
+        template.sendBodyAndHeader("direct:start", "A", "id", 123);
+        template.sendBodyAndHeader("direct:start", "B", "id", 123);
+        template.sendBodyAndHeader("direct:start", "C", "id", 123);
+        template.sendBodyAndHeader("direct:start", "D", "id", 123);
+
+        Thread.sleep(6000);
+
+        template.sendBodyAndHeader("direct:start", "E", "id", 123);
+
+        assertMockEndpointsSatisfied();
+
+        // from endpoint should be preserved
+        assertEquals("direct://start", mock.getReceivedExchanges().get(0).getFromEndpoint().getEndpointUri());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            // START SNIPPET: e1
+            public void configure() throws Exception {
+                // create the leveldb repo
+                LevelDBAggregationRepository repo = new LevelDBAggregationRepository("repo1", "target/data/leveldb.dat");
+
+                // here is the Camel route where we aggregate
+                from("direct:start")
+                    .aggregate(header("id"), new MyAggregationStrategy())
+                        // complete every 5th seconds
+                        .completionInterval(5000).aggregationRepository(repo)
+                        .to("mock:aggregated");
+            }
+            // END SNIPPET: e1
+        };
+    }
+
+    public static class MyAggregationStrategy implements AggregationStrategy {
+
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            if (oldExchange == null) {
+                return newExchange;
+            }
+            String body1 = oldExchange.getIn().getBody(String.class);
+            String body2 = newExchange.getIn().getBody(String.class);
+
+            oldExchange.getIn().setBody(body1 + body2);
+            return oldExchange;
+        }
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateCompletionIntervalTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateCompletionIntervalTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentDifferentGroupsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentDifferentGroupsTest.java?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentDifferentGroupsTest.java (added)
+++ camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentDifferentGroupsTest.java Sat Mar 31 14:32:43 2012
@@ -0,0 +1,107 @@
+/**
+ * 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.leveldb;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class LevelDBAggregateConcurrentDifferentGroupsTest extends CamelTestSupport {
+
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/data");
+        super.setUp();
+    }
+
+    @Test
+    public void testNoConcurrentProducers() throws Exception {
+        doSendMessages(2, 1);
+    }
+
+    @Test
+    public void testConcurrentProducers() throws Exception {
+        doSendMessages(10, 5);
+    }
+
+    @Test
+    public void testMoreConcurrentProducers() throws Exception {
+        doSendMessages(50, 10);
+    }
+
+    private void doSendMessages(int files, int poolSize) throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:aggregated");
+        mock.expectedMessageCount(2);
+        mock.setResultWaitTime(30 * 1000L);
+
+        ExecutorService executor = Executors.newFixedThreadPool(poolSize);
+        for (int i = 0; i < files; i++) {
+            final int index = i;
+            executor.submit(new Callable<Object>() {
+                public Object call() throws Exception {
+                    String id = index % 2 == 0 ? "A" : "B";
+                    template.sendBodyAndHeader("direct:start", index, "id", id);
+                    // simulate a little delay
+                    Thread.sleep(3);
+                    return null;
+                }
+            });
+        }
+
+        assertMockEndpointsSatisfied();
+        executor.shutdownNow();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                LevelDBAggregationRepository repo = new LevelDBAggregationRepository("repo1", "target/data/leveldb.dat");
+
+                from("direct:start")
+                    .aggregate(header("id"), new MyAggregationStrategy())
+                        .completionTimeout(1000).aggregationRepository(repo)
+                        .to("mock:aggregated");
+            }
+        };
+    }
+
+    private static class MyAggregationStrategy implements AggregationStrategy {
+
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            if (oldExchange == null) {
+                return newExchange;
+            }
+            String body1 = oldExchange.getIn().getBody(String.class);
+            String body2 = newExchange.getIn().getBody(String.class);
+
+            oldExchange.getIn().setBody(body1 + body2);
+            return oldExchange;
+        }
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentDifferentGroupsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentDifferentGroupsTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentSameGroupTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentSameGroupTest.java?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentSameGroupTest.java (added)
+++ camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentSameGroupTest.java Sat Mar 31 14:32:43 2012
@@ -0,0 +1,106 @@
+/**
+ * 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.leveldb;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version 
+ */
+public class LevelDBAggregateConcurrentSameGroupTest extends CamelTestSupport {
+
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/data");
+        super.setUp();
+    }
+
+    @Test
+    public void testNoConcurrentProducers() throws Exception {
+        doSendMessages(1, 1);
+    }
+
+    @Test
+    public void testConcurrentProducers() throws Exception {
+        doSendMessages(10, 5);
+    }
+
+    @Test
+    public void testMoreConcurrentProducers() throws Exception {
+        doSendMessages(50, 10);
+    }
+
+    private void doSendMessages(int files, int poolSize) throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:aggregated");
+        mock.setResultWaitTime(30 * 1000L);
+        mock.expectedMessageCount(1);
+
+        ExecutorService executor = Executors.newFixedThreadPool(poolSize);
+        for (int i = 0; i < files; i++) {
+            final int index = i;
+            executor.submit(new Callable<Object>() {
+                public Object call() throws Exception {
+                    template.sendBodyAndHeader("direct:start", index, "id", 123);
+                    // simulate a little delay
+                    Thread.sleep(3);
+                    return null;
+                }
+            });
+        }
+
+        assertMockEndpointsSatisfied();
+        executor.shutdownNow();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                LevelDBAggregationRepository repo = new LevelDBAggregationRepository("repo1", "target/data/leveldb.dat");
+
+                from("direct:start")
+                    .aggregate(header("id"), new MyAggregationStrategy())
+                        .completionTimeout(1000).aggregationRepository(repo)
+                        .to("mock:aggregated");
+            }
+        };
+    }
+
+    private static class MyAggregationStrategy implements AggregationStrategy {
+
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            if (oldExchange == null) {
+                return newExchange;
+            }
+            String body1 = oldExchange.getIn().getBody(String.class);
+            String body2 = newExchange.getIn().getBody(String.class);
+
+            oldExchange.getIn().setBody(body1 + body2);
+            return oldExchange;
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentSameGroupTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateConcurrentSameGroupTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateDiscardOnTimeoutTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateDiscardOnTimeoutTest.java?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateDiscardOnTimeoutTest.java (added)
+++ camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateDiscardOnTimeoutTest.java Sat Mar 31 14:32:43 2012
@@ -0,0 +1,98 @@
+/**
+ * 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.leveldb;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class LevelDBAggregateDiscardOnTimeoutTest extends CamelTestSupport {
+   
+    private LevelDBAggregationRepository repo;
+
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/data");
+        repo = new LevelDBAggregationRepository("repo1", "target/data/leveldb.dat");
+        // enable recovery
+        repo.setUseRecovery(true);
+        // check faster
+        repo.setRecoveryInterval(500, TimeUnit.MILLISECONDS);
+        super.setUp();
+    }
+
+    @Test
+    public void testAggregateDiscardOnTimeout() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:aggregated");
+        mock.expectedMessageCount(0);
+
+        template.sendBodyAndHeader("direct:start", "A", "id", 123);
+        template.sendBodyAndHeader("direct:start", "B", "id", 123);
+
+        // wait 3 seconds
+        Thread.sleep(3000);
+
+        mock.assertIsSatisfied();
+
+        // now send 3 which does not timeout
+        mock.reset();
+        mock.expectedBodiesReceived("C+D+E");
+
+        template.sendBodyAndHeader("direct:start", "A", "id", 123);
+        template.sendBodyAndHeader("direct:start", "B", "id", 123);
+        template.sendBodyAndHeader("direct:start", "C", "id", 123);
+
+        // should complete before timeout
+        mock.await(1500, TimeUnit.MILLISECONDS);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .aggregate(header("id"), new MyAggregationStrategy())
+                        .completionSize(3).aggregationRepository(repo)
+                        // use a 3 second timeout
+                        .completionTimeout(2000)
+                        // and if timeout occurred then just discard the aggregated message
+                        .discardOnCompletionTimeout()
+                        .to("mock:aggregated");
+            }
+        };
+    }
+
+    public static class MyAggregationStrategy implements AggregationStrategy {
+
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            if (oldExchange == null) {
+                return newExchange;
+            }
+            String body1 = oldExchange.getIn().getBody(String.class);
+            String body2 = newExchange.getIn().getBody(String.class);
+
+            oldExchange.getIn().setBody(body1 + body2);
+            return oldExchange;
+        }
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateDiscardOnTimeoutTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateDiscardOnTimeoutTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateForceCompletionHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateForceCompletionHeaderTest.java?rev=1307815&view=auto
==============================================================================
--- camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateForceCompletionHeaderTest.java (added)
+++ camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateForceCompletionHeaderTest.java Sat Mar 31 14:32:43 2012
@@ -0,0 +1,89 @@
+/**
+ * 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.leveldb;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * To test CAMEL-4118 support for completing all aggregation groups with a signal message
+ */
+public class LevelDBAggregateForceCompletionHeaderTest extends CamelTestSupport {
+
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/data");
+        super.setUp();
+    }
+
+    @Test
+    public void testForceCompletionTrue() throws Exception {
+
+        getMockEndpoint("mock:aggregated").expectedMessageCount(0);
+
+        template.sendBodyAndHeader("direct:start", "test1", "id", "1");
+        template.sendBodyAndHeader("direct:start", "test2", "id", "2");
+        template.sendBodyAndHeader("direct:start", "test3", "id", "1");
+        template.sendBodyAndHeader("direct:start", "test4", "id", "2");
+
+        assertMockEndpointsSatisfied();
+
+        getMockEndpoint("mock:aggregated").expectedMessageCount(2);
+        getMockEndpoint("mock:aggregated").expectedBodiesReceived("test1test3", "test2test4");
+        getMockEndpoint("mock:aggregated").expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "forceCompletion");
+
+        //now send the signal message to trigger completion of all groups, message should NOT be aggregated
+        template.sendBodyAndHeader("direct:start", "test5", Exchange.AGGREGATION_COMPLETE_ALL_GROUPS, true);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // create the leveldb repo
+                LevelDBAggregationRepository repo = new LevelDBAggregationRepository("repo1", "target/data/leveldb.dat");
+
+                // here is the Camel route where we aggregate
+                from("direct:start")
+                    .aggregate(header("id"), new MyAggregationStrategy())
+                        // use our created leveldb repo as aggregation repository
+                        .completionSize(10).aggregationRepository(repo)
+                        .to("mock:aggregated");
+            }
+        };
+    }
+
+    public static class MyAggregationStrategy implements AggregationStrategy {
+
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            if (oldExchange == null) {
+                return newExchange;
+            }
+            String body1 = oldExchange.getIn().getBody(String.class);
+            String body2 = newExchange.getIn().getBody(String.class);
+
+            oldExchange.getIn().setBody(body1 + body2);
+            return oldExchange;
+        }
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateForceCompletionHeaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateForceCompletionHeaderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date