Updated Branches: refs/heads/master dad558cc8 -> 1278d3762
CAMEL-6476: Introducing StreamCachingStrategy SPI to make it easier to configure and allow 3rd party to plugin custom strategies. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1278d376 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1278d376 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1278d376 Branch: refs/heads/master Commit: 1278d37623534acc535a4a5263a7131f7b4eebb9 Parents: dad558c Author: Claus Ibsen <[email protected]> Authored: Tue Jul 23 16:39:52 2013 +0200 Committer: Claus Ibsen <[email protected]> Committed: Tue Jul 23 16:39:52 2013 +0200 ---------------------------------------------------------------------- .../impl/DefaultStreamCachingStrategy.java | 31 +++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/1278d376/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 347e8ac..ed2b767 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 @@ -154,6 +154,10 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi boolean result = rule.shouldSpoolCache(length); if (!result) { all = false; + if (!anySpoolRules) { + // no need to check anymore + break; + } } else { any = true; if (anySpoolRules) { @@ -162,7 +166,10 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi } } } - return anySpoolRules ? any : all; + + boolean answer = anySpoolRules ? any : all; + LOG.debug("Should spool cache {} -> {}", length, answer); + return answer; } public void addSpoolRule(SpoolRule rule) { @@ -326,7 +333,7 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi public boolean shouldSpoolCache(long length) { if (spoolThreshold > 0 && length > spoolThreshold) { - LOG.trace("Should spool cache {} > {} -> true", length, spoolThreshold); + LOG.trace("Should spool cache fixed threshold {} > {} -> true", length, spoolThreshold); return true; } return false; @@ -351,12 +358,20 @@ public class DefaultStreamCachingStrategy extends org.apache.camel.support.Servi public boolean shouldSpoolCache(long length) { if (spoolUsedHeapMemoryThreshold > 0) { - long used = heapUsage.getHeapMemoryUsage().getUsed(); - long committed = heapUsage.getHeapMemoryUsage().getCommitted(); - long percentage = committed / used * 100; - LOG.trace("Heap memory: [used=%sK (%sK\\%), committed=%sK]", new Object[]{used >> 10, percentage, committed >> 10}); - if (percentage >= spoolUsedHeapMemoryThreshold) { - LOG.trace("Should spool cache {} > {} -> true", percentage, spoolUsedHeapMemoryThreshold); + // must use double to calculate with decimals for the percentage + double used = heapUsage.getHeapMemoryUsage().getUsed(); + double committed = heapUsage.getHeapMemoryUsage().getCommitted(); + double calc = (used / committed) * 100; + int percentage = (int) calc; + + if (LOG.isTraceEnabled()) { + long u = heapUsage.getHeapMemoryUsage().getUsed(); + long c = heapUsage.getHeapMemoryUsage().getCommitted(); + LOG.trace("Heap memory: [used={}M ({}%), committed={}M]", new Object[]{u >> 20, percentage, c >> 20}); + } + + if (percentage > spoolUsedHeapMemoryThreshold) { + LOG.trace("Should spool cache heap memory threshold {} > {} -> true", percentage, spoolUsedHeapMemoryThreshold); return true; } }
