Skip to content
Permalink
Browse files

Improved: Delay the construction of component classpaths

(OFBIZ-11264)

The list of component classpath elements was constructed iteratively
while loading components. This list was additionally used to check if
a component was actually loaded.  This implementation was leading to
hard to understand code that has been replaced by a more appropriate
‘LinkedHashSet’ object.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1869182 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Oct 30, 2019
1 parent 7093974 commit aeebf807b8b2b8d60559092293e3799e2c3ac5bf
Showing with 13 additions and 12 deletions.
  1. +13 −12 framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
@@ -26,9 +26,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -62,7 +62,8 @@

private String name;
private final AtomicBoolean loaded = new AtomicBoolean(false);
private final List<Classpath> componentsClassPath = new ArrayList<>();
/** The set of ready components in their inverse dependency order. */
private final LinkedHashSet<ComponentConfig> readyComponents = new LinkedHashSet<>();
private static Map<String, List<DependsOnInfo>> toBeLoadedComponents = new ConcurrentHashMap<>();

@Override
@@ -80,6 +81,11 @@ public void init(List<StartupCommand> ofbizCommands, String name, String configF
} catch (IOException | ComponentException e) {
throw new ContainerException(e);
}
String fmt = "Added class path for component : [%s]";
List<Classpath> componentsClassPath = readyComponents.stream()
.peek(cmpnt -> Debug.logInfo(String.format(fmt, cmpnt.getComponentName()), module))
.map(cmpnt -> buildClasspathFromComponentConfig(cmpnt))
.collect(Collectors.toList());
loadClassPathForAllComponents(componentsClassPath);
Debug.logInfo("All components loaded", module);
}
@@ -237,9 +243,8 @@ private void loadComponentWithDependency() throws IOException, ComponentExceptio
Debug.logInfo(msg, module);
}
if (UtilValidate.isEmpty(dependencyList)) {
componentsClassPath.add(buildClasspathFromComponentConfig(config));
readyComponents.add(config);
toBeLoadedComponents.replace(config.getComponentName(), dependencyList);
Debug.logInfo("Added class path for component : [" + config.getComponentName() + "]", module);
}
} else {
Debug.logInfo("Not loading component [" + config.getComponentName() + "] because it's disabled", module);
@@ -280,8 +285,7 @@ private void loadSingleComponent(ComponentConfig config) throws ComponentExcepti
if (config.enabled()) {
List<DependsOnInfo> dependencyList = checkDependencyForComponent(config);
if (UtilValidate.isEmpty(dependencyList)) {
componentsClassPath.add(buildClasspathFromComponentConfig(config));
Debug.logInfo("Added class path for component : [" + config.getComponentName() + "]", module);
readyComponents.add(config);
}
} else {
Debug.logInfo("Not loading component [" + config.getComponentName() + "] because it's disabled", module);
@@ -302,12 +306,9 @@ private void loadSingleComponent(ComponentConfig config) throws ComponentExcepti
for (DependsOnInfo dependency : dependencyList) {
Debug.logInfo("Component : " + config.getComponentName() + " is Dependent on " + dependency.componentName, module);
ComponentConfig componentConfig = ComponentConfig.getComponentConfig(String.valueOf(dependency.componentName));
Classpath dependentComponentClasspath = buildClasspathFromComponentConfig(componentConfig);
componentsClassPath.forEach(componentClassPath -> {
if (Arrays.equals(componentClassPath.toString().split(":"), dependentComponentClasspath.toString().split(":"))) {
resolvedDependencyList.add(dependency);
}
});
if (readyComponents.contains(componentConfig)) {
resolvedDependencyList.add(dependency);
}
}
resolvedDependencyList.forEach(resolvedDependency -> Debug.logInfo("Resolved : " + resolvedDependency.componentName + " Dependency for Component " + config.getComponentName(), module));
dependencyList.removeAll(resolvedDependencyList);

0 comments on commit aeebf80

Please sign in to comment.
You can’t perform that action at this time.