You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/02/10 21:23:29 UTC
[camel-k] branch master updated: Moved route loading of jvm-runtime
inside a Listner to load them after context customizers have run.k
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new eb3cfb8 Moved route loading of jvm-runtime inside a Listner to load them after context customizers have run.k
eb3cfb8 is described below
commit eb3cfb8ba9e1fe42cd18fb16c884d93f067ae35e
Author: Andrea Tarocchi <at...@redhat.com>
AuthorDate: Sun Feb 10 22:03:41 2019 +0100
Moved route loading of jvm-runtime inside a Listner to load them after context customizers have run.k
---
.../java/org/apache/camel/k/jvm/Application.java | 28 ++++++++++++++++------
.../org/apache/camel/k/jvm/PropertiesTest.java | 14 +++++------
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/Application.java b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/Application.java
index e82f713..f317880 100644
--- a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/Application.java
+++ b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/Application.java
@@ -16,10 +16,9 @@
*/
package org.apache.camel.k.jvm;
-import javax.xml.bind.JAXBException;
-
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.k.Constants;
import org.apache.camel.k.RuntimeRegistry;
import org.apache.camel.k.support.RuntimeSupport;
@@ -33,6 +32,8 @@ import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.xml.bind.JAXBException;
+
public class Application {
static {
//
@@ -68,9 +69,9 @@ public class Application {
Runtime runtime = new Runtime();
runtime.setProperties(ApplicationSupport.loadProperties());
- runtime.load(routes.split(",", -1));
- runtime.addMainListener(new ComponentPropertiesBinder(runtime.getRegistry()));
+ runtime.addMainListener(new CamelkJvmRuntimeConfigurer(runtime, routes.split(",", -1)));
runtime.addMainListener(new RoutesDumper());
+
runtime.run();
}
@@ -80,12 +81,16 @@ public class Application {
//
// *******************************
- static class ComponentPropertiesBinder extends MainListenerSupport {
+ static class CamelkJvmRuntimeConfigurer extends MainListenerSupport {
private RuntimeRegistry registry;
+ private Runtime runtime;
+ private String[] routes;
- public ComponentPropertiesBinder(RuntimeRegistry registry){
- this.registry = registry;
+ public CamelkJvmRuntimeConfigurer(Runtime runtime, String[] routes){
+ this.runtime = runtime;
+ this.registry = runtime.getRegistry();
+ this.routes = routes;
}
@Override
@@ -128,6 +133,15 @@ public class Application {
RuntimeSupport.bindProperties(context, component, "camel.component." + name + ".");
}
});
+
+ //
+ // Load routes
+ //
+ try {
+ runtime.load(routes);
+ } catch (Exception e) {
+ throw new RuntimeCamelException("CamelkJvmRuntimeConfigurer has failed to load routes: "+routes);
+ }
}
}
diff --git a/runtime/camel-k-runtime-jvm/src/test/java/org/apache/camel/k/jvm/PropertiesTest.java b/runtime/camel-k-runtime-jvm/src/test/java/org/apache/camel/k/jvm/PropertiesTest.java
index e618860..03de91b 100644
--- a/runtime/camel-k-runtime-jvm/src/test/java/org/apache/camel/k/jvm/PropertiesTest.java
+++ b/runtime/camel-k-runtime-jvm/src/test/java/org/apache/camel/k/jvm/PropertiesTest.java
@@ -19,11 +19,9 @@ package org.apache.camel.k.jvm;
import java.util.Properties;
import java.util.concurrent.ThreadLocalRandom;
-import org.apache.camel.CamelContext;
import org.apache.camel.component.seda.SedaComponent;
import org.apache.camel.k.Constants;
import org.apache.camel.k.ContextCustomizer;
-import org.apache.camel.k.RuntimeRegistry;
import org.junit.jupiter.api.Test;
import static org.apache.camel.k.jvm.RuntimeTestSupport.afterStart;
@@ -38,7 +36,7 @@ public class PropertiesTest {
Runtime runtime = new Runtime();
runtime.setProperties(properties);
runtime.setDuration(5);
- runtime.addMainListener(new Application.ComponentPropertiesBinder(runtime.getRegistry()));
+ runtime.addMainListener(new Application.CamelkJvmRuntimeConfigurer(runtime, new String[0]));
runtime.addMainListener(afterStart((main, context) -> {
assertThat(context.resolvePropertyPlaceholders("{{root.key}}")).isEqualTo("root.value");
assertThat(context.resolvePropertyPlaceholders("{{001.key}}")).isEqualTo("001.value");
@@ -58,7 +56,7 @@ public class PropertiesTest {
Runtime runtime = new Runtime();
runtime.setProperties(System.getProperties());
runtime.setDuration(5);
- runtime.addMainListener(new Application.ComponentPropertiesBinder(runtime.getRegistry()));
+ runtime.addMainListener(new Application.CamelkJvmRuntimeConfigurer(runtime, new String[0]));
runtime.addMainListener(afterStart((main, context) -> {
String value = context.resolvePropertyPlaceholders("{{my.property}}");
@@ -85,7 +83,7 @@ public class PropertiesTest {
runtime.setProperties(System.getProperties());
runtime.setDuration(5);
runtime.getRegistry().bind("my-seda", new SedaComponent());
- runtime.addMainListener(new Application.ComponentPropertiesBinder(runtime.getRegistry()));
+ runtime.addMainListener(new Application.CamelkJvmRuntimeConfigurer(runtime, new String[0]));
runtime.addMainListener(afterStart((main, context) -> {
assertThat(context.getComponent("seda", true)).hasFieldOrPropertyWithValue("queueSize", queueSize1);
assertThat(context.getComponent("my-seda", true)).hasFieldOrPropertyWithValue("queueSize", queueSize2);
@@ -108,7 +106,7 @@ public class PropertiesTest {
Runtime runtime = new Runtime();
runtime.setProperties(System.getProperties());
runtime.setDuration(5);
- runtime.addMainListener(new Application.ComponentPropertiesBinder(runtime.getRegistry()));
+ runtime.addMainListener(new Application.CamelkJvmRuntimeConfigurer(runtime, new String[0]));
runtime.addMainListener(afterStart((main, context) -> {
assertThat(context.isMessageHistory()).isFalse();
assertThat(context.isLoadTypeConverters()).isFalse();
@@ -130,7 +128,7 @@ public class PropertiesTest {
Runtime runtime = new Runtime();
runtime.setProperties(System.getProperties());
runtime.setDuration(5);
- runtime.addMainListener(new Application.ComponentPropertiesBinder(runtime.getRegistry()));
+ runtime.addMainListener(new Application.CamelkJvmRuntimeConfigurer(runtime, new String[0]));
runtime.addMainListener(afterStart((main, context) -> {
assertThat(context.isMessageHistory()).isFalse();
assertThat(context.isLoadTypeConverters()).isFalse();
@@ -149,7 +147,7 @@ public class PropertiesTest {
camelContext.setMessageHistory(false);
camelContext.setLoadTypeConverters(false);
});
- runtime.addMainListener(new Application.ComponentPropertiesBinder(runtime.getRegistry()));
+ runtime.addMainListener(new Application.CamelkJvmRuntimeConfigurer(runtime, new String[0]));
runtime.addMainListener(afterStart((main, context) -> {
assertThat(context.isMessageHistory()).isFalse();
assertThat(context.isLoadTypeConverters()).isFalse();