ref #9359 use commons-collections4 in cdmserver
authorAndreas Müller <a.mueller@bgbm.org>
Sat, 15 Jan 2022 18:14:52 +0000 (19:14 +0100)
committerAndreas Müller <a.mueller@bgbm.org>
Sat, 15 Jan 2022 18:14:52 +0000 (19:14 +0100)
pom.xml
src/main/java/eu/etaxonomy/cdm/server/instance/InstanceManager.java

diff --git a/pom.xml b/pom.xml
index 6cc8439f87a4c2a3f81fc2294386e17b0193a64c..9d8905e1f465eebbb67beba487653606004df15f 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <version>2.11.0</version>
     </dependency>
     <dependency>
-      <groupId>commons-collections</groupId>
-      <artifactId>commons-collections</artifactId>
-      <version>3.2.2</version>
+      <!-- only used in InstanceManger class -->
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-collections4</artifactId>
+      <version>4.4</version>
     </dependency>
     <dependency>
       <groupId>net.sf.jopt-simple</groupId>
index da885e9cf1564f377799c81404d88887b64b05a5..918346ab1f9ce19ccca4b77d211799546f73da66 100644 (file)
@@ -16,7 +16,7 @@ import java.io.File;
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.commons.collections.map.ListOrderedMap;
+import org.apache.commons.collections4.map.ListOrderedMap;
 import org.apache.log4j.Logger;
 import org.eclipse.jetty.util.component.LifeCycle;
 
@@ -38,7 +38,7 @@ public class InstanceManager implements LifeCycle.Listener {
 
     private static final Logger logger = Logger.getLogger(InstanceManager.class);
 
-    private ListOrderedMap instances = new ListOrderedMap();
+    private ListOrderedMap<String,CdmInstance> instances = new ListOrderedMap<>();
 
     private final StartupQueue queue = new StartupQueue();
 
@@ -81,19 +81,18 @@ public class InstanceManager implements LifeCycle.Listener {
      *
      * @return the instances
      */
-    @SuppressWarnings("unchecked")
     public List<CdmInstance> getInstances() {
         return instances.valueList();
     }
 
     public CdmInstance getInstance(String instanceName) {
-        return (CdmInstance) instances.get(instanceName);
+        return instances.get(instanceName);
     }
 
     /**
      * Starts the instance
      *
-     * Rebinds the JndiDataSource and starts the given instance. The method
+     * Re-binds the JndiDataSource and starts the given instance. The method
      * returns once the instance is fully started up.
      *
      * @param instance
@@ -163,8 +162,8 @@ public class InstanceManager implements LifeCycle.Listener {
      */
     synchronized public void reLoadInstanceConfigurations() {
 
-        ListOrderedMap currentInstances = instances;
-        ListOrderedMap updatedInstances = new ListOrderedMap();
+        ListOrderedMap<String,CdmInstance> currentInstances = instances;
+        ListOrderedMap<String,CdmInstance> updatedInstances = new ListOrderedMap<>();
 
         List<Configuration> configList = DataSourcePropertyParser.parseDataSourceConfigs(datasourcesFile);
         logger.info("cdm server instance names loaded: " + configList.toString());
@@ -172,7 +171,7 @@ public class InstanceManager implements LifeCycle.Listener {
         for (Configuration config : configList) {
             String key = config.getInstanceName();
             if (currentInstances.containsKey(key)) {
-                CdmInstance existingInstance = (CdmInstance) currentInstances.get(key);
+                CdmInstance existingInstance = currentInstances.get(key);
                 if (!(existingInstance.getStatus().equals(Status.removed) && existingInstance.getWebAppContext() == null)) {
                     // re-added instance if not already removed (removed
                     // instances will not be re-added if they have been stopped
@@ -202,9 +201,9 @@ public class InstanceManager implements LifeCycle.Listener {
         }
 
         // find removed instances
-        for (Object keyOfExisting : currentInstances.keyList()) {
+        for (String keyOfExisting : currentInstances.keyList()) {
             if (!updatedInstances.containsKey(keyOfExisting)) {
-                CdmInstance removedInstance = (CdmInstance) currentInstances.get(keyOfExisting);
+                CdmInstance removedInstance = currentInstances.get(keyOfExisting);
 
                 if (removedInstance.getStatus().equals(Status.removed)) {
                     // instance already is removed, forget it now
@@ -220,7 +219,6 @@ public class InstanceManager implements LifeCycle.Listener {
                 } catch (Exception e) {
                     logger.error(e.getMessage(), e);
                 }
-
             }
         }