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 2009/07/14 13:39:09 UTC

svn commit: r793862 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/converter/ camel-core/src/main/java/org/apache/camel/util/ camel-core/src/test/java/org/apache/camel/processor/ components/camel-spring/src/test/resources/org/apache/camel...

Author: davsclaus
Date: Tue Jul 14 11:39:09 2009
New Revision: 793862

URL: http://svn.apache.org/viewvc?rev=793862&view=rev
Log:
MR-216: Performance optimization for recipientList and type converter to String from numeric values.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipeientListWithSimpleExpressionTest.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java?rev=793862&r1=793861&r2=793862&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/ObjectConverter.java Tue Jul 14 11:39:09 2009
@@ -222,4 +222,19 @@
         }
     }
 
+    @Converter
+    public static String toString(Integer value) {
+        return value.toString();
+    }
+
+    @Converter
+    public static String toString(Long value) {
+        return value.toString();
+    }
+
+    @Converter
+    public static String toString(Boolean value) {
+        return value.toString();
+    }
+
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=793862&r1=793861&r2=793862&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java Tue Jul 14 11:39:09 2009
@@ -464,9 +464,33 @@
                 }
             };
         } else if (value instanceof String) {
-            Scanner scanner = new Scanner((String)value);
-            scanner.useDelimiter(delimiter);
-            return scanner;
+            final String s = (String) value;
+
+            // this code is optimized to only use a Scanner if needed, eg there is a delimiter
+
+            if (s.contains(delimiter)) {
+                // use a scanner if it contains the delimtor
+                Scanner scanner = new Scanner((String)value);
+                scanner.useDelimiter(delimiter);
+                return scanner;
+            } else {
+                // use a plain iterator that returns the value as is as there are only a single value
+                return new Iterator<String>() {
+                    int idx = -1;
+
+                    public boolean hasNext() {
+                        return ++idx == 0;
+                    }
+
+                    public String next() {
+                        return s;
+                    }
+
+                    public void remove() {
+                        throw new UnsupportedOperationException();
+                    }
+                };
+            }
         } else {
             return Collections.singletonList(value).iterator();
         }

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipeientListWithSimpleExpressionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipeientListWithSimpleExpressionTest.java?rev=793862&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipeientListWithSimpleExpressionTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipeientListWithSimpleExpressionTest.java Tue Jul 14 11:39:09 2009
@@ -0,0 +1,118 @@
+/**
+ * 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.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Header;
+import org.apache.camel.builder.RouteBuilder;
+import static org.apache.camel.language.simple.SimpleLanguage.simple;
+
+/**
+ * @version $Revision$
+ */
+public class RecipeientListWithSimpleExpressionTest extends ContextTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        disableJMX();
+        super.setUp();
+    }
+
+    public void testRecipientList() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .recipientList(simple("mock:${in.header.queue}"));
+            }
+        });
+        context.start();
+
+        for (int i = 0; i < 10; i++) {
+            getMockEndpoint("mock:" + i).expectedMessageCount(1000);
+        }
+
+        // use concurrent producers to send a lot of messages
+        ExecutorService executors = Executors.newFixedThreadPool(20);
+        for (int i = 0; i < 1000; i++) {
+            executors.execute(new Runnable() {
+                public void run() {
+                    for (int i = 0; i < 10; i++) {
+                        template.sendBodyAndHeader("direct:start", "Hello " + i, "queue", i);
+                    }
+                }
+            });
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public static class MyBeanRouter {
+
+        @org.apache.camel.RecipientList
+        public String route(@Header("queue") String queue) {
+            return "mock:"+ queue;
+        }
+    }
+
+
+    public void testStatic() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:0").to("mock:0");
+                from("direct:1").to("mock:1");
+                from("direct:2").to("mock:2");
+                from("direct:3").to("mock:3");
+                from("direct:4").to("mock:4");
+                from("direct:5").to("mock:5");
+                from("direct:6").to("mock:6");
+                from("direct:7").to("mock:7");
+                from("direct:8").to("mock:8");
+                from("direct:9").to("mock:9");
+            }
+        });
+        context.start();
+
+        for (int i = 0; i < 10; i++) {
+            getMockEndpoint("mock:" + i).expectedMessageCount(1000);
+        }
+
+        // use concurrent producers to send a lot of messages
+        ExecutorService executors = Executors.newFixedThreadPool(20);
+        for (int i = 0; i < 1000; i++) {
+            executors.execute(new Runnable() {
+                public void run() {
+                    for (int i = 0; i < 10; i++) {
+                        template.sendBodyAndHeader("direct:" + i, "Hello " + i, "queue", i);
+                    }
+                }
+            });
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipeientListWithSimpleExpressionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipeientListWithSimpleExpressionTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml?rev=793862&r1=793861&r2=793862&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/multicastAggregator.xml Tue Jul 14 11:39:09 2009
@@ -31,6 +31,7 @@
          <to uri="direct:y"/>
          <to uri="direct:z"/>
       </multicast>
+      <to uri="mock:result"/>
     </route>
 
     <route>
@@ -40,6 +41,7 @@
          <to uri="direct:y"/>
          <to uri="direct:z"/>
       </multicast>
+      <to uri="mock:result"/>
     </route>
 
     <route>