camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/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:58:57 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x f341506ea -> 6f3b86cf8
  refs/heads/camel-2.13.x 48567a23d -> 2c1f12dc0
  refs/heads/master 2f8bc8045 -> e1f9e26e6


CAMEL-7745: EndpointInject using ref should be enlisted in JMX when using OSGi such as blueprint.


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

Branch: refs/heads/master
Commit: e1f9e26e6aaf9f92e93f5851bf7189f01e819aa0
Parents: 2e43bd6
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:56:45 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/e1f9e26e/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 ae31c51..23ba36d 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -397,6 +397,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
@@ -707,6 +715,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/e1f9e26e/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 abf0c9a..666ee4a 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
@@ -186,6 +186,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;
@@ -803,6 +804,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));
     }
@@ -1423,6 +1429,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/e1f9e26e/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 7eb1452..3e44b60 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
@@ -862,6 +862,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/e1f9e26e/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 1b0fdd1..4dec4fd 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
@@ -310,6 +310,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();
 
@@ -331,6 +334,9 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
 
             // and add the rests
             getContext().addRestDefinitions(getRests());
+
+            // and we are now finished setting up the routes
+            getContext().setupRoutes(true);
         }
     }
 


Mime
View raw message