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 51f5d412579d2b4ab1737e01cdc65a037ac7cda0 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Nov 2 20:19:18 2020 +0100 CAMEL-15784: camel-core - Optimize with bootstrap factory finder. --- .../org/apache/camel/spi/FactoryFinderResolver.java | 19 +++++++++++++++++++ .../camel/impl/engine/AbstractCamelContext.java | 5 +++-- .../impl/engine/DefaultFactoryFinderResolver.java | 4 ++++ .../engine/DefaultServiceBootstrapCloseable.java | 20 ++++++++++---------- .../camel/processor/DefaultProcessorFactory.java | 8 +++++--- 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java b/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java index 695be6c5..c75ad6c 100644 --- a/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java +++ b/core/camel-api/src/main/java/org/apache/camel/spi/FactoryFinderResolver.java @@ -32,6 +32,16 @@ public interface FactoryFinderResolver { } /** + * Creates a new bootstrap factory finder using a default resource path. + * + * @param classResolver the class resolver to use + * @return a factory finder. + */ + default FactoryFinder resolveBootstrapFactoryFinder(ClassResolver classResolver) { + return resolveBootstrapFactoryFinder(classResolver, FactoryFinder.DEFAULT_PATH); + } + + /** * Creates a new factory finder. * * @param classResolver the class resolver to use @@ -40,4 +50,13 @@ public interface FactoryFinderResolver { */ FactoryFinder resolveFactoryFinder(ClassResolver classResolver, String resourcePath); + /** + * Creates a new factory finder. + * + * @param classResolver the class resolver to use + * @param resourcePath the resource path as base to lookup files within + * @return a factory finder. + */ + FactoryFinder resolveBootstrapFactoryFinder(ClassResolver classResolver, String resourcePath); + } 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 9b9ff49..cf50377 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 @@ -3385,7 +3385,8 @@ public abstract class AbstractCamelContext extends BaseService synchronized (lock) { if (bootstrapConfigurerResolver == null) { bootstrapConfigurerResolver = new BootstrapConfigurerResolver( - new BootstrapFactoryFinder(getClassResolver(), ConfigurerResolver.RESOURCE_PATH)); + getFactoryFinderResolver().resolveBootstrapFactoryFinder(getClassResolver(), + ConfigurerResolver.RESOURCE_PATH)); } } } @@ -3402,7 +3403,7 @@ public abstract class AbstractCamelContext extends BaseService if (bootstrapFactoryFinder == null) { synchronized (lock) { if (bootstrapFactoryFinder == null) { - bootstrapFactoryFinder = new BootstrapFactoryFinder(getClassResolver(), FactoryFinder.DEFAULT_PATH); + bootstrapFactoryFinder = getFactoryFinderResolver().resolveBootstrapFactoryFinder(getClassResolver()); } } } diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultFactoryFinderResolver.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultFactoryFinderResolver.java index 027dead..e44cad2 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultFactoryFinderResolver.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultFactoryFinderResolver.java @@ -30,4 +30,8 @@ public class DefaultFactoryFinderResolver implements FactoryFinderResolver { return new DefaultFactoryFinder(classResolver, resourcePath); } + @Override + public FactoryFinder resolveBootstrapFactoryFinder(ClassResolver classResolver, String resourcePath) { + return new BootstrapFactoryFinder(classResolver, resourcePath); + } } diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultServiceBootstrapCloseable.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultServiceBootstrapCloseable.java index 6d37eca..7394d33 100644 --- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultServiceBootstrapCloseable.java +++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultServiceBootstrapCloseable.java @@ -75,27 +75,27 @@ public class DefaultServiceBootstrapCloseable implements BootstrapCloseable { } camelContext.setBootstrapConfigurerResolver(null); - // clear bootstrap factory finder - FactoryFinder ff = camelContext.getBootstrapFactoryFinder(); - if (ff instanceof BootstrapCloseable) { + // clear processor factory + ProcessorFactory pf = camelContext.getProcessorFactory(); + if (pf instanceof BootstrapCloseable) { try { - ((BootstrapCloseable) ff).close(); + ((BootstrapCloseable) pf).close(); } catch (Exception e) { LOG.warn("Error during closing bootstrap service. This exception is ignored", e); } } - camelContext.setBootstrapFactoryFinder(null); + camelContext.setProcessorFactory(null); - // clear processor factory - ProcessorFactory pf = camelContext.getProcessorFactory(); - if (pf instanceof BootstrapCloseable) { + // clear bootstrap factory finder + FactoryFinder ff = camelContext.getBootstrapFactoryFinder(); + if (ff instanceof BootstrapCloseable) { try { - ((BootstrapCloseable) pf).close(); + ((BootstrapCloseable) ff).close(); } catch (Exception e) { LOG.warn("Error during closing bootstrap service. This exception is ignored", e); } } - camelContext.setProcessorFactory(null); + camelContext.setBootstrapFactoryFinder(null); } } diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/DefaultProcessorFactory.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/DefaultProcessorFactory.java index 68db7de..8ffab7a 100644 --- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/DefaultProcessorFactory.java +++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/DefaultProcessorFactory.java @@ -23,11 +23,11 @@ import java.util.concurrent.ExecutorService; import org.apache.camel.CamelContext; import org.apache.camel.ExchangePattern; import org.apache.camel.Expression; +import org.apache.camel.ExtendedCamelContext; import org.apache.camel.NamedNode; import org.apache.camel.NoFactoryAvailableException; import org.apache.camel.Processor; import org.apache.camel.Route; -import org.apache.camel.impl.engine.BootstrapFactoryFinder; import org.apache.camel.spi.BootstrapCloseable; import org.apache.camel.spi.FactoryFinder; import org.apache.camel.spi.ProcessorFactory; @@ -64,7 +64,8 @@ public class DefaultProcessorFactory implements ProcessorFactory, BootstrapClose public Processor createChildProcessor(Route route, NamedNode definition, boolean mandatory) throws Exception { String name = definition.getClass().getSimpleName(); if (finder == null) { - finder = new BootstrapFactoryFinder(route.getCamelContext().getClassResolver(), RESOURCE_PATH); + finder = route.getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinderResolver() + .resolveBootstrapFactoryFinder(route.getCamelContext().getClassResolver(), RESOURCE_PATH); } try { Object object = finder.newInstance(name).orElse(null); @@ -83,7 +84,8 @@ public class DefaultProcessorFactory implements ProcessorFactory, BootstrapClose public Processor createProcessor(Route route, NamedNode definition) throws Exception { String name = definition.getClass().getSimpleName(); if (finder == null) { - finder = new BootstrapFactoryFinder(route.getCamelContext().getClassResolver(), RESOURCE_PATH); + finder = route.getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinderResolver() + .resolveBootstrapFactoryFinder(route.getCamelContext().getClassResolver(), RESOURCE_PATH); } ProcessorFactory pc = finder.newInstance(name, ProcessorFactory.class).orElse(null); if (pc != null) {