CAMEL-7017: Fixed CS and polished new camel-optaplanner component.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4de59831 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4de59831 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4de59831 Branch: refs/heads/master Commit: 4de59831e3a9b84e56b37642a6d31f33550939a3 Parents: e86d429 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Nov 27 11:57:18 2013 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Nov 27 11:57:18 2013 +0100 ---------------------------------------------------------------------- components/camel-optaplanner/pom.xml | 93 ++++++++++---------- .../optaplanner/OptaPlannerComponent.java | 6 +- .../optaplanner/OptaPlannerEndpoint.java | 18 +--- .../component/optaplanner/OptaPlannerTest.java | 6 +- .../component/optaplanner/solverConfig.xml | 16 ++++ 5 files changed, 71 insertions(+), 68 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/4de59831/components/camel-optaplanner/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-optaplanner/pom.xml b/components/camel-optaplanner/pom.xml index eb36231..1be864a 100644 --- a/components/camel-optaplanner/pom.xml +++ b/components/camel-optaplanner/pom.xml @@ -15,57 +15,58 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.camel</groupId> - <artifactId>components</artifactId> - <version>2.13-SNAPSHOT</version> - </parent> + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>components</artifactId> + <version>2.13-SNAPSHOT</version> + </parent> - <artifactId>camel-optaplanner</artifactId> - <packaging>bundle</packaging> - <name>Camel :: OptaPlanner</name> - <description>Camel OptaPlanner support</description> + <artifactId>camel-optaplanner</artifactId> + <packaging>bundle</packaging> + <name>Camel :: OptaPlanner</name> + <description>Camel OptaPlanner support</description> - <properties> - <camel.osgi.export.pkg>org.apache.camel.component.optaplanner.*</camel.osgi.export.pkg> - <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=optaplanner</camel.osgi.export.service> - </properties> + <properties> + <camel.osgi.export.pkg>org.apache.camel.component.optaplanner.*</camel.osgi.export.pkg> + <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=optaplanner</camel.osgi.export.service> + </properties> - <dependencies> + <dependencies> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> - </dependency> - <dependency> - <groupId>org.optaplanner</groupId> - <artifactId>optaplanner-core</artifactId> - </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + <dependency> + <groupId>org.optaplanner</groupId> + <artifactId>optaplanner-core</artifactId> + </dependency> - <!-- testing --> - <dependency> - <groupId>org.optaplanner</groupId> - <artifactId>optaplanner-examples</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test-spring</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> + <!-- testing --> + <dependency> + <groupId>org.optaplanner</groupId> + <artifactId>optaplanner-examples</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test-spring</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> </project> http://git-wip-us.apache.org/repos/asf/camel/blob/4de59831/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerComponent.java b/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerComponent.java index 55f26e3..307dba5 100644 --- a/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerComponent.java +++ b/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerComponent.java @@ -16,13 +16,10 @@ */ package org.apache.camel.component.optaplanner; -import java.net.URL; import java.util.Map; import org.apache.camel.Endpoint; import org.apache.camel.impl.DefaultComponent; -import org.apache.camel.util.ObjectHelper; -import org.apache.camel.util.ResourceHelper; import org.optaplanner.core.api.solver.SolverFactory; import org.optaplanner.core.config.solver.XmlSolverFactory; @@ -33,8 +30,11 @@ public class OptaPlannerComponent extends DefaultComponent { protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { SolverFactory solverFactory = new XmlSolverFactory(remaining); + OptaPlannerEndpoint endpoint = new OptaPlannerEndpoint(uri, this, remaining); endpoint.setSolverFactory(solverFactory); + setProperties(endpoint, parameters); + return endpoint; } http://git-wip-us.apache.org/repos/asf/camel/blob/4de59831/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerEndpoint.java b/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerEndpoint.java index 5eefc56..fe4003b 100644 --- a/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerEndpoint.java +++ b/components/camel-optaplanner/src/main/java/org/apache/camel/component/optaplanner/OptaPlannerEndpoint.java @@ -16,17 +16,10 @@ */ package org.apache.camel.component.optaplanner; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.util.Map; - import org.apache.camel.Component; import org.apache.camel.Exchange; import org.apache.camel.ExchangePattern; -import org.apache.camel.Message; import org.apache.camel.component.ResourceEndpoint; -import org.apache.camel.util.ExchangeHelper; import org.apache.camel.util.ObjectHelper; import org.optaplanner.core.api.solver.Solver; import org.optaplanner.core.api.solver.SolverFactory; @@ -55,11 +48,6 @@ public class OptaPlannerEndpoint extends ResourceEndpoint { } @Override - public boolean isSingleton() { - return true; - } - - @Override public ExchangePattern getExchangePattern() { return ExchangePattern.InOut; } @@ -74,14 +62,16 @@ public class OptaPlannerEndpoint extends ResourceEndpoint { ObjectHelper.notNull(solverFactory, "solverFactory"); Solver solver = solverFactory.buildSolver(); - Object bodyObject = exchange.getIn().getBody(); - Solution planningProblem = ObjectHelper.cast(Solution.class, bodyObject); + Solution planningProblem = exchange.getIn().getMandatoryBody(Solution.class); solver.setPlanningProblem(planningProblem); solver.solve(); Solution bestSolution = solver.getBestSolution(); exchange.getOut().setBody(bestSolution); + // propagate headers and attachments + exchange.getOut().setHeaders(exchange.getIn().getHeaders()); + exchange.getOut().setAttachments(exchange.getIn().getAttachments()); } } http://git-wip-us.apache.org/repos/asf/camel/blob/4de59831/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerTest.java b/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerTest.java index d5a84de..1d541be 100644 --- a/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerTest.java +++ b/components/camel-optaplanner/src/test/java/org/apache/camel/component/optaplanner/OptaPlannerTest.java @@ -16,10 +16,6 @@ */ package org.apache.camel.component.optaplanner; -import javax.activation.DataHandler; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; @@ -32,7 +28,7 @@ import org.optaplanner.examples.cloudbalancing.persistence.CloudBalancingGenerat public class OptaPlannerTest extends CamelTestSupport { @Test - public void testCloudBalance_4computers_12processes() throws Exception { + public void testCloudBalance4computers12processes() throws Exception { CloudBalancingGenerator generator = new CloudBalancingGenerator(true); final CloudBalance planningProblem = generator.createCloudBalance(4, 12); assertNull(planningProblem.getScore()); http://git-wip-us.apache.org/repos/asf/camel/blob/4de59831/components/camel-optaplanner/src/test/resources/org/apache/camel/component/optaplanner/solverConfig.xml ---------------------------------------------------------------------- diff --git a/components/camel-optaplanner/src/test/resources/org/apache/camel/component/optaplanner/solverConfig.xml b/components/camel-optaplanner/src/test/resources/org/apache/camel/component/optaplanner/solverConfig.xml index 9362df9..eb07fc0 100644 --- a/components/camel-optaplanner/src/test/resources/org/apache/camel/component/optaplanner/solverConfig.xml +++ b/components/camel-optaplanner/src/test/resources/org/apache/camel/component/optaplanner/solverConfig.xml @@ -1,4 +1,20 @@ <?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> <solver> <!--<environmentMode>FAST_ASSERT</environmentMode>-->