camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-6476: Introducing StreamCachingStrategy SPI to make it easier to configure and allow 3rd party to plugin custom strategies. Work in progress.
Date Wed, 17 Jul 2013 16:43:19 GMT
Updated Branches:
  refs/heads/master d0235489f -> b026ba010


CAMEL-6476: Introducing StreamCachingStrategy SPI to make it easier to configure and allow
3rd party to plugin custom strategies. Work in progress.


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

Branch: refs/heads/master
Commit: 1471c61746f635435e1f8402645a626b4fbecc08
Parents: d023548
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Jul 17 18:17:46 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Jul 17 18:17:46 2013 +0200

----------------------------------------------------------------------
 .../converter/stream/CachedOutputStream.java    |  2 +-
 .../impl/DefaultStreamCachingStrategy.java      | 56 +++++++++++---------
 .../apache/camel/spi/StreamCachingStrategy.java | 14 ++---
 .../stream/CachedOutputStreamTest.java          |  2 +-
 .../processor/SplitterStreamCacheTest.java      |  3 +-
 5 files changed, 42 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1471c617/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
b/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
index 1b7f90b..b25046b 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
@@ -208,7 +208,7 @@ public class CachedOutputStream extends OutputStream {
         flush();
 
         ByteArrayOutputStream bout = (ByteArrayOutputStream)currentStream;
-        tempFile = FileUtil.createTempFile("cos", ".tmp", strategy.getTemporaryDirectory());
+        tempFile = FileUtil.createTempFile("cos", ".tmp", strategy.getSpoolDirectory());
 
         LOG.trace("Creating temporary stream cache file: {}", tempFile);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/1471c617/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
b/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
index d5f558a..d81c244 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultStreamCachingStrategy.java
@@ -47,11 +47,11 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
     private static final Logger LOG = LoggerFactory.getLogger(DefaultStreamCachingStrategy.class);
 
     private CamelContext camelContext;
-    private File temporaryDirectory;
+    private File spoolDirectory;
     private long spoolThreshold = StreamCache.DEFAULT_SPOOL_THRESHOLD;
     private String spoolChiper;
     private int bufferSize = IOHelper.DEFAULT_BUFFER_SIZE;
-    private boolean removeTemporaryDirectoryWhenStopping = true;
+    private boolean removeSpoolDirectoryWhenStopping = true;
 
     public CamelContext getCamelContext() {
         return camelContext;
@@ -61,16 +61,16 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
         this.camelContext = camelContext;
     }
 
-    public void setTemporaryDirectory(String path) {
-        this.temporaryDirectory = new File(path);
+    public void setSpoolDirectory(String path) {
+        this.spoolDirectory = new File(path);
     }
 
-    public void setTemporaryDirectory(File path) {
-        this.temporaryDirectory = path;
+    public void setSpoolDirectory(File path) {
+        this.spoolDirectory = path;
     }
 
-    public File getTemporaryDirectory() {
-        return temporaryDirectory;
+    public File getSpoolDirectory() {
+        return spoolDirectory;
     }
 
     public long getSpoolThreshold() {
@@ -97,12 +97,12 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
         this.bufferSize = bufferSize;
     }
 
-    public boolean isRemoveTemporaryDirectoryWhenStopping() {
-        return removeTemporaryDirectoryWhenStopping;
+    public boolean isRemoveSpoolDirectoryWhenStopping() {
+        return removeSpoolDirectoryWhenStopping;
     }
 
-    public void setRemoveTemporaryDirectoryWhenStopping(boolean removeTemporaryDirectoryWhenStopping)
{
-        this.removeTemporaryDirectoryWhenStopping = removeTemporaryDirectoryWhenStopping;
+    public void setRemoveSpoolDirectoryWhenStopping(boolean removeSpoolDirectoryWhenStopping)
{
+        this.removeSpoolDirectoryWhenStopping = removeSpoolDirectoryWhenStopping;
     }
 
     @Override
@@ -112,32 +112,40 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
         String chiper = camelContext.getProperty(CIPHER_TRANSFORMATION);
         String dir = camelContext.getProperty(TEMP_DIR);
 
+        boolean warn = false;
         if (bufferSize != null) {
+            warn = true;
             this.bufferSize = camelContext.getTypeConverter().convertTo(Integer.class, bufferSize);
         }
         if (hold != null) {
+            warn = true;
             this.spoolThreshold = camelContext.getTypeConverter().convertTo(Long.class, hold);
         }
         if (chiper != null) {
+            warn = true;
             this.spoolChiper = chiper;
         }
         if (dir != null) {
-            this.temporaryDirectory = camelContext.getTypeConverter().convertTo(File.class,
dir);
+            warn = true;
+            this.spoolDirectory = camelContext.getTypeConverter().convertTo(File.class, dir);
+        }
+        if (warn) {
+            LOG.warn("Configuring of StreamCaching using CamelContext properties is deprecated
- use StreamCachingStrategy instead.");
         }
 
         LOG.info("StreamCaching in use with {}", this.toString());
 
         // create random temporary directory if none has been created
-        if (temporaryDirectory == null) {
-            temporaryDirectory = FileUtil.createNewTempDir();
-            LOG.info("Created temporary directory {}", temporaryDirectory);
+        if (spoolDirectory == null) {
+            spoolDirectory = FileUtil.createNewTempDir();
+            LOG.info("Created temporary spool directory {}", spoolDirectory);
         } else {
-            if (!temporaryDirectory.exists()) {
-                boolean created = temporaryDirectory.mkdirs();
+            if (!spoolDirectory.exists()) {
+                boolean created = spoolDirectory.mkdirs();
                 if (!created) {
-                    LOG.warn("Cannot create temporary directory {}", temporaryDirectory);
+                    LOG.warn("Cannot create spool directory {}", spoolDirectory);
                 } else {
-                    LOG.info("Created temporary directory {}", temporaryDirectory);
+                    LOG.info("Created spool directory {}", spoolDirectory);
                 }
             }
         }
@@ -145,16 +153,16 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi
 
     @Override
     protected void doStop() throws Exception {
-        if (temporaryDirectory != null  && isRemoveTemporaryDirectoryWhenStopping())
{
-            LOG.info("Removing temporary directory {}", temporaryDirectory);
-            FileUtil.removeDir(temporaryDirectory);
+        if (spoolDirectory != null  && isRemoveSpoolDirectoryWhenStopping()) {
+            LOG.info("Removing spool directory {}", spoolDirectory);
+            FileUtil.removeDir(spoolDirectory);
         }
     }
 
     @Override
     public String toString() {
         return "DefaultStreamCachingStrategy["
-            + "temporaryDirectory=" + temporaryDirectory
+            + "spoolDirectory=" + spoolDirectory
             + ", spoolThreshold=" + spoolThreshold
             + ", spoolChiper=" + spoolChiper
             + ", bufferSize=" + bufferSize + "]";

http://git-wip-us.apache.org/repos/asf/camel/blob/1471c617/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java b/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
index a5cfa1b..217a0fc 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/StreamCachingStrategy.java
@@ -24,16 +24,16 @@ import java.io.File;
 public interface StreamCachingStrategy {
 
     /**
-     * Sets the temporary directory to use for overflow and spooling to disk.
+     * Sets the spool (temporary) directory to use for overflow and spooling to disk.
      * <p/>
-     * If no temporary directory has been explicit configured, then a directory
+     * If no spool directory has been explicit configured, then a temporary directory
      * is created in the <tt>java.io.tmpdir</tt> directory.
      */
-    void setTemporaryDirectory(File path);
+    void setSpoolDirectory(File path);
 
-    File getTemporaryDirectory();
+    File getSpoolDirectory();
 
-    void setTemporaryDirectory(String path);
+    void setSpoolDirectory(String path);
 
     /**
      * Threshold in bytes when overflow to disk is activated.
@@ -68,8 +68,8 @@ public interface StreamCachingStrategy {
      * <p/>
      * This option is default <tt>true</tt>
      */
-    void setRemoveTemporaryDirectoryWhenStopping(boolean remove);
+    void setRemoveSpoolDirectoryWhenStopping(boolean remove);
 
-    boolean isRemoveTemporaryDirectoryWhenStopping();
+    boolean isRemoveSpoolDirectoryWhenStopping();
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1471c617/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
b/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
index 91729f1..a705e1a 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/stream/CachedOutputStreamTest.java
@@ -43,7 +43,7 @@ public class CachedOutputStreamTest extends ContextTestSupport {
     protected CamelContext createCamelContext() throws Exception {
         CamelContext context = super.createCamelContext();
         context.setStreamCaching(true);
-        context.getStreamCachingStrategy().setTemporaryDirectory("target/cachedir");
+        context.getStreamCachingStrategy().setSpoolDirectory("target/cachedir");
         context.getStreamCachingStrategy().setSpoolThreshold(16);
         return context;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/1471c617/camel-core/src/test/java/org/apache/camel/processor/SplitterStreamCacheTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/SplitterStreamCacheTest.java
b/camel-core/src/test/java/org/apache/camel/processor/SplitterStreamCacheTest.java
index d17410e..f223730 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/SplitterStreamCacheTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/SplitterStreamCacheTest.java
@@ -23,7 +23,6 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.builder.xml.XPathBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.stream.CachedOutputStream;
 
 /**
  * @version 
@@ -48,7 +47,7 @@ public class SplitterStreamCacheTest extends ContextTestSupport {
         return new RouteBuilder() {
             public void configure() {
                 //ensure stream is spooled to disk
-                context.getStreamCachingStrategy().setTemporaryDirectory("target/tmp");
+                context.getStreamCachingStrategy().setSpoolDirectory("target/tmp");
                 context.getStreamCachingStrategy().setSpoolThreshold(-1);
 
                 from("seda:parallel?concurrentConsumers=5").streamCaching()


Mime
View raw message