camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9174: Main - Make it easier to configure CamelContext before its started
Date Sun, 27 Sep 2015 07:22:26 GMT
Repository: camel
Updated Branches:
  refs/heads/master cc9924f41 -> ba631d53c


CAMEL-9174: Main - Make it easier to configure CamelContext before its started


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

Branch: refs/heads/master
Commit: ba631d53c1a1cac0c45682c6bad6ba851572807d
Parents: cc9924f
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Sep 27 09:11:13 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Sep 27 09:11:13 2015 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/camel/main/MainListener.java | 14 +++++++++++++-
 .../org/apache/camel/main/MainListenerSupport.java    |  6 ++++++
 .../main/java/org/apache/camel/main/MainSupport.java  |  4 ++++
 3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ba631d53/camel-core/src/main/java/org/apache/camel/main/MainListener.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/main/MainListener.java b/camel-core/src/main/java/org/apache/camel/main/MainListener.java
index 3de7668..ac797d5 100644
--- a/camel-core/src/main/java/org/apache/camel/main/MainListener.java
+++ b/camel-core/src/main/java/org/apache/camel/main/MainListener.java
@@ -16,19 +16,31 @@
  */
 package org.apache.camel.main;
 
+import org.apache.camel.CamelContext;
+
 /**
  * A lifecycle listener to receive callbacks when the main is started and stopped.
  */
 public interface MainListener {
 
     /**
-     * Callback before the CamelContext(s) is being started.
+     * Callback before the CamelContext(s) is being created and started.
      *
      * @param main  the main instance
      */
     void beforeStart(MainSupport main);
 
     /**
+     * Callback to configure <b>each</b> created CamelContext.
+     * <p/>
+     * Notice this callback will be invoked for <b>each</b> CamelContext and
therefore can be invoked
+     * multiple times if there is 2 or more CamelContext's being created.
+     *
+     * @param context the created CamelContext
+     */
+    void configure(CamelContext context);
+
+    /**
      * Callback after the CamelContext(s) has been started.
      *
      * @param main  the main instance

http://git-wip-us.apache.org/repos/asf/camel/blob/ba631d53/camel-core/src/main/java/org/apache/camel/main/MainListenerSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/main/MainListenerSupport.java b/camel-core/src/main/java/org/apache/camel/main/MainListenerSupport.java
index 6dda55b..1a31b37 100644
--- a/camel-core/src/main/java/org/apache/camel/main/MainListenerSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/main/MainListenerSupport.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.main;
 
+import org.apache.camel.CamelContext;
+
 /**
  * A useful base class for {@link org.apache.camel.main.MainListener} implementations.
  */
@@ -25,6 +27,10 @@ public class MainListenerSupport implements MainListener {
         // noop
     }
 
+    public void configure(CamelContext context) {
+        // noop
+    }
+
     public void afterStart(MainSupport main) {
         // noop
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/ba631d53/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/main/MainSupport.java b/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
index de0fbdf..69d4589 100644
--- a/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/main/MainSupport.java
@@ -419,6 +419,10 @@ public abstract class MainSupport extends ServiceSupport {
         for (RouteBuilder routeBuilder : routeBuilders) {
             camelContext.addRoutes(routeBuilder);
         }
+        // allow to do configuration before its started
+        for (MainListener listener : listeners) {
+            listener.configure(camelContext);
+        }
     }
 
     public void addRouteBuilder(RouteBuilder routeBuilder) {


Mime
View raw message