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:45 UTC
[camel] 01/03: (chores) camel-base-engine: cleanup lambdas for improved readability
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