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 2013/06/03 08:20:26 UTC

[8/8] git commit: CAMEL-6190: Log a INFO when Camel is starting if StreamCaching is enabled and what the limit is for spooling to disk.

CAMEL-6190: Log a INFO when Camel is starting if StreamCaching is enabled and what the limit is for spooling to disk.


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

Branch: refs/heads/master
Commit: f55cf593d93cfb4f8316f327d4e9c5b5f8814715
Parents: a635588
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 3 08:19:42 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jun 3 08:19:42 2013 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/camel/StreamCache.java    |    2 +
 .../camel/converter/stream/CachedOutputStream.java |   11 ++-
 .../org/apache/camel/impl/DefaultCamelContext.java |   20 ++++++
 .../processor/StreamCachingOnlyRouteTest.java      |   53 +++++++++++++++
 4 files changed, 82 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f55cf593/camel-core/src/main/java/org/apache/camel/StreamCache.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/StreamCache.java b/camel-core/src/main/java/org/apache/camel/StreamCache.java
index 2b66563..615ad5b 100644
--- a/camel-core/src/main/java/org/apache/camel/StreamCache.java
+++ b/camel-core/src/main/java/org/apache/camel/StreamCache.java
@@ -30,6 +30,8 @@ import java.io.OutputStream;
  */
 public interface StreamCache {
 
+    public static final long DEFAULT_SPOOL_THRESHOLD = 128 * 1024;
+
     /**
      * Resets the StreamCache for a new stream consumption.
      */

http://git-wip-us.apache.org/repos/asf/camel/blob/f55cf593/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 c59a040..4951c90 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
@@ -39,9 +39,12 @@ import org.slf4j.LoggerFactory;
 
 /**
  * This output stream will store the content into a File if the stream context size is exceed the
- * THRESHOLD which's default value is 64K. The temp file will store in the temp directory, you 
- * can configure it by setting the TEMP_DIR property. If you don't set the TEMP_DIR property,
- * it will choose the directory which is set by the system property of "java.io.tmpdir".
+ * THRESHOLD which's default value is {@link StreamCache#DEFAULT_SPOOL_THRESHOLD} bytes .
+ * <p/>
+ * The temp file will store in the temp directory, you can configure it by setting the TEMP_DIR property.
+ * If you don't set the TEMP_DIR property, it will choose the directory which is set by the
+ * system property of "java.io.tmpdir".
+ * <p/>
  * You can get a cached input stream of this stream. The temp file which is created with this 
  * output stream will be deleted when you close this output stream or the all cached 
  * fileInputStream is closed after the exchange is completed.
@@ -59,7 +62,7 @@ public class CachedOutputStream extends OutputStream {
     private File tempFile;
     private FileInputStreamCache fileInputStreamCache;
 
-    private long threshold = 64 * 1024;
+    private long threshold = StreamCache.DEFAULT_SPOOL_THRESHOLD;
     private int bufferSize = 2 * 1024;
     private File outputDir;
     private String cipherTransformation;

http://git-wip-us.apache.org/repos/asf/camel/blob/f55cf593/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 62a03ed..ecee677 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -64,6 +64,7 @@ import org.apache.camel.ShutdownRoute;
 import org.apache.camel.ShutdownRunningTask;
 import org.apache.camel.StartupListener;
 import org.apache.camel.StatefulService;
+import org.apache.camel.StreamCache;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.VetoCamelContextStartException;
@@ -1642,6 +1643,25 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         // start the route definitions before the routes is started
         startRouteDefinitions(routeDefinitions);
 
+        // is there any stream caching enabled then log an info about this and its limit of spooling to disk, so people is aware of this
+        boolean streamCachingInUse = isStreamCaching();
+        if (!streamCachingInUse) {
+            for (RouteDefinition route : routeDefinitions) {
+                StreamCaching cache = StreamCaching.getStreamCaching(route.getInterceptStrategies());
+                if (cache != null) {
+                    streamCachingInUse = true;
+                    break;
+                }
+            }
+        }
+        if (streamCachingInUse) {
+            Long threshold = CamelContextHelper.convertTo(this, Long.class, getProperties().get("CamelCachedOutputStreamThreshold"));
+            if (threshold == null) {
+                threshold = StreamCache.DEFAULT_SPOOL_THRESHOLD;
+            }
+            log.info("Stream caching is enabled, and using {} kb as threshold for overflow and spooling to disk store.", threshold / 1024);
+        }
+
         // start routes
         if (doNotStartRoutesOnFirstStart) {
             log.debug("Skip starting of routes as CamelContext has been configured with autoStartup=false");

http://git-wip-us.apache.org/repos/asf/camel/blob/f55cf593/camel-core/src/test/java/org/apache/camel/processor/StreamCachingOnlyRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/StreamCachingOnlyRouteTest.java b/camel-core/src/test/java/org/apache/camel/processor/StreamCachingOnlyRouteTest.java
new file mode 100644
index 0000000..8fff9b5
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/StreamCachingOnlyRouteTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.processor;
+
+import java.io.StringReader;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version 
+ */
+public class StreamCachingOnlyRouteTest extends ContextTestSupport {
+
+    public void testStreamCachingPerRoute() throws Exception {
+        MockEndpoint c = getMockEndpoint("mock:c");
+        c.expectedMessageCount(1);
+
+        new StreamSource(new StringReader("A"));
+
+        template.sendBody("direct:c", new StreamSource(new StringReader("C")));
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                getContext().getProperties().put("CamelCachedOutputStreamThreshold", "4096");
+
+                from("direct:c").streamCaching().to("mock:c");
+            }
+        };
+    }
+}
\ No newline at end of file