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 2021/01/23 11:12:24 UTC
[camel] 03/09: CAMEL-15844: camel-core - Optimize Route to move its
setup (init) logic to the init phase of CamelContext,
so they are initialized together.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 11a78f573e3de939d417ade4f701a9639296ec51
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 22 13:52:31 2021 +0100
CAMEL-15844: camel-core - Optimize Route to move its setup (init) logic to the init phase of CamelContext, so they are initialized together.
---
.../camel/impl/engine/AbstractCamelContext.java | 22 ++++++++++++++--------
.../org/apache/camel/impl/engine/RouteService.java | 12 +++++-------
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 036e98b..2549d74 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -314,8 +314,8 @@ public abstract class AbstractCamelContext extends BaseService
private ShutdownRoute shutdownRoute = ShutdownRoute.Default;
private ShutdownRunningTask shutdownRunningTask = ShutdownRunningTask.CompleteCurrentTaskOnly;
private Debugger debugger;
+ private long initTaken;
private long startDate;
- private long bootDate;
private SSLContextParameters sslContextParameters;
@@ -2535,8 +2535,6 @@ public abstract class AbstractCamelContext extends BaseService
@Override
public void doBuild() throws Exception {
- bootDate = System.currentTimeMillis();
-
// auto-detect step recorder from classpath if none has been explicit configured
if (startupStepRecorder.getClass().getSimpleName().equals("DefaultStartupStepRecorder")) {
StartupStepRecorder fr = getBootstrapFactoryFinder()
@@ -2593,6 +2591,8 @@ public abstract class AbstractCamelContext extends BaseService
@Override
public void doInit() throws Exception {
+ StopWatch watch = new StopWatch();
+
StartupStep step = startupStepRecorder.beginStep(CamelContext.class, null, "Initializing CamelContext");
// init the route controller
@@ -2738,6 +2738,9 @@ public abstract class AbstractCamelContext extends BaseService
EventHelper.notifyCamelContextInitialized(this);
startupStepRecorder.endStep(step);
+
+ initTaken = watch.taken();
+ LOG.info("Apache Camel {} ({}) initialized in {}", getVersion(), getName(), TimeUtils.printDuration(initTaken));
}
@Override
@@ -2765,7 +2768,9 @@ public abstract class AbstractCamelContext extends BaseService
}
protected void doStartContext() throws Exception {
- LOG.info("Apache Camel {} ({}) is starting", getVersion(), getName());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Apache Camel {} ({}) is starting", getVersion(), getName());
+ }
vetoed = null;
startDate = System.currentTimeMillis();
stopWatch.restart();
@@ -2874,9 +2879,11 @@ public abstract class AbstractCamelContext extends BaseService
}
}
- String start = TimeUtils.printDuration(stopWatch.taken());
- String boot = TimeUtils.printDuration(new StopWatch(bootDate).taken());
- LOG.info("Apache Camel {} ({}) started in {} (incl boot {})", getVersion(), getName(), start, boot);
+ long taken = stopWatch.taken();
+ long total = initTaken + taken;
+ String start = TimeUtils.printDuration(taken);
+ String boot = TimeUtils.printDuration(total);
+ LOG.info("Apache Camel {} ({}) started in {} (with init {})", getVersion(), getName(), start, boot);
}
protected void doStartCamel() throws Exception {
@@ -3176,7 +3183,6 @@ public abstract class AbstractCamelContext extends BaseService
// and clear start date
startDate = 0;
- bootDate = 0;
// Call all registered trackers with this context
// Note, this may use a partially constructed object
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java
index 2b9fc9f..2bf2261 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/RouteService.java
@@ -168,7 +168,7 @@ public class RouteService extends ChildServiceSupport {
list.add(service);
}
}
- initChildServices(route, list);
+ initChildServices(list);
}
}
@@ -249,8 +249,7 @@ public class RouteService extends ChildServiceSupport {
}
try (MDCHelper mdcHelper = new MDCHelper(route.getId())) {
- // TODO: childrenService + some more
- // gather list of services to stop as we need to start child services as well
+ // gather list of services to stop
Set<Service> services = gatherChildServices();
// stop services
@@ -285,8 +284,7 @@ public class RouteService extends ChildServiceSupport {
@Override
protected void doShutdown() {
try (MDCHelper mdcHelper = new MDCHelper(route.getId())) {
- // TODO: childrenService + some more
- // gather list of services to stop as we need to start child services as well
+ // gather list of services to shutdown
Set<Service> services = gatherChildServices();
// shutdown services
@@ -351,9 +349,10 @@ public class RouteService extends ChildServiceSupport {
}
}
- protected void initChildServices(Route route, List<Service> services) {
+ protected void initChildServices(List<Service> services) {
for (Service service : services) {
ServiceHelper.initService(service);
+ // add and remember as child service
addChildService(service);
}
}
@@ -385,7 +384,6 @@ public class RouteService extends ChildServiceSupport {
* Gather all child services
*/
private Set<Service> gatherChildServices() {
- // gather list of services to stop as we need to start child services as well
List<Service> services = new ArrayList<>(route.getServices());
// also get route scoped services
doGetRouteServices(services);