Author: hadrian Date: Sat Jun 11 03:00:43 2011 New Revision: 1134510 URL: http://svn.apache.org/viewvc?rev=1134510&view=rev Log: CAMEL-4044. Port to 2.7.x
Modified: camel/branches/camel-2.7.x/ (props changed) camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/impl/RouteService.java camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java camel/branches/camel-2.7.x/components/camel-http/ (props changed) Propchange: camel/branches/camel-2.7.x/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Sat Jun 11 03:00:43 2011 @@ -1 +1 @@ -/camel/trunk:1083696,1087276,1087612,1087856,1088583,1088916-1088917,1089275,1090166,1091518,1091771,1091799,1092068,1092577,1092667,1093978,1095405,1095469,1095471,1095475-1095476,1099417,1102162,1104076,1124497,1131411 +/camel/trunk:1083696,1087276,1087612,1087856,1088583,1088916-1088917,1089275,1090166,1091518,1091771,1091799,1092068,1092577,1092667,1093978,1095405,1095469,1095471,1095475-1095476,1099417,1102162,1104076,1124497,1131411,1134501 Modified: camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/impl/RouteService.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/impl/RouteService.java?rev=1134510&r1=1134509&r2=1134510&view=diff ============================================================================== --- camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/impl/RouteService.java (original) +++ camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/impl/RouteService.java Sat Jun 11 03:00:43 2011 @@ -244,6 +244,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/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java?rev=1134510&r1=1134509&r2=1134510&view=diff ============================================================================== --- camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java (original) +++ camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java Sat Jun 11 03:00:43 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 CNR - 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/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java?rev=1134510&r1=1134509&r2=1134510&view=diff ============================================================================== --- camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java (original) +++ camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/OtherwiseDefinition.java Sat Jun 11 03:00:43 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/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=1134510&r1=1134509&r2=1134510&view=diff ============================================================================== --- camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original) +++ camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Sat Jun 11 03:00:43 2011 @@ -159,14 +159,16 @@ public abstract class ProcessorDefinitio } public void addOutput(ProcessorDefinition output) { - output.setParent(this); - configureChild(output); - if (blocks.isEmpty()) { - getOutputs().add(output); - } else { + if (!blocks.isEmpty()) { + // let the Block deal with the output Block block = blocks.getLast(); block.addOutput(output); + return; } + + output.setParent(this); + configureChild(output); + getOutputs().add(output); } public void clearOutput() { @@ -903,7 +905,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; @@ -1090,7 +1103,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/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java?rev=1134510&r1=1134509&r2=1134510&view=diff ============================================================================== --- camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java (original) +++ camel/branches/camel-2.7.x/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java Sat Jun 11 03:00:43 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); // first wrap the output with the managed strategy if any InterceptStrategy managed = routeContext.getManagedInterceptStrategy(); Modified: camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java?rev=1134510&r1=1134509&r2=1134510&view=diff ============================================================================== --- camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java (original) +++ camel/branches/camel-2.7.x/camel-core/src/test/java/org/apache/camel/management/ManagedCBRTest.java Sat Jun 11 03:00:43 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 Propchange: camel/branches/camel-2.7.x/components/camel-http/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Sat Jun 11 03:00:43 2011 @@ -1 +1 @@ -/camel/trunk/components/camel-http:917526,1083696,1087276,1087612,1087856,1088583,1088916-1088917,1089275,1090166,1091518,1091771,1091799,1092068,1092577,1092667,1093978,1095405,1095469,1095471,1095475-1095476,1099417,1102162,1104076,1124497,1131411 +/camel/trunk/components/camel-http:917526,1083696,1087276,1087612,1087856,1088583,1088916-1088917,1089275,1090166,1091518,1091771,1091799,1092068,1092577,1092667,1093978,1095405,1095469,1095471,1095475-1095476,1099417,1102162,1104076,1124497,1131411,1134501