svn commit: r1869185 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base: component/ComponentConfig.java container/ComponentContainer.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1869185 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base: component/ComponentConfig.java container/ComponentContainer.java

mthl
Author: mthl
Date: Wed Oct 30 15:47:58 2019
New Revision: 1869185

URL: http://svn.apache.org/viewvc?rev=1869185&view=rev
Log:
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

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java?rev=1869185&r1=1869184&r2=1869185&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/component/ComponentConfig.java Wed Oct 30 15:47:58 2019
@@ -262,7 +262,7 @@ public final class ComponentConfig {
     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 @@ public final class ComponentConfig {
         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 final class ComponentConfig {
             return this;
         }
 
-        public Builder dependsOnInfos(List<DependsOnInfo> dependsOnInfos) {
+        public Builder dependsOnInfos(List<String> dependsOnInfos) {
             this.dependsOnInfos = dependsOnInfos;
             return this;
         }
@@ -416,7 +416,7 @@ public final class ComponentConfig {
         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 final class ComponentConfig {
      *
      * @return an immutable list containing the dependency information.
      */
-    public List<DependsOnInfo> getDependsOn() {
+    public List<String> getDependsOn() {
         return this.dependsOnInfos;
     }
 
@@ -676,7 +676,7 @@ public final class ComponentConfig {
 
     // 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 @@ public final class ComponentConfig {
             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 @@ public final class ComponentConfig {
         }
     }
 
-    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.
      *

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java?rev=1869185&r1=1869184&r2=1869185&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/container/ComponentContainer.java Wed Oct 30 15:47:58 2019
@@ -38,7 +38,6 @@ import java.util.stream.Collectors;
 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 @@ public class ComponentContainer implemen
     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 @@ public class ComponentContainer implemen
             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 @@ public class ComponentContainer implemen
      */
     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 @@ public class ComponentContainer implemen
      * @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());