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 2015/08/05 15:01:17 UTC

[2/4] camel git commit: CAMEL-8857: camel-scr should publish the Camel to osgi so the karaf commands works and also what blueprint/spring-dm does.

CAMEL-8857: camel-scr should publish the Camel to osgi so the karaf commands works and also what blueprint/spring-dm does.


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

Branch: refs/heads/camel-2.15.x
Commit: bfd8a10b0b37a606af2302c6e2e9071d2351adf2
Parents: 0c268d4
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Aug 5 15:05:26 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Aug 5 15:06:28 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/scr/AbstractCamelRunner.java   | 21 +++++++++++---------
 .../camel/scr/AbstractCamelRunnerTest.java      |  1 +
 2 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bfd8a10b/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java b/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
index 0d52927..86ff9bb 100644
--- a/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
+++ b/components/camel-scr/src/main/java/org/apache/camel/scr/AbstractCamelRunner.java
@@ -36,6 +36,7 @@ import java.util.concurrent.TimeUnit;
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.component.properties.PropertiesComponent;
+import org.apache.camel.core.osgi.OsgiCamelContextPublisher;
 import org.apache.camel.core.osgi.OsgiDefaultCamelContext;
 import org.apache.camel.core.osgi.utils.BundleDelegatingClassLoader;
 import org.apache.camel.impl.DefaultCamelContext;
@@ -57,15 +58,11 @@ public abstract class AbstractCamelRunner implements Runnable {
     protected ModelCamelContext context;
     protected SimpleRegistry registry = new SimpleRegistry();
 
-    // Configured fields
-    private String camelContextId = "camel-runner-default";
-    private boolean active;   
-
     private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
     private ScheduledFuture starter;
     private volatile boolean activated;
     private volatile boolean started;
-
+    protected volatile boolean active;
 
     public synchronized void activate(final BundleContext bundleContext, final Map<String, String> props) throws Exception {
         if (activated) {
@@ -86,7 +83,7 @@ public abstract class AbstractCamelRunner implements Runnable {
         // Configure fields from properties
         configure(context, this, log, true);
 
-        setupCamelContext(bundleContext, camelContextId);
+        setupCamelContext(bundleContext);
     }
 
     protected void createCamelContext(final BundleContext bundleContext, final Map<String, String> props) {
@@ -100,11 +97,18 @@ public abstract class AbstractCamelRunner implements Runnable {
             context = new DefaultCamelContext(registry);
         }
         setupPropertiesComponent(context, props, log);
+
+        String name = props.remove("camelContextId");
+        if (name != null) {
+            context.setNameStrategy(new ExplicitCamelContextNameStrategy(name));
+        }
+
+        // ensure we publish this CamelContext to the OSGi service registry
+        context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundleContext));
     }
     
-    protected void setupCamelContext(final BundleContext bundleContext, final String camelContextId) throws Exception {
+    protected void setupCamelContext(final BundleContext bundleContext) throws Exception {
         // Set up CamelContext
-        context.setNameStrategy(new ExplicitCamelContextNameStrategy(camelContextId));
         context.setUseMDCLogging(true);
         context.setUseBreadcrumb(true);
 
@@ -188,7 +192,6 @@ public abstract class AbstractCamelRunner implements Runnable {
         try {
             if (!active) {
                 context.setAutoStartup(false);
-                log.info(camelContextId + " autoStartup disabled (active property is false)");
             }
             context.start();
             started = true;

http://git-wip-us.apache.org/repos/asf/camel/blob/bfd8a10b/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java b/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java
index c8fb1ce..5b10b15 100644
--- a/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java
+++ b/components/camel-scr/src/test/java/org/apache/camel/scr/AbstractCamelRunnerTest.java
@@ -49,6 +49,7 @@ public class AbstractCamelRunnerTest {
     @Test
     public void testDeepConfigure() throws Exception {
         ConcreteCamelRunner integration = new ConcreteCamelRunner();
+
         integration.activate(null, integration.getDefaultProperties());
         assertEquals("Overriding camelContextId failed (deep configure)", integration.getDefaultProperties().get("camelContextId"), integration.getContext().getName());
     }