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-6680: Simple langage should be singleton to improve performance on reuse/loop where its used such as bean OGNL expressions.
Date Thu, 29 Aug 2013 09:26:58 GMT
Updated Branches:
  refs/heads/camel-2.11.x 3ea01dfa7 -> 1fd52ef1b
  refs/heads/master 36f362aa0 -> 48c7fc8ec


CAMEL-6680: Simple langage should be singleton to improve performance on reuse/loop where
its used such as bean OGNL expressions.


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

Branch: refs/heads/master
Commit: 48c7fc8ec6ea10cc7f61de0cd30cd2858869e106
Parents: 36f362a
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Aug 29 11:07:38 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Aug 29 11:08:34 2013 +0200

----------------------------------------------------------------------
 .../org/apache/camel/builder/SimpleBuilder.java | 12 ++--
 .../camel/language/simple/FileLanguage.java     |  9 +--
 .../camel/language/simple/SimpleLanguage.java   | 33 ++-------
 .../component/bean/BeanOgnlPerformanceTest.java | 73 ++++++++++++++++++++
 4 files changed, 84 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/48c7fc8e/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java
index 0201d42..0a6861d 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/SimpleBuilder.java
@@ -85,9 +85,6 @@ public class SimpleBuilder implements Predicate, Expression {
 
     private Predicate createPredicate(Exchange exchange) {
         SimpleLanguage simple = (SimpleLanguage) exchange.getContext().resolveLanguage("simple");
-        if (resultType != null) {
-            simple.setResultType(resultType);
-        }
         // resolve property placeholders
         try {
             String resolve = exchange.getContext().resolvePropertyPlaceholders(text);
@@ -99,13 +96,14 @@ public class SimpleBuilder implements Predicate, Expression {
 
     private Expression createExpression(Exchange exchange) {
         SimpleLanguage simple = (SimpleLanguage) exchange.getContext().resolveLanguage("simple");
-        if (resultType != null) {
-            simple.setResultType(resultType);
-        }
         // resolve property placeholders
         try {
             String resolve = exchange.getContext().resolvePropertyPlaceholders(text);
-            return simple.createExpression(resolve);
+            Expression exp = simple.createExpression(resolve);
+            if (resultType != null) {
+                exp = ExpressionBuilder.convertToExpression(exp, resultType);
+            }
+            return exp;
         } catch (Exception e) {
             throw ObjectHelper.wrapCamelExecutionException(exchange, e);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/48c7fc8e/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java b/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java
index af9bedd..ff58663 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/FileLanguage.java
@@ -23,14 +23,7 @@ public class FileLanguage extends SimpleLanguage {
 
     public FileLanguage() {
         // do not allow escaping, as Windows uses \ as path separator
-        setAllowEscape(false);
+        allowEscape = false;
     }
 
-    @Override
-    public void setAllowEscape(boolean allowEscape) {
-        if (allowEscape) {
-            throw new IllegalArgumentException("File language does not allow escape");
-        }
-        this.allowEscape = allowEscape;
-    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/48c7fc8e/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
index 76db93a..b4d0f62 100644
--- a/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
+++ b/camel-core/src/main/java/org/apache/camel/language/simple/SimpleLanguage.java
@@ -93,7 +93,6 @@ public class SimpleLanguage extends LanguageSupport {
     // singleton for expressions without a result type
     private static final SimpleLanguage SIMPLE = new SimpleLanguage();
 
-    protected Class<?> resultType;
     protected boolean allowEscape = true;
 
     /**
@@ -102,28 +101,6 @@ public class SimpleLanguage extends LanguageSupport {
     public SimpleLanguage() {
     }
 
-    public Class<?> getResultType() {
-        return resultType;
-    }
-
-    public void setResultType(Class<?> resultType) {
-        this.resultType = resultType;
-    }
-
-    public boolean isAllowEscape() {
-        return allowEscape;
-    }
-
-    public void setAllowEscape(boolean allowEscape) {
-        this.allowEscape = allowEscape;
-    }
-
-    @Override
-    public boolean isSingleton() {
-        // we cannot be singleton as we have state
-        return false;
-    }
-
     public Predicate createPredicate(String expression) {
         ObjectHelper.notNull(expression, "expression");
 
@@ -153,9 +130,6 @@ public class SimpleLanguage extends LanguageSupport {
             SimpleExpressionParser parser = new SimpleExpressionParser(expression, allowEscape);
             answer = parser.parseExpression();
         }
-        if (resultType != null) {
-            answer = ExpressionBuilder.convertToExpression(answer, resultType);
-        }
         return answer;
     }
 
@@ -175,13 +149,16 @@ public class SimpleLanguage extends LanguageSupport {
      */
     public static Expression simple(String expression, Class<?> resultType) {
         SimpleLanguage answer = new SimpleLanguage();
-        answer.setResultType(resultType);
         if (resultType == Boolean.class || resultType == boolean.class) {
             // if its a boolean as result then its a predicate
             Predicate predicate = answer.createPredicate(expression);
             return PredicateToExpressionAdapter.toExpression(predicate);
         } else {
-            return answer.createExpression(expression);
+            Expression exp = answer.createExpression(expression);
+            if (resultType != null) {
+                exp = ExpressionBuilder.convertToExpression(exp, resultType);
+            }
+            return exp;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/48c7fc8e/camel-core/src/test/java/org/apache/camel/component/bean/BeanOgnlPerformanceTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/BeanOgnlPerformanceTest.java
b/camel-core/src/test/java/org/apache/camel/component/bean/BeanOgnlPerformanceTest.java
new file mode 100644
index 0000000..b539869
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanOgnlPerformanceTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.util.StopWatch;
+
+/**
+ *
+ */
+public class BeanOgnlPerformanceTest extends ContextTestSupport {
+
+    private int size = 1000;
+    private String cache = "true";
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("foo", new MyFooBean());
+        return jndi;
+    }
+
+    public void testBeanOgnlPerformance() throws Exception {
+        StopWatch watch = new StopWatch();
+
+        getMockEndpoint("mock:result").expectedMessageCount(size);
+
+        for (int i = 0; i < size; i++) {
+            template.sendBody("direct:start", "Hello World");
+        }
+
+        assertMockEndpointsSatisfied();
+
+        log.info("Took {} millis", watch.stop());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .toF("bean:foo?cache=%s&method=hello('Camel')", cache)
+                    .to("mock:result");
+            }
+        };
+    }
+}


Mime
View raw message