camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [5/5] git commit: CAMEL-7745: EndpointInject using ref should be enlisted in JMX when using OSGi such as blueprint.
Date Tue, 26 Aug 2014 07:59:01 GMT
CAMEL-7745: EndpointInject using ref should be enlisted in JMX when using OSGi such as blueprint.

Conflicts:
	components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java


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

Branch: refs/heads/camel-2.12.x
Commit: 6f3b86cf8217277edd94cff473e3c747a33b39bc
Parents: f341506
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Aug 26 09:51:40 2014 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Aug 26 09:58:34 2014 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     | 23 ++++++++++++++++++++
 .../apache/camel/impl/DefaultCamelContext.java  | 14 ++++++++++++
 .../DefaultManagementLifecycleStrategy.java     |  5 +++++
 .../xml/AbstractCamelContextFactoryBean.java    |  6 +++++
 4 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6f3b86cf/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 319e3a0..56aebd6 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -367,6 +367,14 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration
{
     //-----------------------------------------------------------------------
 
     /**
+     * Method to signal to {@link CamelContext} that the process to initialize setup routes
is in progress.
+     *
+     * @param done <tt>false</tt> to start the process, call again with <tt>true</tt>
to signal its done.
+     * @see #isSetupRoutes()
+     */
+    void setupRoutes(boolean done);
+
+    /**
      * Returns a list of the current route definitions
      *
      * @return list of the current route definitions
@@ -645,6 +653,21 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration
{
      */
     boolean isStartingRoutes();
 
+    /**
+     * Indicates whether current thread is setting up route(s) as part of starting Camel
from spring/blueprint.
+     * <p/>
+     * This can be useful to know by {@link LifecycleStrategy} or the likes, in case
+     * they need to react differently.
+     * <p/>
+     * As the startup procedure of {@link CamelContext} is slightly different when using
plain Java versus
+     * Spring or Blueprint, then we need to know when Spring/Blueprint is setting up the
routes, which
+     * can happen after the {@link CamelContext} itself is in started state, due the asynchronous
event nature
+     * of especially Blueprint.
+     *
+     * @return <tt>true</tt> if current thread is setting up route(s), or <tt>false</tt>
if not.
+     */
+    boolean isSetupRoutes();
+
     // Properties
     //-----------------------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6f3b86cf/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index bbb8bde..0f2f3a9 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -176,6 +176,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
     private volatile boolean firstStartDone;
     private volatile boolean doNotStartRoutesOnFirstStart;
     private final ThreadLocal<Boolean> isStartingRoutes = new ThreadLocal<Boolean>();
+    private final ThreadLocal<Boolean> isSetupRoutes = new ThreadLocal<Boolean>();
     private Boolean autoStartup = Boolean.TRUE;
     private Boolean trace = Boolean.FALSE;
     private Boolean messageHistory = Boolean.TRUE;
@@ -790,6 +791,11 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         return answer != null && answer;
     }
 
+    public boolean isSetupRoutes() {
+        Boolean answer = isSetupRoutes.get();
+        return answer != null && answer;
+    }
+
     public void stopRoute(RouteDefinition route) throws Exception {
         stopRoute(route.idOrCreate(nodeIdFactory));
     }
@@ -1294,6 +1300,14 @@ public class DefaultCamelContext extends ServiceSupport implements
ModelCamelCon
         this.lifecycleStrategies.add(lifecycleStrategy);
     }
 
+    public void setupRoutes(boolean done) {
+        if (done) {
+            isSetupRoutes.remove();
+        } else {
+            isSetupRoutes.set(true);
+        }
+    }
+
     public synchronized List<RouteDefinition> getRouteDefinitions() {
         return routeDefinitions;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/6f3b86cf/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
index 2528715..976993e 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
@@ -854,6 +854,11 @@ public class DefaultManagementLifecycleStrategy extends ServiceSupport
implement
             return true;
         }
 
+        // always register if we are setting up routes
+        if (getCamelContext().isSetupRoutes()) {
+            return true;
+        }
+
         // register if always is enabled
         if (agent.getRegisterAlways()) {
             return true;

http://git-wip-us.apache.org/repos/asf/camel/blob/6f3b86cf/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index 84f6b5a..102db5a 100644
--- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -288,6 +288,9 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
         if (routesSetupDone.compareAndSet(false, true)) {
             LOG.debug("Setting up routes");
 
+            // mark that we are setting up routes
+            getContext().setupRoutes(false);
+
             // must init route refs before we prepare the routes below
             initRouteRefs();
 
@@ -303,6 +306,9 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
 
             findRouteBuilders();
             installRoutes();
+
+            // and we are now finished setting up the routes
+            getContext().setupRoutes(true);
         }
     }
 


Mime
View raw message