lburgazzoli commented on a change in pull request #4998:
URL: https://github.com/apache/camel/pull/4998#discussion_r569269828



##########
File path: 
core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoutesLoader.java
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.engine;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.spi.FactoryFinder;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.spi.RoutesBuilderLoader;
+import org.apache.camel.spi.RoutesLoader;
+import org.apache.camel.spi.annotations.JdkService;
+import org.apache.camel.util.FileUtil;
+import org.apache.camel.util.ObjectHelper;
+
+@JdkService(RoutesLoader.FACTORY)
+public class DefaultRoutesLoader implements RoutesLoader {
+    private CamelContext camelContext;
+
+    public DefaultRoutesLoader() {
+    }
+
+    public DefaultRoutesLoader(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    @Override
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
+    @Override
+    public Collection<RoutesBuilder> findRoutesBuilders(Collection<Resource> 
resources) throws Exception {
+        List<RoutesBuilder> answer = new ArrayList<>(resources.size());
+
+        for (Resource resource : resources) {
+            // language is derived from the file extension
+            final String extension = FileUtil.onlyExt(resource.getLocation(), 
true);
+
+            if (ObjectHelper.isEmpty(extension)) {
+                throw new IllegalArgumentException("Unable to determine 
extension for resource: " + resource.getLocation());
+            }
+
+            answer.add(getLoader(extension).loadRoutesBuilder(resource));
+        }
+
+        return answer;
+    }
+
+    /**
+     *
+     * @param  extension
+     * @return
+     */
+    private RoutesBuilderLoader getLoader(String extension) {
+        RoutesBuilderLoader answer = 
getCamelContext().getRegistry().lookupByNameAndType(extension, 
RoutesBuilderLoader.class);
+
+        if (answer == null) {
+            final ExtendedCamelContext ecc = 
getCamelContext(ExtendedCamelContext.class);
+            final FactoryFinder finder = 
ecc.getFactoryFinder(RoutesBuilderLoader.FACTORY_PATH);

Review comment:
       Added: `FactoryFinder getBootstrapFactoryFinder(String path);`
   I see that the `AbstractCamelContext` has a cache for the standard 
factories, as example:
   
   ```java
       @Override
       public FactoryFinder getFactoryFinder(String path) {
           return factories.computeIfAbsent(path, this::createFactoryFinder);
       }
   
       protected FactoryFinder createFactoryFinder(String path) {
           return 
getFactoryFinderResolver().resolveFactoryFinder(getClassResolver(), path);
       }
   ```
   
   And I've implemented the same logic for `getBootstrapFactoryFinder(string)` 
but is it right ? maybe we should clean up the bootstrap factories cache after 
bootsrtap or even not cache them so the GC can claim the instances. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to