Skip to content
Permalink
Browse files

Improved: Turn ‘DependsOnInfo’ into a String

(OFBIZ-11264)

`depends-on` XML tag doesn't have any `loader` or `location` attribute so
DependsOnInfo does not need to extend ResourceInfo.

When removing the class derivation, DependsOnInfo now becomes a simple box
containing a String attribute. In order to make the manipulation of dependency
information simpler, the attribute is now inlined as a simple String value.

Thanks: Samuel Trégouët for your contribution


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1869185 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Oct 30, 2019
1 parent e5592a9 commit 7d9080702dd77f224e3cbba640fb1181eb7ea7fc
@@ -262,7 +262,7 @@ public static WebappInfo getWebAppInfo(String serverName, String contextRoot) {
private final boolean enabled;
private final Map<String, ResourceLoaderInfo> resourceLoaderInfos;
private final List<ClasspathInfo> classpathInfos;
private final List<DependsOnInfo> dependsOnInfos;
private final List<String> dependsOnInfos;
private final List<EntityResourceInfo> entityResourceInfos;
private final List<ServiceResourceInfo> serviceResourceInfos;
private final List<TestSuiteInfo> testSuiteInfos;
@@ -305,7 +305,7 @@ private ComponentConfig(Builder b) {
private boolean enabled = true;
private Map<String, ResourceLoaderInfo> resourceLoaderInfos;
private List<ClasspathInfo> classpathInfos;
private List<DependsOnInfo> dependsOnInfos;
private List<String> dependsOnInfos;
private List<EntityResourceInfo> entityResourceInfos;
private List<ServiceResourceInfo> serviceResourceInfos;
private List<TestSuiteInfo> testSuiteInfos;
@@ -343,7 +343,7 @@ public Builder classpathInfos(List<ClasspathInfo> classpathInfos) {
return this;
}

public Builder dependsOnInfos(List<DependsOnInfo> dependsOnInfos) {
public Builder dependsOnInfos(List<String> dependsOnInfos) {
this.dependsOnInfos = dependsOnInfos;
return this;
}
@@ -416,7 +416,7 @@ private ComponentConfig(String globalName, String rootLocation) throws Component
componentName = componentElement.getAttribute("name");
enabled = "true".equalsIgnoreCase(componentElement.getAttribute("enabled"));
this.globalName = UtilValidate.isEmpty(globalName) ? componentName : globalName;
dependsOnInfos = collectElements(componentElement, "depends-on", DependsOnInfo::new);
dependsOnInfos = collectElements(componentElement, "depends-on", (c, e) -> e.getAttribute("component-name"));
classpathInfos = collectElements(componentElement, "classpath", ClasspathInfo::new);
entityResourceInfos = collectElements(componentElement, "entity-resource", EntityResourceInfo::new);
serviceResourceInfos = collectElements(componentElement, "service-resource", ServiceResourceInfo::new);
@@ -518,7 +518,7 @@ public String getGlobalName() {
*
* @return an immutable list containing the dependency information.
*/
public List<DependsOnInfo> getDependsOn() {
public List<String> getDependsOn() {
return this.dependsOnInfos;
}

@@ -676,7 +676,7 @@ public String toString() {

// ComponentConfig instances need to be looked up by their global name and root location,
// so this class encapsulates the Maps and synchronization code required to do that.
private static final class ComponentConfigCache {
static final class ComponentConfigCache {
// Key is the global name.
private final Map<String, ComponentConfig> componentConfigs = new LinkedHashMap<>();
// Root location mapped to global name.
@@ -694,14 +694,14 @@ private synchronized ComponentConfig fromRootLocation(String rootLocation) {
return componentConfigs.get(globalName);
}

private synchronized ComponentConfig put(ComponentConfig config) {
synchronized ComponentConfig put(ComponentConfig config) {
String globalName = config.getGlobalName();
String fileLocation = config.rootLocation().toString();
componentLocations.put(fileLocation, globalName);
return componentConfigs.put(globalName, config);
}

private synchronized Collection<ComponentConfig> values() {
synchronized Collection<ComponentConfig> values() {
return Collections.unmodifiableList(new ArrayList<>(componentConfigs.values()));
}
}
@@ -723,15 +723,6 @@ private EntityResourceInfo(ComponentConfig componentConfig, Element element) {
}
}

public static final class DependsOnInfo extends ResourceInfo {
public final String componentName;

private DependsOnInfo(ComponentConfig componentConfig, Element element) {
super(componentConfig, element);
this.componentName = element.getAttribute("component-name");
}
}

/**
* An object that models the <code>&lt;keystore&gt;</code> element.
*
@@ -38,7 +38,6 @@
import java.util.stream.Stream;

import org.apache.ofbiz.base.component.ComponentConfig;
import org.apache.ofbiz.base.component.ComponentConfig.DependsOnInfo;
import org.apache.ofbiz.base.component.ComponentException;
import org.apache.ofbiz.base.component.ComponentLoaderConfig;
import org.apache.ofbiz.base.component.ComponentLoaderConfig.ComponentDef;
@@ -65,7 +64,7 @@
private final AtomicBoolean loaded = new AtomicBoolean(false);
/** 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<>();
private static Map<String, List<String>> toBeLoadedComponents = new ConcurrentHashMap<>();

@Override
public void init(List<StartupCommand> ofbizCommands, String name, String configFile) throws ContainerException {
@@ -227,10 +226,10 @@ private void loadComponentWithDependency() throws IOException, ComponentExceptio
if (UtilValidate.isEmpty(toBeLoadedComponents)) {
return;
} else {
for (Map.Entry<String, List<DependsOnInfo>> entries : toBeLoadedComponents.entrySet()) {
for (Map.Entry<String, List<String>> entries : toBeLoadedComponents.entrySet()) {
ComponentConfig config = retrieveComponentConfig(entries.getKey(), null);
if (config.enabled()) {
List<DependsOnInfo> dependencyList = checkDependencyForComponent(config);
List<String> dependencyList = checkDependencyForComponent(config);
if (UtilValidate.isNotEmpty(dependencyList)) {
toBeLoadedComponents.replace(config.getComponentName(), dependencyList);
String msg = "Not loading component [" + config.getComponentName() + "] because it's dependent Component is not loaded [ " + dependencyList + "]";
@@ -277,7 +276,7 @@ private static ComponentConfig retrieveComponentConfig(String name, Path locatio
*/
private void loadSingleComponent(ComponentConfig config) throws ComponentException {
if (config.enabled()) {
List<DependsOnInfo> dependencyList = checkDependencyForComponent(config);
List<String> dependencyList = checkDependencyForComponent(config);
if (UtilValidate.isEmpty(dependencyList)) {
readyComponents.add(config);
}
@@ -293,18 +292,18 @@ private void loadSingleComponent(ComponentConfig config) throws ComponentExcepti
* @param config the component configuration
* @throws ComponentException
*/
private List<DependsOnInfo> checkDependencyForComponent(ComponentConfig config) throws ComponentException {
List<DependsOnInfo> dependencyList = new ArrayList<>(config.getDependsOn());
private List<String> checkDependencyForComponent(ComponentConfig config) throws ComponentException {
List<String> dependencyList = new ArrayList<>(config.getDependsOn());
if (UtilValidate.isNotEmpty(dependencyList)) {
Set<DependsOnInfo> resolvedDependencyList = new HashSet<>();
for (DependsOnInfo dependency : dependencyList) {
Debug.logInfo("Component : " + config.getComponentName() + " is Dependent on " + dependency.componentName, module);
ComponentConfig componentConfig = ComponentConfig.getComponentConfig(String.valueOf(dependency.componentName));
Set<String> resolvedDependencyList = new HashSet<>();
for (String dependency : dependencyList) {
Debug.logInfo("Component : " + config.getComponentName() + " is Dependent on " + dependency, module);
ComponentConfig componentConfig = ComponentConfig.getComponentConfig(String.valueOf(dependency));
if (readyComponents.contains(componentConfig)) {
resolvedDependencyList.add(dependency);
}
}
resolvedDependencyList.forEach(resolvedDependency -> Debug.logInfo("Resolved : " + resolvedDependency.componentName + " Dependency for Component " + config.getComponentName(), module));
resolvedDependencyList.forEach(resolvedDependency -> Debug.logInfo("Resolved : " + resolvedDependency + " Dependency for Component " + config.getComponentName(), module));
dependencyList.removeAll(resolvedDependencyList);
if (UtilValidate.isEmpty(dependencyList)) {
toBeLoadedComponents.remove(config.getComponentName());

0 comments on commit 7d90807

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