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 2017/06/26 09:09:15 UTC

camel git commit: CAMEL-11450: Optimise - Calling a bean without method name defined can be optimised

Repository: camel
Updated Branches:
  refs/heads/master b612a50bc -> ab6327dbf


CAMEL-11450: Optimise - Calling a bean without method name defined can be optimised


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

Branch: refs/heads/master
Commit: ab6327dbf5e25724ec7ed722a356dacdba717c20
Parents: b612a50
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 26 11:08:59 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Jun 26 11:09:08 2017 +0200

----------------------------------------------------------------------
 .../component/bean/AbstractBeanProcessor.java      | 17 ++++++++++++-----
 .../bean/issues/BeanRouteToDerivedClassTest.java   |  8 ++++++++
 2 files changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ab6327db/camel-core/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java b/camel-core/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
index 88d78c7..02425d7 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
@@ -38,11 +38,14 @@ public abstract class AbstractBeanProcessor implements AsyncProcessor {
     private static final Logger LOG = LoggerFactory.getLogger(AbstractBeanProcessor.class);
 
     private final BeanHolder beanHolder;
-    private Processor processor;
+    private transient Processor processor;
+    private transient boolean lookupProcessorDone;
+    private final Object lock = new Object();
     private boolean multiParameterArray;
     private String method;
     private boolean shorthandMethod;
 
+
     public AbstractBeanProcessor(Object pojo, BeanInfo beanInfo) {
         this(new ConstantBeanHolder(pojo, beanInfo));
     }
@@ -91,10 +94,14 @@ public abstract class AbstractBeanProcessor implements AsyncProcessor {
         // do we have a custom adapter for this POJO to a Processor
         // but only do this if allowed
         if (allowProcessor(explicitMethodName, beanInfo)) {
-            Processor processor = getProcessor();
-            if (processor == null) {
-                // so if there is a custom type converter for the bean to processor
-                processor = exchange.getContext().getTypeConverter().tryConvertTo(Processor.class, exchange, bean);
+            processor = getProcessor();
+            if (processor == null && !lookupProcessorDone) {
+                // only attempt to lookup the processor once or nearly once
+                synchronized (lock) {
+                    lookupProcessorDone = true;
+                    // so if there is a custom type converter for the bean to processor
+                    processor = exchange.getContext().getTypeConverter().tryConvertTo(Processor.class, exchange, bean);
+                }
             }
             if (processor != null) {
                 LOG.trace("Using a custom adapter as bean invocation: {}", processor);

http://git-wip-us.apache.org/repos/asf/camel/blob/ab6327db/camel-core/src/test/java/org/apache/camel/component/bean/issues/BeanRouteToDerivedClassTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/issues/BeanRouteToDerivedClassTest.java b/camel-core/src/test/java/org/apache/camel/component/bean/issues/BeanRouteToDerivedClassTest.java
index dc4235f..9edf224 100644
--- a/camel-core/src/test/java/org/apache/camel/component/bean/issues/BeanRouteToDerivedClassTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/issues/BeanRouteToDerivedClassTest.java
@@ -70,6 +70,10 @@ public class BeanRouteToDerivedClassTest extends ContextTestSupport {
         out = template.requestBody("direct:other", new MyMessage("Hello World"));
         assertEquals("Derived class should NOT have been invoked", null, derived.getAndClearBody());
         assertEquals("Bye World", out.toString());
+
+        out = template.requestBody("direct:other", new MyMessage("Hello Again"));
+        assertEquals("Derived class should NOT have been invoked", null, derived.getAndClearBody());
+        assertEquals("Bye World", out.toString());
     }
     
     public void testDerivedClassCalledWithCustomProcessor() throws Exception {
@@ -96,6 +100,10 @@ public class BeanRouteToDerivedClassTest extends ContextTestSupport {
         out = template.requestBody("direct:other", new MyMessage("Hello World"));
         assertEquals("Derived class should NOT have been invoked", null, derived.getAndClearBody());
         assertEquals("Bye World", out.toString());
+
+        out = template.requestBody("direct:other", new MyMessage("Hello Again"));
+        assertEquals("Derived class should NOT have been invoked", null, derived.getAndClearBody());
+        assertEquals("Bye World", out.toString());
     }
 
     @Override