You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2011/06/11 03:45:11 UTC

svn commit: r1134501 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/processor/ camel-core/src/test/java/org/apache/camel/management/ componen...

Author: hadrian
Date: Sat Jun 11 01:45:11 2011
New Revision: 1134501

URL: http://svn.apache.org/viewvc?rev=1134501&view=rev
Log:
CAMEL-4044. JMX mbean registration for choice() fixed. Thanks to Dan Kulp for the patch

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java?rev=1134501&r1=1134500&r2=1134501&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java Sat Jun 11 01:45:11 2011
@@ -238,6 +238,7 @@ public class RouteService extends Servic
 
     protected void startChildService(Route route, List<Service> services) throws Exception {
         for (Service service : services) {
+            LOG.debug("Starting {}", service);
             for (LifecycleStrategy strategy : camelContext.getLifecycleStrategies()) {
                 strategy.onServiceAdd(camelContext, service, route);
             }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java?rev=1134501&r1=1134500&r2=1134501&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java Sat Jun 11 01:45:11 2011
@@ -16,9 +16,11 @@
  */
 package org.apache.camel.model;
 
+import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
@@ -48,15 +50,69 @@ public class ChoiceDefinition extends Pr
 
     public ChoiceDefinition() {
     }
+    
+    @Override
+    public List<ProcessorDefinition> getOutputs() {
+        return new AbstractList<ProcessorDefinition>() {
+            public ProcessorDefinition get(int index) {
+                if (index < whenClauses.size()) {
+                    return whenClauses.get(index);
+                } 
+                if (index == whenClauses.size()) {
+                    return otherwise;
+                }
+                throw new IndexOutOfBoundsException();
+            }
+            public boolean add(ProcessorDefinition def) {
+                if (def instanceof WhenDefinition) {
+                    return whenClauses.add((WhenDefinition)def);
+                } else if (def instanceof OtherwiseDefinition) {
+                    otherwise = (OtherwiseDefinition)def;
+                    return true;
+                }
+                throw new IllegalArgumentException();
+            }
+            public int size() {
+                return whenClauses.size() + (otherwise == null ? 0 : 1);
+            }
+            public void clear() {
+                whenClauses.clear();
+                otherwise = null;
+            }
+            public ProcessorDefinition set(int index, ProcessorDefinition element) {
+                if (index < whenClauses.size()) {
+                    if (element instanceof WhenDefinition) {
+                        return whenClauses.set(index, (WhenDefinition)element);
+                    }
+                    throw new IllegalArgumentException();
+                } else if (index == whenClauses.size()) {
+                    ProcessorDefinition old = otherwise;
+                    otherwise = (OtherwiseDefinition)element;
+                    return old;
+                }
+                throw new IndexOutOfBoundsException();
+            }
+            public ProcessorDefinition remove(int index) {
+                if (index < whenClauses.size()) {
+                    return whenClauses.remove(index);
+                } else if (index == whenClauses.size()) {
+                    ProcessorDefinition old = otherwise;
+                    otherwise = null;
+                    return old;
+                }
+                throw new IndexOutOfBoundsException();
+            }
+        };
+    }
 
     @Override
+    public boolean isOutputSupported() {
+        return true;
+    }
+    
+    @Override
     public String toString() {
-        if (getOtherwise() != null) {
-            return "Choice[" + getWhenClauses() + " " + getOtherwise() + "]";
-        } else {
-            return "Choice[" + getWhenClauses() + "]";
-
-        }
+        return "Choice[" + getWhenClauses() + (getOtherwise() != null ? " " + getOtherwise() : "") + "]";
     }
 
     @Override
@@ -67,8 +123,8 @@ public class ChoiceDefinition extends Pr
     @Override
     public Processor createProcessor(RouteContext routeContext) throws Exception {
         List<FilterProcessor> filters = new ArrayList<FilterProcessor>();
-        for (WhenDefinition whenClaus : whenClauses) {
-            filters.add(whenClaus.createProcessor(routeContext));
+        for (WhenDefinition whenClause : whenClauses) {
+            filters.add(whenClause.createProcessor(routeContext));
         }
         Processor otherwiseProcessor = null;
         if (otherwise != null) {
@@ -87,9 +143,7 @@ public class ChoiceDefinition extends Pr
      * @return the builder
      */
     public ChoiceDefinition when(Predicate predicate) {
-        WhenDefinition when = new WhenDefinition(predicate);
-        when.setParent(this);
-        getWhenClauses().add(when);
+        addClause(new WhenDefinition(predicate));
         return this;
     }
 
@@ -99,14 +153,17 @@ public class ChoiceDefinition extends Pr
      * @return expression to be used as builder to configure the when node
      */
     public ExpressionClause<ChoiceDefinition> when() {
-        WhenDefinition when = new WhenDefinition();
-        when.setParent(this);
-        getWhenClauses().add(when);
         ExpressionClause<ChoiceDefinition> clause = new ExpressionClause<ChoiceDefinition>(this);
-        when.setExpression(clause);
+        addClause(new WhenDefinition(clause));
         return clause;
     }
-
+    
+    private void addClause(ProcessorDefinition when) {
+        popBlock();
+        addOutput(when);
+        pushBlock(when);
+    }
+    
     /**
      * Sets the otherwise node
      *
@@ -114,8 +171,7 @@ public class ChoiceDefinition extends Pr
      */
     public ChoiceDefinition otherwise() {
         OtherwiseDefinition answer = new OtherwiseDefinition();
-        answer.setParent(this);
-        setOtherwise(answer);
+        addClause(answer);
         return this;
     }
 
@@ -132,20 +188,6 @@ public class ChoiceDefinition extends Pr
         }
     }
 
-    @Override
-    public void addOutput(ProcessorDefinition output) {
-        super.addOutput(output);
-        // re-configure parent as its a tad more complex for the Content Based Router
-        if (otherwise != null) {
-            output.setParent(otherwise);
-        } else if (!getWhenClauses().isEmpty()) {
-            int size = getWhenClauses().size();
-            output.setParent(getWhenClauses().get(size - 1));
-        } else {
-            output.setParent(this);
-        }
-    }
-
     // Properties
     // -------------------------------------------------------------------------
 
@@ -167,22 +209,6 @@ public class ChoiceDefinition extends Pr
         this.whenClauses = whenClauses;
     }
 
-    @SuppressWarnings("unchecked")
-    public List<ProcessorDefinition> getOutputs() {
-        if (otherwise != null) {
-            return otherwise.getOutputs();
-        } else if (whenClauses.isEmpty()) {
-            return Collections.EMPTY_LIST;
-        } else {
-            WhenDefinition when = whenClauses.get(whenClauses.size() - 1);
-            return when.getOutputs();
-        }
-    }
-
-    public boolean isOutputSupported() {
-        return true;
-    }
-
     public OtherwiseDefinition getOtherwise() {
         return otherwise;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java?rev=1134501&r1=1134500&r2=1134501&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java Sat Jun 11 01:45:11 2011
@@ -32,7 +32,7 @@ import org.apache.camel.util.CollectionS
  */
 @XmlRootElement(name = "otherwise")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class OtherwiseDefinition extends OutputDefinition<OtherwiseDefinition> implements Block {
+public class OtherwiseDefinition extends OutputDefinition<OtherwiseDefinition> {
 
     public OtherwiseDefinition() {
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=1134501&r1=1134500&r2=1134501&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Sat Jun 11 01:45:11 2011
@@ -160,16 +160,18 @@ public abstract class ProcessorDefinitio
     }
 
     public void addOutput(ProcessorDefinition output) {
+        if (!blocks.isEmpty()) {
+            // let the Block deal with the output
+            Block block = blocks.getLast();
+            block.addOutput(output);
+            return;
+        }
+
         output.setParent(this);
         output.setNodeFactory(getNodeFactory());
         output.setErrorHandlerBuilder(getErrorHandlerBuilder());
         configureChild(output);
-        if (blocks.isEmpty()) {
-            getOutputs().add(output);
-        } else {
-            Block block = blocks.getLast();
-            block.addOutput(output);
-        }
+        getOutputs().add(output);
     }
 
     public void clearOutput() {
@@ -932,7 +934,18 @@ public abstract class ProcessorDefinitio
             setId(id);
         } else {
             // set it on last output as this is what the user means to do
-            getOutputs().get(getOutputs().size() - 1).setId(id);
+            // for Block(s) with non empty getOutputs() the id probably refers
+            //  to the last definition in the current Block
+            List<ProcessorDefinition> outputs = getOutputs();
+            if (!blocks.isEmpty()) {
+                if (blocks.getLast() instanceof ProcessorDefinition) {
+                    ProcessorDefinition block = (ProcessorDefinition)blocks.getLast();
+                    if (!block.getOutputs().isEmpty()) {
+                        outputs = block.getOutputs();
+                    }
+                }
+            }
+            outputs.get(outputs.size() - 1).setId(id);
         }
 
         return (Type) this;
@@ -1120,7 +1133,9 @@ public abstract class ProcessorDefinitio
         // when using doTry .. doCatch .. doFinally we should always
         // end the try definition to avoid having to use 2 x end() in the route
         // this is counter intuitive for end users
-        if (defn instanceof TryDefinition) {
+        // TODO (camel-3.0): this should be done inside of TryDefinition or even better
+        //  in Block(s) in general, but the api needs to be revisited for that.
+        if (defn instanceof TryDefinition || defn instanceof ChoiceDefinition) {
             popBlock();
         }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java?rev=1134501&r1=1134500&r2=1134501&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java Sat Jun 11 01:45:11 2011
@@ -168,6 +168,7 @@ public class DefaultChannel extends Serv
         // the definition to wrap should be the fine grained,
         // so if a child is set then use it, if not then its the original output used
         ProcessorDefinition<?> targetOutputDef = childDefinition != null ? childDefinition : outputDefinition;
+        LOG.debug("Initialize channel for target: '{}'", targetOutputDef);
 
         // fix parent/child relationship. This will be the case of the routes has been
         // defined using XML DSL or end user may have manually assembled a route from the model.

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java?rev=1134501&r1=1134500&r2=1134501&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java Sat Jun 11 01:45:11 2011
@@ -26,32 +26,33 @@ import org.apache.camel.builder.RouteBui
  */
 public class ManagedCBRTest extends ManagementTestSupport {
 
+    // CAMEL-4044: mbeans not registered for children of choice
     public void testManagedCBR() throws Exception {
         MBeanServer mbeanServer = getMBeanServer();
 
         ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=routes,name=\"route\"");
-        mbeanServer.isRegistered(on);
+        assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
 
         on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"task-a\"");
-        mbeanServer.isRegistered(on);
+        assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
 
         on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"choice\"");
-        mbeanServer.isRegistered(on);
+        assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
 
         on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"task-b\"");
-        mbeanServer.isRegistered(on);
-
+        assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
+        
         on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"task-c\"");
-        mbeanServer.isRegistered(on);
+        assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
 
         on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"task-d\"");
-        mbeanServer.isRegistered(on);
+        assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
 
         on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"task-e\"");
-        mbeanServer.isRegistered(on);
+        assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
 
         on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=processors,name=\"task-done\"");
-        mbeanServer.isRegistered(on);
+        assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
     }
 
     @Override

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java?rev=1134501&r1=1134500&r2=1134501&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandlerBuilder.java Sat Jun 11 01:45:11 2011
@@ -84,7 +84,7 @@ public class TransactionErrorHandlerBuil
                     LOG.trace("No TransactionTemplate found in registry.");
                 } else {
                     LOG.debug("Found {} TransactionTemplate in registry. Cannot determine which one to use. "
-                    		+ "Please configure a TransactionTemplate on the TransactionErrorHandlerBuilder", map.size());
+                              + "Please configure a TransactionTemplate on the TransactionErrorHandlerBuilder", map.size());
                 }
             }
 
@@ -97,7 +97,7 @@ public class TransactionErrorHandlerBuil
                     LOG.trace("No PlatformTransactionManager found in registry.");
                 } else {
                     LOG.debug("Found {} PlatformTransactionManager in registry. Cannot determine which one to use for TransactionTemplate. "
-                    		+ "Please configure a TransactionTemplate on the TransactionErrorHandlerBuilder", map.size());
+                              + "Please configure a TransactionTemplate on the TransactionErrorHandlerBuilder", map.size());
                 }
             }