From 8f8ff424f1b2de2eef97985136253ebf353fd09a Mon Sep 17 00:00:00 2001 From: Claus Ibsen Date: Sat, 12 Oct 2024 22:55:38 +0200 Subject: [PATCH] CAMEL-21338: camel-core - Add boot startup time in INFO logging so it show the total time incl boot camel-jbang/camel-main/camel-spring-boot that may take some time also. --- .../impl/engine/AbstractCamelContext.java | 2 +- .../apache/camel/main/BaseMainSupport.java | 34 ++++++++++++------- .../main/java/org/apache/camel/main/Main.java | 2 -- .../org/apache/camel/main/MainSupport.java | 2 -- 4 files changed, 22 insertions(+), 18 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 a874ef3a18b59..4bca692a410d4 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 @@ -2749,7 +2749,7 @@ protected void logStartSummary() { } } String msg = String.format("Apache Camel %s (%s) started in %s (build:%s init:%s start:%s", getVersion(), - camelContextExtension.getName(), total, built, init, start); + camelContextExtension.getName(), total, built, init, start); if (boot != null) { msg += " boot:" + boot; } diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java index 161ca88c86f84..0f06523176fef 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java @@ -739,19 +739,25 @@ protected void postProcessCamelContext(CamelContext camelContext) throws Excepti // ensure camel context is build camelContext.build(); - for (MainListener listener : listeners) { - listener.beforeInitialize(this); - } - - // allow doing custom configuration before camel is started - for (MainListener listener : listeners) { - listener.beforeConfigure(this); - } - // we want to capture startup events for import tasks during main bootstrap StartupStepRecorder recorder = camelContext.getCamelContextExtension().getStartupStepRecorder(); StartupStep step; + if (!listeners.isEmpty()) { + step = recorder.beginStep(BaseMainSupport.class, "beforeInitialize", "MainListener"); + for (MainListener listener : listeners) { + listener.beforeInitialize(this); + } + recorder.endStep(step); + + // allow doing custom configuration before camel is started + step = recorder.beginStep(BaseMainSupport.class, "beforeConfigure", "MainListener"); + for (MainListener listener : listeners) { + listener.beforeConfigure(this); + } + recorder.endStep(step); + } + if (standalone) { step = recorder.beginStep(BaseMainSupport.class, "autoconfigure", "Auto Configure"); autoconfigure(camelContext); @@ -774,11 +780,13 @@ protected void postProcessCamelContext(CamelContext camelContext) throws Excepti postProcessCamelRegistry(camelContext, mainConfigurationProperties); // allow doing custom configuration before camel is started - step = recorder.beginStep(BaseMainSupport.class, "afterConfigure", "MainListener"); - for (MainListener listener : listeners) { - listener.afterConfigure(this); + if (!listeners.isEmpty()) { + step = recorder.beginStep(BaseMainSupport.class, "afterConfigure", "MainListener"); + for (MainListener listener : listeners) { + listener.afterConfigure(this); + } + recorder.endStep(step); } - recorder.endStep(step); // we want to log the property placeholder summary after routes has been started, // but before camel context logs that it has been started, so we need to use an event listener diff --git a/core/camel-main/src/main/java/org/apache/camel/main/Main.java b/core/camel-main/src/main/java/org/apache/camel/main/Main.java index bdab0232182ea..fbdf88d436aef 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/Main.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/Main.java @@ -20,9 +20,7 @@ import org.apache.camel.CamelConfiguration; import org.apache.camel.CamelContext; -import org.apache.camel.ContextEvents; import org.apache.camel.ProducerTemplate; -import org.apache.camel.clock.EventClock; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.spi.Registry; diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java index fd508d6c75b55..ffb89845d66e2 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java @@ -24,11 +24,9 @@ import org.apache.camel.ContextEvents; import org.apache.camel.ProducerTemplate; import org.apache.camel.clock.Clock; -import org.apache.camel.clock.ContextClock; import org.apache.camel.spi.EventNotifier; import org.apache.camel.support.ResetableClock; import org.apache.camel.support.service.ServiceHelper; -import org.apache.camel.util.StopWatch; import org.slf4j.Logger; import org.slf4j.LoggerFactory;