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 2011/10/24 14:40:19 UTC

svn commit: r1188121 [1/2] - in /camel/trunk: apache-camel/ apache-camel/src/main/descriptors/ components/ components/camel-krati/ components/camel-krati/src/ components/camel-krati/src/main/ components/camel-krati/src/main/java/ components/camel-krati...

Author: davsclaus
Date: Mon Oct 24 12:40:18 2011
New Revision: 1188121

URL: http://svn.apache.org/viewvc?rev=1188121&view=rev
Log:
CAMEL-4566: New camel-krati component. Thanks to Ioannis for contribution.

Added:
    camel/trunk/components/camel-krati/
    camel/trunk/components/camel-krati/pom.xml   (with props)
    camel/trunk/components/camel-krati/src/
    camel/trunk/components/camel-krati/src/main/
    camel/trunk/components/camel-krati/src/main/java/
    camel/trunk/components/camel-krati/src/main/java/org/
    camel/trunk/components/camel-krati/src/main/java/org/apache/
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiComponent.java   (with props)
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConstants.java   (with props)
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConsumer.java   (with props)
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiDataStoreRegistration.java   (with props)
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiEndpoint.java   (with props)
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiHelper.java   (with props)
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java   (with props)
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/processor/
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/processor/idempotent/
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/processor/idempotent/KratiIdempotentRepository.java   (with props)
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/serializer/
    camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/serializer/KratiDefaultSerializer.java   (with props)
    camel/trunk/components/camel-krati/src/main/resources/
    camel/trunk/components/camel-krati/src/main/resources/META-INF/
    camel/trunk/components/camel-krati/src/main/resources/META-INF/LICENSE.txt   (with props)
    camel/trunk/components/camel-krati/src/main/resources/META-INF/NOTICE.txt   (with props)
    camel/trunk/components/camel-krati/src/main/resources/META-INF/services/
    camel/trunk/components/camel-krati/src/main/resources/META-INF/services/org/
    camel/trunk/components/camel-krati/src/main/resources/META-INF/services/org/apache/
    camel/trunk/components/camel-krati/src/main/resources/META-INF/services/org/apache/camel/
    camel/trunk/components/camel-krati/src/main/resources/META-INF/services/org/apache/camel/component/
    camel/trunk/components/camel-krati/src/main/resources/META-INF/services/org/apache/camel/component/krati
    camel/trunk/components/camel-krati/src/test/
    camel/trunk/components/camel-krati/src/test/java/
    camel/trunk/components/camel-krati/src/test/java/org/
    camel/trunk/components/camel-krati/src/test/java/org/apache/
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerSpringTest.java   (with props)
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerTest.java   (with props)
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiEndpointTest.java   (with props)
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerSpringTest.java   (with props)
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerTest.java   (with props)
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/processor/
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/processor/idempotent/
    camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/processor/idempotent/KratiIdempotentRepositoryTest.java   (with props)
    camel/trunk/components/camel-krati/src/test/resources/
    camel/trunk/components/camel-krati/src/test/resources/consumer-test.xml   (with props)
    camel/trunk/components/camel-krati/src/test/resources/log4j.properties   (with props)
    camel/trunk/components/camel-krati/src/test/resources/producer-test.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
    camel/trunk/platforms/karaf/features/src/main/resources/features.xml

Modified: camel/trunk/apache-camel/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/apache-camel/pom.xml?rev=1188121&r1=1188120&r2=1188121&view=diff
==============================================================================
--- camel/trunk/apache-camel/pom.xml (original)
+++ camel/trunk/apache-camel/pom.xml Mon Oct 24 12:40:18 2011
@@ -258,7 +258,7 @@
       <exclusions>
          <exclusion>
             <groupId>net.sf.jt400</groupId>
-	    <artifactId>jt400-full</artifactId> 
+            <artifactId>jt400-full</artifactId> 
          </exclusion>
       </exclusions>
     </dependency>
@@ -272,6 +272,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-krati</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-lucene</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=1188121&r1=1188120&r2=1188121&view=diff
==============================================================================
--- camel/trunk/apache-camel/src/main/descriptors/common-bin.xml (original)
+++ camel/trunk/apache-camel/src/main/descriptors/common-bin.xml Mon Oct 24 12:40:18 2011
@@ -89,6 +89,7 @@
         <include>org.apache.camel:camel-juel</include>
         <include>org.apache.camel:camel-jxpath</include>
         <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-lucene</include>
         <include>org.apache.camel:camel-mail</include>

Added: camel/trunk/components/camel-krati/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/pom.xml?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/pom.xml (added)
+++ camel/trunk/components/camel-krati/pom.xml Mon Oct 24 12:40:18 2011
@@ -0,0 +1,83 @@
+<?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">
+    <parent>
+        <artifactId>components</artifactId>
+        <groupId>org.apache.camel</groupId>
+        <version>2.9-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-krati</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: Krati</name>
+    <description>Camel Krati support</description>
+
+    <properties>
+        <camel.osgi.export.pkg>org.apache.camel.component.krati.*</camel.osgi.export.pkg>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.sna-projects.krati</groupId>
+            <artifactId>krati</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+
+        <!-- for testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <!-- logging -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <defaultGoal>install</defaultGoal>
+
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.3.2</version>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

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

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

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

Added: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiComponent.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiComponent.java (added)
+++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiComponent.java Mon Oct 24 12:40:18 2011
@@ -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.krati;
+
+import java.util.Map;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * Represents the component that manages {@link KratiEndpoint}.
+ */
+public class KratiComponent extends DefaultComponent {
+
+    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+        Endpoint endpoint = new KratiEndpoint(uri, this);
+        setProperties(endpoint, parameters);
+        return endpoint;
+    }
+
+}

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

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

Added: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConstants.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConstants.java (added)
+++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConstants.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,48 @@
+/**
+ * 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.krati;
+
+public final class KratiConstants {
+    public static final String KEY = "CamelKratiKey";
+    public static final String VALUE = "CamelKratiValue";
+
+    //Store Types
+    public static final String STORE_TYPE = "STORE_TYPE";
+    public static final String DYNAMIC_STORE = "DYNAMIC_STORE";
+    public static final String INDEXED_STORE = "INDEXED_STORE";
+
+    //Operation Types
+    public static final String KRATI_OPERATION = "CamelKratiOperation";
+    public static final String KRATI_OPERATION_ADD = "CamelKratiAdd";
+    public static final String KRATI_OPERATION_UPDATE = "CamelKratiUpdate";
+    public static final String KRATI_OPERATION_DELETE = "CamelKratiDelete";
+    public static final String KRATI_OPERATION_DELETEALL = "CamelKratiDeleteAll";
+    public static final String KRATI_OPERATION_GET = "CamelKratiGet";
+
+    public static final String KRATI_OPERATION_STATUS = "CamelKratiOperationStatus";
+    public static final String KRATI_OPERATION_SUCESSFUL = "CamelKratiOperationSuccess";
+    public static final String KRATI_OPERATION_FAILURE = "CamelKratiOperationFailure";
+
+    private KratiConstants() {
+        //Utility Class
+    }
+
+
+
+
+}

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

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

Added: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConsumer.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConsumer.java (added)
+++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiConsumer.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,165 @@
+/**
+ * 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.krati;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Queue;
+import krati.store.DataStore;
+import org.apache.camel.BatchConsumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.ShutdownRunningTask;
+import org.apache.camel.impl.ScheduledPollConsumer;
+import org.apache.camel.spi.ShutdownAware;
+import org.apache.camel.spi.Synchronization;
+import org.apache.camel.util.CastUtils;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The Krati consumer.
+ */
+public class KratiConsumer extends ScheduledPollConsumer implements BatchConsumer, ShutdownAware {
+
+    private static final transient Logger LOG = LoggerFactory.getLogger(KratiConsumer.class);
+
+    protected final KratiEndpoint endpoint;
+    protected DataStore dataStore;
+    protected int maxMessagesPerPoll = 10;
+
+    protected volatile ShutdownRunningTask shutdownRunningTask;
+    protected volatile int pendingExchanges;
+
+    public KratiConsumer(KratiEndpoint endpoint, Processor processor, DataStore dataStore) {
+        super(endpoint, processor);
+        this.endpoint = endpoint;
+        this.dataStore = dataStore;
+    }
+
+    @Override
+    protected int poll() throws Exception {
+        shutdownRunningTask = null;
+        pendingExchanges = 0;
+
+        Queue<Exchange> queue = new LinkedList<Exchange>();
+
+        Iterator keyIterator = dataStore.keyIterator();
+        while (keyIterator.hasNext()) {
+            Object key = keyIterator.next();
+            Object value = dataStore.get(key);
+            Exchange exchange = endpoint.createExchange();
+            exchange.setProperty(KratiConstants.KEY, key);
+            exchange.getIn().setBody(value);
+            queue.add(exchange);
+        }
+        return queue.isEmpty() ? 0 : processBatch(CastUtils.cast(queue));
+    }
+
+    /**
+     * Sets a maximum number of messages as a limit to poll at each polling.
+     * <p/>
+     * Can be used to limit eg to 100 to avoid when starting and there are millions
+     * of messages for you in the first poll.
+     * <p/>
+     * Default value is 10.
+     *
+     * @param maxMessagesPerPoll maximum messages to poll.
+     */
+    @Override
+    public void setMaxMessagesPerPoll(int maxMessagesPerPoll) {
+        this.maxMessagesPerPoll = maxMessagesPerPoll;
+    }
+
+    @Override
+    public int processBatch(Queue<Object> exchanges) throws Exception {
+        int total = exchanges.size();
+
+        for (int index = 0; index < total && isBatchAllowed(); index++) {
+            // only loop if we are started (allowed to run)
+            Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll());
+            // add current index and total as properties
+            exchange.setProperty(Exchange.BATCH_INDEX, index);
+            exchange.setProperty(Exchange.BATCH_SIZE, total);
+            exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1);
+
+            // update pending number of exchanges
+            pendingExchanges = total - index - 1;
+
+            // add on completion to handle after work when the exchange is done
+            exchange.addOnCompletion(new Synchronization() {
+                public void onComplete(Exchange exchange) {
+                    try {
+                        dataStore.delete(exchange.getProperty(KratiConstants.KEY));
+                    } catch (Exception e) {
+                        LOG.warn("Failed to remove from datastore.", e);
+                    }
+                }
+
+                public void onFailure(Exchange exchange) {
+                  //emtpy
+                }
+            });
+
+            LOG.trace("Processing exchange [{}]...", exchange);
+            getProcessor().process(exchange);
+        }
+
+        return total;
+    }
+
+    @Override
+    public boolean isBatchAllowed() {
+        // stop if we are not running
+        boolean answer = isRunAllowed();
+        if (!answer) {
+            return false;
+        }
+
+        if (shutdownRunningTask == null) {
+            // we are not shutting down so continue to run
+            return true;
+        }
+
+        // we are shutting down so only continue if we are configured to complete all tasks
+        return ShutdownRunningTask.CompleteAllTasks == shutdownRunningTask;
+    }
+
+    @Override
+    public boolean deferShutdown(ShutdownRunningTask shutdownRunningTask) {
+        // store a reference what to do in case when shutting down and we have pending messages
+        this.shutdownRunningTask = shutdownRunningTask;
+        // do not defer shutdown
+        return false;
+    }
+
+    @Override
+    public int getPendingExchangesSize() {
+        // only return the real pending size in case we are configured to complete all tasks
+        if (ShutdownRunningTask.CompleteAllTasks == shutdownRunningTask) {
+            return pendingExchanges;
+        } else {
+            return 0;
+        }
+    }
+
+    @Override
+    public void prepareShutdown() {
+    }
+}

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

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

Added: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiDataStoreRegistration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiDataStoreRegistration.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiDataStoreRegistration.java (added)
+++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiDataStoreRegistration.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,57 @@
+/**
+ * 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.krati;
+
+import java.io.IOException;
+import krati.store.DataStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KratiDataStoreRegistration {
+
+    private static final transient Logger LOG = LoggerFactory.getLogger(KratiDataStoreRegistration.class);
+
+    private final DataStore dataStore;
+    private int registrationCount;
+
+    public KratiDataStoreRegistration(DataStore dataStore) {
+        this.dataStore = dataStore;
+    }
+
+    public int register() {
+        return ++registrationCount;
+    }
+
+    public boolean unregister() {
+        if (--registrationCount <= 0) {
+            try {
+                dataStore.close();
+            } catch (IOException e) {
+                LOG.warn("Error while closing datastore.", e);
+            }
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public DataStore getDataStore() {
+        register();
+        return dataStore;
+    }
+}

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

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

Added: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiEndpoint.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiEndpoint.java (added)
+++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiEndpoint.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,186 @@
+/**
+ * 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.krati;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+import krati.core.segment.ChannelSegmentFactory;
+import krati.core.segment.SegmentFactory;
+import krati.io.Serializer;
+import krati.store.DataStore;
+import krati.util.FnvHashFunction;
+import krati.util.HashFunction;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.krati.serializer.KratiDefaultSerializer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Represents a Krati endpoint.
+ */
+public class KratiEndpoint extends DefaultEndpoint {
+
+    protected static Map<String, KratiDataStoreRegistration> dataStoreRegistry = new HashMap<String, KratiDataStoreRegistration>();
+
+    protected String key;
+    protected String value;
+    protected String operation;
+
+    protected int initialCapacity = 100;
+    protected int segmentFileSize = 64;
+    protected Serializer keySerializer = new KratiDefaultSerializer();
+    protected Serializer valueSerializer = new KratiDefaultSerializer();
+    protected SegmentFactory segmentFactory = new ChannelSegmentFactory();
+    protected HashFunction hashFunction = new FnvHashFunction();
+
+    protected String path;
+
+    public KratiEndpoint(String uri, KratiComponent component) throws URISyntaxException {
+        super(uri, component);
+        this.path = getPath(uri);
+    }
+
+    public KratiEndpoint(String endpointUri) throws URISyntaxException {
+        super(endpointUri);
+        this.path = getPath(endpointUri);
+    }
+
+    @Override
+    public void stop() throws Exception {
+        super.stop();
+        KratiDataStoreRegistration registration = dataStoreRegistry.get(path);
+        if (registration != null) {
+            registration.unregister();
+        }
+    }
+
+    public Producer createProducer() throws Exception {
+        DataStore dataStore = null;
+        KratiDataStoreRegistration registration = dataStoreRegistry.get(path);
+        if (registration != null) {
+            dataStore = registration.getDataStore();
+        }
+        if (dataStore == null || !dataStore.isOpen()) {
+            dataStore = KratiHelper.createDataStore(path, initialCapacity, segmentFileSize, segmentFactory, hashFunction, keySerializer, valueSerializer);
+            dataStoreRegistry.put(path, new KratiDataStoreRegistration(dataStore));
+        }
+        return new KratiProducer(this, dataStore);
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        DataStore dataStore = null;
+        KratiDataStoreRegistration registration = dataStoreRegistry.get(path);
+        if (registration != null) {
+            dataStore = registration.getDataStore();
+        }
+        if (dataStore == null || !dataStore.isOpen()) {
+            dataStore = KratiHelper.createDataStore(path, initialCapacity, segmentFileSize, segmentFactory, hashFunction, keySerializer, valueSerializer);
+            dataStoreRegistry.put(path, new KratiDataStoreRegistration(dataStore));
+        }
+        return new KratiConsumer(this, processor, dataStore);
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+
+
+    /**
+     * Returns the path from the URI.
+     *
+     * @param uri
+     * @return
+     */
+    protected String getPath(String uri) throws URISyntaxException {
+        URI u = new URI(uri);
+        StringBuilder pathBuilder = new StringBuilder();
+        if (u.getHost() != null) {
+            pathBuilder.append(u.getHost());
+        }
+        if (u.getPath() != null) {
+            pathBuilder.append(u.getPath());
+        }
+        return pathBuilder.toString();
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public String getOperation() {
+        return operation;
+    }
+
+    public void setOperation(String operation) {
+        this.operation = operation;
+    }
+
+    public int getInitialCapacity() {
+        return initialCapacity;
+    }
+
+    public void setInitialCapacity(int initialCapacity) {
+        this.initialCapacity = initialCapacity;
+    }
+
+    public int getSegmentFileSize() {
+        return segmentFileSize;
+    }
+
+    public void setSegmentFileSize(int segmentFileSize) {
+        this.segmentFileSize = segmentFileSize;
+    }
+
+    public SegmentFactory getSegmentFactory() {
+        return segmentFactory;
+    }
+
+    public void setSegmentFactory(SegmentFactory segmentFactory) {
+        this.segmentFactory = segmentFactory;
+    }
+
+    public HashFunction getHashFunction() {
+        return hashFunction;
+    }
+
+    public void setHashFunction(HashFunction hashFunction) {
+        this.hashFunction = hashFunction;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+
+}

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

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

Added: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiHelper.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiHelper.java (added)
+++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiHelper.java Mon Oct 24 12:40:18 2011
@@ -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.krati;
+
+import java.io.File;
+import krati.core.StoreConfig;
+import krati.core.segment.SegmentFactory;
+import krati.io.Serializer;
+import krati.sos.SerializableObjectStore;
+import krati.store.DataSet;
+import krati.store.DataStore;
+import krati.store.DynamicDataSet;
+import krati.store.DynamicDataStore;
+import krati.util.HashFunction;
+import org.apache.camel.RuntimeCamelException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class KratiHelper {
+
+    private static final transient Logger LOG = LoggerFactory.getLogger(KratiHelper.class);
+
+    private KratiHelper() {
+        //Utillity Class
+    }
+
+    /**
+     * Creates a {@link krati.sos.SerializableObjectStore} with the given parameters.
+     *
+     * @param path            The directory which the store will use.
+     * @param initialCapacity
+     * @param segmentFileSize
+     * @param segmentFactory  The segment factory, defaults to {@link krati.core.segment.ChannelSegmentFactory}.
+     * @param hashFunction    The hash function, defaults to {@link krati.util.FnvHashFunction}.
+     * @param keySerializer   The serializer used for keys, defaults to {@link org.apache.camel.component.krati.serializer.KratiDefaultSerializer}.
+     * @param valueSerializer The serializer used for values,defaults to {@link org.apache.camel.component.krati.serializer.KratiDefaultSerializer}.
+     * @return
+     */
+    public static DataStore createDataStore(String path, int initialCapacity, int segmentFileSize, SegmentFactory segmentFactory,
+                                            HashFunction hashFunction, Serializer keySerializer, Serializer valueSerializer) {
+        DataStore result = null;
+        File homeDir = new File(path);
+        homeDir.mkdirs();
+        try {
+            StoreConfig storeConfig = new StoreConfig(homeDir, initialCapacity);
+            storeConfig.setSegmentFactory(segmentFactory);
+            storeConfig.setHashFunction(hashFunction);
+            storeConfig.setSegmentFileSizeMB(segmentFileSize);
+            DataStore dynamicDataStore = new DynamicDataStore(storeConfig);
+            result = new SerializableObjectStore(dynamicDataStore, keySerializer, valueSerializer);
+        } catch (Exception e) {
+            throw new RuntimeCamelException("Failed to create Krati DataStore.", e);
+        }
+        return result;
+    }
+
+
+    /**
+     * Creates a {@link krati.store.DynamicDataSet} with the given parameters.
+     *
+     * @param path            The directory which the set will use.
+     * @param initialCapacity
+     * @param segmentFactory  The segment factory, defaults to {@link krati.core.segment.ChannelSegmentFactory}.
+     * @return
+     */
+    public static DataSet createDataSet(String path, int initialCapacity, SegmentFactory segmentFactory) {
+        DataSet result = null;
+        File homeDir = new File(path);
+        homeDir.mkdirs();
+        try {
+            result = new DynamicDataSet(homeDir, initialCapacity, segmentFactory);
+        } catch (Exception e) {
+            throw new RuntimeCamelException("Failed to create Krati DataSet.", e);
+        }
+        return result;
+    }
+}

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

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

Added: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java (added)
+++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,125 @@
+/**
+ * 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.krati;
+
+import krati.store.DataStore;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Krati producer.
+ */
+public class KratiProducer extends DefaultProducer {
+    private static final transient Logger LOG = LoggerFactory.getLogger(KratiProducer.class);
+
+    protected KratiEndpoint endpoint;
+    protected DataStore dataStore;
+
+    public KratiProducer(KratiEndpoint endpoint, DataStore dataStore) {
+        super(endpoint);
+        this.endpoint = endpoint;
+        this.dataStore = dataStore;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        String operation = getOperation(exchange);
+        String key = getKey(exchange);
+
+        LOG.trace("Processing {} operation on '[{}]'", operation, exchange);
+        if (KratiConstants.KRATI_OPERATION_GET.equals(operation) && key != null) {
+            exchange.getOut().setBody(dataStore.get(key));
+        } else if (KratiConstants.KRATI_OPERATION_DELETE.equals(operation) && key != null) {
+            boolean status;
+            synchronized (dataStore) {
+                status = dataStore.delete(key);
+                dataStore.persist();
+            }
+            if (status) {
+                exchange.getOut().setHeader(KratiConstants.KRATI_OPERATION_STATUS, KratiConstants.KRATI_OPERATION_SUCESSFUL);
+            } else {
+                exchange.getOut().setHeader(KratiConstants.KRATI_OPERATION_STATUS, KratiConstants.KRATI_OPERATION_FAILURE);
+            }
+        } else if (KratiConstants.KRATI_OPERATION_DELETEALL.equals(operation)) {
+            try {
+                dataStore.clear();
+                exchange.getOut().setHeader(KratiConstants.KRATI_OPERATION_STATUS, KratiConstants.KRATI_OPERATION_SUCESSFUL);
+            } catch (Exception e) {
+                LOG.warn("Error clearing all entries from store", e);
+                exchange.getOut().setHeader(KratiConstants.KRATI_OPERATION_STATUS, KratiConstants.KRATI_OPERATION_FAILURE);
+            }
+        } else {
+            Object value = getValue(exchange);
+            //Its required to have only one thread putting stuff there at any given time per store.
+            synchronized (endpoint.getPath().intern()) {
+                dataStore.put(key, value);
+            }
+        }
+    }
+
+    /**
+     * Retrieves the operation from the URI or from the exchange headers. The header will take precedence over the URI.
+     *
+     * @param exchange
+     * @return
+     */
+    public String getOperation(Exchange exchange) {
+        String operation = ((KratiEndpoint) getEndpoint()).getOperation();
+
+        if (exchange.getIn().getHeader(KratiConstants.KRATI_OPERATION) != null) {
+            operation = (String) exchange.getIn().getHeader(KratiConstants.KRATI_OPERATION);
+        }
+        return operation;
+    }
+
+
+    /**
+     * Retrieves the key from the URI or from the exchange headers. The header will take precedence over the URI.
+     *
+     * @param exchange
+     * @return
+     */
+    public String getKey(Exchange exchange) {
+        String key = ((KratiEndpoint) getEndpoint()).getKey();
+
+        if (exchange.getIn().getHeader(KratiConstants.KEY) != null) {
+            key = (String) exchange.getIn().getHeader(KratiConstants.KEY);
+        }
+        return key;
+    }
+
+    /**
+     * Retrieves the value from the URI or from the exchange headers/body. The header/body will take precedence over the URI.
+     *
+     * @param exchange
+     * @return
+     */
+    public Object getValue(Exchange exchange) {
+        Object value = ((KratiEndpoint) getEndpoint()).getValue();
+
+        if (exchange.getIn().getHeader(KratiConstants.VALUE) != null) {
+            value = (String) exchange.getIn().getHeader(KratiConstants.VALUE);
+        }
+
+        if (exchange.getIn().getBody() != null) {
+            value = exchange.getIn().getBody();
+        }
+        return value;
+    }
+
+}

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

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

Added: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/processor/idempotent/KratiIdempotentRepository.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/processor/idempotent/KratiIdempotentRepository.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/processor/idempotent/KratiIdempotentRepository.java (added)
+++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/processor/idempotent/KratiIdempotentRepository.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,148 @@
+/**
+ * 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.krati.processor.idempotent;
+
+import krati.core.segment.ChannelSegmentFactory;
+import krati.core.segment.SegmentFactory;
+import krati.io.Serializer;
+import krati.store.DataSet;
+import org.apache.camel.api.management.ManagedOperation;
+import org.apache.camel.component.krati.KratiHelper;
+import org.apache.camel.component.krati.serializer.KratiDefaultSerializer;
+import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.support.ServiceSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KratiIdempotentRepository extends ServiceSupport implements IdempotentRepository<String> {
+
+    private static final transient Logger LOG = LoggerFactory.getLogger(KratiHelper.class);
+
+    private String repositoryPath;
+
+    private DataSet dataSet;
+    private int initialCapacity = 100;
+    private Serializer serializer = new KratiDefaultSerializer();
+    private SegmentFactory segmentFactory = new ChannelSegmentFactory();
+
+    public KratiIdempotentRepository(String repositoryPath) {
+        this.repositoryPath = repositoryPath;
+
+    }
+
+    @Override
+    @ManagedOperation(description = "Adds the key to the store")
+    public boolean add(String s) {
+        byte[] bytes = serializer.serialize(s);
+        try {
+            synchronized (dataSet) {
+                if (dataSet.has(bytes)) {
+                    return false;
+                } else {
+                    return dataSet.add(serializer.serialize(s));
+                }
+
+            }
+        } catch (Exception e) {
+            LOG.warn("Error adding item to krati idempotent repository. This exception is ignored.", e);
+            return false;
+        }
+    }
+
+    @Override
+    @ManagedOperation(description = "Does the store contain the given key")
+    public boolean contains(String s) {
+        byte[] bytes = serializer.serialize(s);
+        try {
+            return dataSet.has(bytes);
+        } catch (Exception e) {
+            LOG.warn("Error adding item to krati idempotent repository. This exception is ignored.", e);
+            return false;
+        }
+    }
+
+    @Override
+    @ManagedOperation(description = "Does the store contain the given key")
+    public boolean remove(String s) {
+        byte[] bytes = serializer.serialize(s);
+        try {
+            return dataSet.delete(bytes);
+        } catch (Exception e) {
+            LOG.warn("Error adding item to krati idempotent repository. This exception is ignored.", e);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean confirm(String s) {
+        return true;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        if (dataSet == null) {
+            this.dataSet = KratiHelper.createDataSet(repositoryPath, initialCapacity, segmentFactory);
+        }
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        if (dataSet != null && dataSet.isOpen()) {
+            this.dataSet.close();
+        }
+    }
+
+    public String getRepositoryPath() {
+        return repositoryPath;
+    }
+
+    public void setRepositoryPath(String repositoryPath) {
+        this.repositoryPath = repositoryPath;
+    }
+
+    public DataSet getDataSet() {
+        return dataSet;
+    }
+
+    public void setDataSet(DataSet dataSet) {
+        this.dataSet = dataSet;
+    }
+
+    public int getInitialCapacity() {
+        return initialCapacity;
+    }
+
+    public void setInitialCapacity(int initialCapacity) {
+        this.initialCapacity = initialCapacity;
+    }
+
+    public Serializer getSerializer() {
+        return serializer;
+    }
+
+    public void setSerializer(Serializer serializer) {
+        this.serializer = serializer;
+    }
+
+    public SegmentFactory getSegmentFactory() {
+        return segmentFactory;
+    }
+
+    public void setSegmentFactory(SegmentFactory segmentFactory) {
+        this.segmentFactory = segmentFactory;
+    }
+}

Propchange: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/processor/idempotent/KratiIdempotentRepository.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/processor/idempotent/KratiIdempotentRepository.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/serializer/KratiDefaultSerializer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/serializer/KratiDefaultSerializer.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/serializer/KratiDefaultSerializer.java (added)
+++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/serializer/KratiDefaultSerializer.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,104 @@
+/**
+ * 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.krati.serializer;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.Serializable;
+import krati.io.SerializationException;
+import krati.io.Serializer;
+import org.apache.camel.util.IOHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KratiDefaultSerializer<T extends Serializable> implements Serializer<T> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(KratiDefaultSerializer.class);
+
+    /**
+     * Serialize an object into a byte array.
+     *
+     * @param object - an object to be serialized by this Serializer.
+     * @return a byte array which is the raw representation of an object.
+     */
+    public byte[] serialize(T object) throws SerializationException {
+        byte[] result = null;
+
+        if (object == null) {
+            return null;
+        }
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = null;
+        try {
+            oos = new ObjectOutputStream(baos);
+            oos.writeObject(object);
+            result = baos.toByteArray();
+        } catch (IOException e) {
+            LOG.warn("Error while serializing object. Null will be used.", e);
+        } finally {
+            IOHelper.close(oos);
+            IOHelper.close(baos);
+        }
+        return result;
+    }
+
+    /**
+     * Deserialize an object from its raw bytes generated by {{@link #serialize(Object)}.
+     *
+     * @param binary - the raw bytes from which an object is constructed.
+     * @return an object constructed from the raw bytes.
+     * @throws SerializationException if the object cannot be constructed from the raw bytes.
+     */
+    public T deserialize(byte[] binary) throws SerializationException {
+        T result = null;
+        ObjectInputStream ois = null;
+
+        if (binary == null) {
+            return null;
+        }
+
+        ByteArrayInputStream bais = new ByteArrayInputStream(binary);
+        final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        try {
+            ois = new ObjectInputStream(bais) {
+                @Override
+                public Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+                    try {
+                        return classLoader.loadClass(desc.getName());
+                    } catch (Exception e) {
+                    }
+                    return super.resolveClass(desc);
+                }
+            };
+            result = (T) ois.readObject();
+        } catch (IOException e) {
+            LOG.warn("Error while deserializing object. Null will be used.", e);
+        } catch (ClassNotFoundException e) {
+            LOG.warn("Could not find class while deserializing object. Null will be used.", e);
+        } finally {
+            IOHelper.close(ois);
+            IOHelper.close(bais);
+        }
+        return result;
+    }
+}

Propchange: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/serializer/KratiDefaultSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/serializer/KratiDefaultSerializer.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-krati/src/main/resources/META-INF/LICENSE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/resources/META-INF/LICENSE.txt?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/resources/META-INF/LICENSE.txt (added)
+++ camel/trunk/components/camel-krati/src/main/resources/META-INF/LICENSE.txt Mon Oct 24 12:40:18 2011
@@ -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-krati/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

Added: camel/trunk/components/camel-krati/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/resources/META-INF/NOTICE.txt?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/resources/META-INF/NOTICE.txt (added)
+++ camel/trunk/components/camel-krati/src/main/resources/META-INF/NOTICE.txt Mon Oct 24 12:40:18 2011
@@ -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-krati/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: camel/trunk/components/camel-krati/src/main/resources/META-INF/services/org/apache/camel/component/krati
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/resources/META-INF/services/org/apache/camel/component/krati?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/main/resources/META-INF/services/org/apache/camel/component/krati (added)
+++ camel/trunk/components/camel-krati/src/main/resources/META-INF/services/org/apache/camel/component/krati Mon Oct 24 12:40:18 2011
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.krati.KratiComponent

Added: camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerSpringTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerSpringTest.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerSpringTest.java (added)
+++ camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerSpringTest.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,45 @@
+/**
+ * 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.krati;
+
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class KratiConsumerSpringTest extends CamelSpringTestSupport {
+
+    @Test
+    public void testPutAndConsume() throws InterruptedException {
+        ProducerTemplate template = context.createProducerTemplate();
+        template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1");
+        template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2");
+        template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3");
+        MockEndpoint endpoint = (MockEndpoint) context.getEndpoint("mock:results");
+        endpoint.expectedMessageCount(3);
+        endpoint.assertIsSatisfied();
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("classpath:producer-test.xml");
+    }
+
+}

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

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

Added: camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerTest.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerTest.java (added)
+++ camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiConsumerTest.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,51 @@
+/**
+ * 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.krati;
+
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class KratiConsumerTest extends CamelTestSupport {
+
+    @Test
+    public void testPutAndConsume() throws InterruptedException {
+        ProducerTemplate template = context.createProducerTemplate();
+        template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1");
+        template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2");
+        template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3");
+        MockEndpoint endpoint = (MockEndpoint) context.getEndpoint("mock:results");
+        endpoint.expectedMessageCount(3);
+        endpoint.assertIsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:put")
+                        .to("krati:target/test/consumertest");
+                from("krati:target/test/consumertest")
+                        .to("mock:results");
+
+            }
+        };
+    }
+}

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

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

Added: camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiEndpointTest.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiEndpointTest.java (added)
+++ camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiEndpointTest.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,47 @@
+/**
+ * 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.krati;
+
+import org.junit.Test;
+
+
+import static org.junit.Assert.assertEquals;
+
+public class KratiEndpointTest {
+
+    @Test
+    public void testCreateEndpointWithRelativePath() throws Exception {
+        String uri = "krati://target/test/endpointtest?initialCapacity=10000";
+        KratiComponent component = new KratiComponent();
+        KratiEndpoint endpoint = new KratiEndpoint(uri, component);
+        endpoint.start();
+        endpoint.stop();
+        assertEquals("target/test/endpointtest", endpoint.getPath());
+
+    }
+
+    @Test
+    public void testCreateEndpointWithAbsolutePath() throws Exception {
+        String uri = "krati:///tmp/target/test/endpointtest?initialCapacity=10000";
+        KratiComponent component = new KratiComponent();
+        KratiEndpoint endpoint = new KratiEndpoint(uri, component);
+        endpoint.start();
+        endpoint.stop();
+        assertEquals("/tmp/target/test/endpointtest", endpoint.getPath());
+    }
+}

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

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

Added: camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerSpringTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerSpringTest.java?rev=1188121&view=auto
==============================================================================
--- camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerSpringTest.java (added)
+++ camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerSpringTest.java Mon Oct 24 12:40:18 2011
@@ -0,0 +1,86 @@
+/**
+ * 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.krati;
+
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class KratiProducerSpringTest extends CamelSpringTestSupport {
+
+    @Test
+    public void testPut() throws InterruptedException {
+        ProducerTemplate template = context.createProducerTemplate();
+        template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1");
+        template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2");
+        template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3");
+        MockEndpoint endpoint = (MockEndpoint) context.getEndpoint("mock:results");
+        endpoint.expectedMessageCount(3);
+        endpoint.assertIsSatisfied();
+    }
+
+
+    @Test
+    public void testPutAndGet() throws InterruptedException {
+        ProducerTemplate template = context.createProducerTemplate();
+        template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1");
+        template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2");
+        template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3");
+
+        MockEndpoint endpoint = (MockEndpoint) context.getEndpoint("mock:results");
+        endpoint.expectedMessageCount(3);
+        endpoint.assertIsSatisfied();
+
+        Object result = template.requestBodyAndHeader("direct:get", null, KratiConstants.KEY, "3");
+        assertEquals("TEST3", result);
+    }
+
+    @Test
+    public void testPutDeleteAndGet() throws InterruptedException {
+        ProducerTemplate template = context.createProducerTemplate();
+        template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1");
+        template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2");
+        template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3");
+        template.requestBodyAndHeader("direct:delete", null, KratiConstants.KEY, "3");
+        Object result = template.requestBodyAndHeader("direct:get", null, KratiConstants.KEY, "3");
+        assertEquals(null, result);
+    }
+
+    @Test
+    public void testPutDeleteAllAndGet() throws InterruptedException {
+        ProducerTemplate template = context.createProducerTemplate();
+        template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1");
+        template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2");
+        template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3");
+        template.requestBodyAndHeader("direct:deleteall", null, KratiConstants.KEY, "3");
+        Object result = template.requestBodyAndHeader("direct:get", null, KratiConstants.KEY, "1");
+        assertEquals(null, result);
+        result = template.requestBodyAndHeader("direct:get", null, KratiConstants.KEY, "2");
+        assertEquals(null, result);
+        result = template.requestBodyAndHeader("direct:get", null, KratiConstants.KEY, "3");
+        assertEquals(null, result);
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("classpath:producer-test.xml");
+    }
+}

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

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