You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/03/28 18:59:44 UTC

[camel] branch main updated (ecbb0f165b4 -> c6d0b74911a)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from ecbb0f165b4 CAMEL-19194: camel-crypto: Remove not used method that was faulty.
     new 6bc4dd246da (chores) camel-base-engine: cleanup lambdas for improved readability
     new 7b7f3850de8 (chores) camel-base-engine: log message cleanups
     new c6d0b74911a (chores) camel-base-engine: other minor cleanups

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../camel/impl/engine/AbstractCamelContext.java    | 178 ++++++++++-----------
 1 file changed, 85 insertions(+), 93 deletions(-)


[camel] 01/03: (chores) camel-base-engine: cleanup lambdas for improved readability

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 6bc4dd246da762ac421995aac1862fa26b28ff67
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Mar 28 17:06:52 2023 +0200

    (chores) camel-base-engine: cleanup lambdas for improved readability
---
 .../camel/impl/engine/AbstractCamelContext.java    | 143 ++++++++++-----------
 1 file changed, 67 insertions(+), 76 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 a34dbbbfa54..207510cf7ef 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
@@ -273,7 +273,7 @@ public abstract class AbstractCamelContext extends BaseService
     private final List<RouteStartupOrder> routeStartupOrder = new ArrayList<>();
     private final StopWatch stopWatch = new StopWatch(false);
     private final Map<Class<?>, Object> extensions = new ConcurrentHashMap<>();
-    private final ThreadLocal<Set<String>> componentsInCreation = ThreadLocal.withInitial(() -> new HashSet<>());
+    private final ThreadLocal<Set<String>> componentsInCreation = ThreadLocal.withInitial(HashSet::new);
     private VetoCamelContextStartException vetoed;
     private String managementName;
     private ClassLoader applicationContextClassLoader;
@@ -385,12 +385,7 @@ public abstract class AbstractCamelContext extends BaseService
         this.bootstraps.add(new DefaultServiceBootstrapCloseable(this));
 
         // add a cleaner for FactoryFinder used only when bootstrapping the context
-        this.bootstraps.add(new BootstrapCloseable() {
-            @Override
-            public void close() throws IOException {
-                bootstrapFactories.clear();
-            }
-        });
+        this.bootstraps.add(bootstrapFactories::clear);
 
         this.internalServiceManager = new InternalServiceManager(this, internalRouteStartupManager, startupListeners);
 
@@ -592,12 +587,9 @@ public abstract class AbstractCamelContext extends BaseService
             final AtomicBoolean created = new AtomicBoolean();
 
             // atomic operation to get/create a component. Avoid global locks.
-            final Component component = components.computeIfAbsent(name, new Function<String, Component>() {
-                @Override
-                public Component apply(String comp) {
-                    created.set(true);
-                    return initComponent(name, autoCreateComponents);
-                }
+            final Component component = components.computeIfAbsent(name, comp -> {
+                created.set(true);
+                return initComponent(name, autoCreateComponents);
             });
 
             // Start the component after its creation as if it is a component proxy
@@ -1575,53 +1567,52 @@ public abstract class AbstractCamelContext extends BaseService
     public Language resolveLanguage(String name) {
         LOG.debug("Resolving language: {}", name);
 
-        return languages.computeIfAbsent(name, new Function<String, Language>() {
-            @Override
-            public Language apply(String s) {
-                StartupStep step = null;
-                // only record startup step during startup (not started)
-                if (!isStarted() && startupStepRecorder.isEnabled()) {
-                    step = startupStepRecorder.beginStep(Language.class, name, "Resolve Language");
-                }
-
-                final CamelContext camelContext = getCamelContextReference();
+        return languages.computeIfAbsent(name, s -> doResolveLanguage(name));
+    }
 
-                // as first iteration, check if there is a language instance for the given name
-                // bound to the registry
-                Language language = ResolverHelper.lookupLanguageInRegistryWithFallback(camelContext, name);
+    private Language doResolveLanguage(String name) {
+        StartupStep step = null;
+        // only record startup step during startup (not started)
+        if (!isStarted() && startupStepRecorder.isEnabled()) {
+            step = startupStepRecorder.beginStep(Language.class, name, "Resolve Language");
+        }
 
-                if (language == null) {
-                    // language not known, then use resolver
-                    language = camelContextExtension.getLanguageResolver().resolveLanguage(name, camelContext);
-                }
+        final CamelContext camelContext = getCamelContextReference();
 
-                if (language != null) {
-                    if (language instanceof Service) {
-                        try {
-                            Service service = (Service) language;
-                            // init service first
-                            CamelContextAware.trySetCamelContext(service, camelContext);
-                            ServiceHelper.initService(service);
-                            startService(service);
-                        } catch (Exception e) {
-                            throw RuntimeCamelException.wrapRuntimeCamelException(e);
-                        }
-                    }
+        // as first iteration, check if there is a language instance for the given name
+        // bound to the registry
+        Language language = ResolverHelper.lookupLanguageInRegistryWithFallback(camelContext, name);
 
-                    // inject CamelContext if aware
-                    CamelContextAware.trySetCamelContext(language, camelContext);
+        if (language == null) {
+            // language not known, then use resolver
+            language = camelContextExtension.getLanguageResolver().resolveLanguage(name, camelContext);
+        }
 
-                    for (LifecycleStrategy strategy : lifecycleStrategies) {
-                        strategy.onLanguageCreated(name, language);
-                    }
+        if (language != null) {
+            if (language instanceof Service) {
+                try {
+                    Service service = (Service) language;
+                    // init service first
+                    CamelContextAware.trySetCamelContext(service, camelContext);
+                    ServiceHelper.initService(service);
+                    startService(service);
+                } catch (Exception e) {
+                    throw RuntimeCamelException.wrapRuntimeCamelException(e);
                 }
+            }
 
-                if (step != null) {
-                    startupStepRecorder.endStep(step);
-                }
-                return language;
+            // inject CamelContext if aware
+            CamelContextAware.trySetCamelContext(language, camelContext);
+
+            for (LifecycleStrategy strategy : lifecycleStrategies) {
+                strategy.onLanguageCreated(name, language);
             }
-        });
+        }
+
+        if (step != null) {
+            startupStepRecorder.endStep(step);
+        }
+        return language;
     }
 
     // Properties
@@ -3656,37 +3647,37 @@ public abstract class AbstractCamelContext extends BaseService
         applicationContextClassLoader = classLoader;
     }
 
-    @Override
-    public DataFormat resolveDataFormat(String name) {
-        final DataFormat answer = dataformats.computeIfAbsent(name, s -> {
-            StartupStep step = null;
-            // only record startup step during startup (not started)
-            if (!isStarted() && startupStepRecorder.isEnabled()) {
-                step = startupStepRecorder.beginStep(DataFormat.class, name, "Resolve DataFormat");
-            }
+    private DataFormat doResolveDataFormat(String name) {
+        StartupStep step = null;
+        // only record startup step during startup (not started)
+        if (!isStarted() && startupStepRecorder.isEnabled()) {
+            step = startupStepRecorder.beginStep(DataFormat.class, name, "Resolve DataFormat");
+        }
 
-            DataFormat df = Optional
-                    .ofNullable(ResolverHelper.lookupDataFormatInRegistryWithFallback(getCamelContextReference(), name))
-                    .orElseGet(() -> camelContextExtension.getDataFormatResolver().createDataFormat(name,
-                            getCamelContextReference()));
+        final DataFormat df = Optional
+                .ofNullable(ResolverHelper.lookupDataFormatInRegistryWithFallback(getCamelContextReference(), name))
+                .orElseGet(() -> camelContextExtension.getDataFormatResolver().createDataFormat(name,
+                        getCamelContextReference()));
 
-            if (df != null) {
-                // inject CamelContext if aware
-                CamelContextAware.trySetCamelContext(df, getCamelContextReference());
+        if (df != null) {
+            // inject CamelContext if aware
+            CamelContextAware.trySetCamelContext(df, getCamelContextReference());
 
-                for (LifecycleStrategy strategy : lifecycleStrategies) {
-                    strategy.onDataFormatCreated(name, df);
-                }
+            for (LifecycleStrategy strategy : lifecycleStrategies) {
+                strategy.onDataFormatCreated(name, df);
             }
+        }
 
-            if (step != null) {
-                startupStepRecorder.endStep(step);
-            }
+        if (step != null) {
+            startupStepRecorder.endStep(step);
+        }
 
-            return df;
-        });
+        return df;
+    }
 
-        return answer;
+    @Override
+    public DataFormat resolveDataFormat(String name) {
+        return dataformats.computeIfAbsent(name, s -> doResolveDataFormat(name));
     }
 
     @Override


[camel] 03/03: (chores) camel-base-engine: other minor cleanups

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c6d0b74911aa665181cd10bedb35407fcef0e955
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Mar 28 17:19:47 2023 +0200

    (chores) camel-base-engine: other minor cleanups
    
    - use final in a few variables
    - avoid unnecessary null check
    - log conditionally to avoid some overhead
    - removed unnecessary return call
---
 .../camel/impl/engine/AbstractCamelContext.java    | 28 ++++++++++++----------
 1 file changed, 15 insertions(+), 13 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 7b34f5c8b0f..17e696579a7 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
@@ -40,7 +40,6 @@ import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.Function;
 import java.util.function.Supplier;
 
 import org.apache.camel.CamelContext;
@@ -2118,7 +2117,7 @@ public abstract class AbstractCamelContext extends BaseService
         try {
             super.init();
         } catch (RuntimeCamelException e) {
-            if (e.getCause() != null && e.getCause() instanceof VetoCamelContextStartException) {
+            if (e.getCause() instanceof VetoCamelContextStartException) {
                 vetoed = (VetoCamelContextStartException) e.getCause();
             } else {
                 throw e;
@@ -2130,7 +2129,6 @@ public abstract class AbstractCamelContext extends BaseService
             LOG.info("CamelContext ({}) vetoed to not initialize due to: {}", camelContextExtension.getName(),
                     vetoed.getMessage());
             failOnStartup(vetoed);
-            return;
         }
     }
 
@@ -2194,7 +2192,7 @@ public abstract class AbstractCamelContext extends BaseService
 
     @Override
     public void doBuild() throws Exception {
-        StopWatch watch = new StopWatch();
+        final StopWatch watch = new StopWatch();
 
         // auto-detect step recorder from classpath if none has been explicit configured
         if (startupStepRecorder.getClass().getSimpleName().equals("DefaultStartupStepRecorder")) {
@@ -2260,9 +2258,11 @@ public abstract class AbstractCamelContext extends BaseService
 
         startupStepRecorder.endStep(step);
 
-        buildTaken = watch.taken();
-        LOG.debug("Apache Camel {} ({}) built in {}", getVersion(), camelContextExtension.getName(),
-                TimeUtils.printDuration(buildTaken, true));
+        if (LOG.isDebugEnabled()) {
+            buildTaken = watch.taken();
+            LOG.debug("Apache Camel {} ({}) built in {}", getVersion(), camelContextExtension.getName(),
+                    TimeUtils.printDuration(buildTaken, true));
+        }
     }
 
     protected void resetBuildTime() {
@@ -2272,7 +2272,7 @@ public abstract class AbstractCamelContext extends BaseService
 
     @Override
     public void doInit() throws Exception {
-        StopWatch watch = new StopWatch();
+        final StopWatch watch = new StopWatch();
 
         vetoed = null;
 
@@ -2478,9 +2478,11 @@ public abstract class AbstractCamelContext extends BaseService
 
         startupStepRecorder.endStep(step);
 
-        initTaken = watch.taken();
-        LOG.debug("Apache Camel {} ({}) initialized in {}", getVersion(), camelContextExtension.getName(),
-                TimeUtils.printDuration(initTaken, true));
+        if (LOG.isDebugEnabled()) {
+            initTaken = watch.taken();
+            LOG.debug("Apache Camel {} ({}) initialized in {}", getVersion(), camelContextExtension.getName(),
+                    TimeUtils.printDuration(initTaken, true));
+        }
     }
 
     @Override
@@ -2548,7 +2550,7 @@ public abstract class AbstractCamelContext extends BaseService
                 return;
             } else {
                 LOG.error("Error starting CamelContext ({}) due to exception thrown: {}", camelContextExtension.getName(),
-                          e.getMessage(), e);
+                        e.getMessage(), e);
                 throw RuntimeCamelException.wrapRuntimeException(e);
             }
         }
@@ -2827,7 +2829,7 @@ public abstract class AbstractCamelContext extends BaseService
             // log if stream caching is not in use as this can help people to
             // enable it if they use streams
             LOG.debug("StreamCaching is not in use. If using streams then it's recommended to enable stream caching."
-                      + " See more details at http://camel.apache.org/stream-caching.html");
+                      + " See more details at https://camel.apache.org/stream-caching.html");
         }
 
         if (isAllowUseOriginalMessage()) {


[camel] 02/03: (chores) camel-base-engine: log message cleanups

Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7b7f3850de809ac3bb390b36f62e32c73a1ae215
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Mar 28 17:07:09 2023 +0200

    (chores) camel-base-engine: log message cleanups
---
 .../java/org/apache/camel/impl/engine/AbstractCamelContext.java  | 9 ++++-----
 1 file changed, 4 insertions(+), 5 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 207510cf7ef..7b34f5c8b0f 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
@@ -703,7 +703,7 @@ public abstract class AbstractCamelContext extends BaseService
             try {
                 stopServices(oldComponent);
             } catch (Exception e) {
-                LOG.warn("Error stopping component " + oldComponent + ". This exception will be ignored.", e);
+                LOG.warn("Error stopping component {}. This exception will be ignored.", oldComponent, e);
             }
             for (LifecycleStrategy strategy : lifecycleStrategies) {
                 strategy.onComponentRemove(componentName, oldComponent);
@@ -767,7 +767,7 @@ public abstract class AbstractCamelContext extends BaseService
                     try {
                         stopServices(oldEndpoint);
                     } catch (Exception e) {
-                        LOG.warn("Error stopping endpoint " + oldEndpoint + ". This exception will be ignored.", e);
+                        LOG.warn("Error stopping endpoint {}. This exception will be ignored.", oldEndpoint, e);
                     }
                     answer.add(oldEndpoint);
                     toRemove.add(entry.getKey());
@@ -2547,9 +2547,8 @@ public abstract class AbstractCamelContext extends BaseService
                 vetoed = veto;
                 return;
             } else {
-                LOG.error("Error starting CamelContext (" + camelContextExtension.getName() + ") due to exception thrown: "
-                          + e.getMessage(),
-                        e);
+                LOG.error("Error starting CamelContext ({}) due to exception thrown: {}", camelContextExtension.getName(),
+                          e.getMessage(), e);
                 throw RuntimeCamelException.wrapRuntimeException(e);
             }
         }