DMAAP-1195 [DR] Remove DR code smells
[dmaap/datarouter.git] / datarouter-node / src / main / java / org / onap / dmaap / datarouter / node / DeliveryQueue.java
index b7699e5..4d336b7 100644 (file)
@@ -27,9 +27,10 @@ package org.onap.dmaap.datarouter.node;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Hashtable;
-import java.util.Vector;
+import java.util.HashMap;
+import java.util.List;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -52,16 +53,15 @@ import org.jetbrains.annotations.Nullable;
  * delivery fails while the delay was active, it will not change the delay
  * or change the duration of any subsequent delay.
  * If, however, it succeeds, it will cancel the delay.
- *
- * <p>The queue maintains 3 collections of files to deliver: A todo list of
+ * The queue maintains 3 collections of files to deliver: A todoList of
  * files that will be attempted, a working set of files that are being
  * attempted, and a retry set of files that were attempted and failed.
- * Whenever the todo list is empty and needs to be refilled, a scan of the
+ * Whenever the todoList is empty and needs to be refilled, a scan of the
  * spool directory is made and the file names sorted.  Any files in the working set are ignored.
  * If a DeliveryTask for the file is in the retry set, then that delivery
- * task is placed on the todo list.  Otherwise, a new DeliveryTask for the
- * file is created and placed on the todo list.
- * If, when a DeliveryTask is about to be removed from the todo list, its
+ * task is placed on the todoList.  Otherwise, a new DeliveryTask for the
+ * file is created and placed on the todoList.
+ * If, when a DeliveryTask is about to be removed from the todoList, its
  * age exceeds DeliveryQueueHelper.getExpirationTimer(), then it is instead
  * marked as expired.
  *
@@ -73,14 +73,24 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
     private DeliveryQueueHelper deliveryQueueHelper;
 
     private DestInfo destinationInfo;
-    private Hashtable<String, DeliveryTask> working = new Hashtable<>();
-    private Hashtable<String, DeliveryTask> retry = new Hashtable<>();
+    private HashMap<String, DeliveryTask> working = new HashMap<>();
+    private HashMap<String, DeliveryTask> retry = new HashMap<>();
     private int todoindex;
     private boolean failed;
     private long failduration;
     private long resumetime;
     private File dir;
-    private Vector<DeliveryTask> todo = new Vector<>();
+    private List<DeliveryTask> todoList = new ArrayList<>();
+
+    /**
+     * Create a delivery queue for a given destination info.
+     */
+    DeliveryQueue(DeliveryQueueHelper deliveryQueueHelper, DestInfo destinationInfo) {
+        this.deliveryQueueHelper = deliveryQueueHelper;
+        this.destinationInfo = destinationInfo;
+        dir = new File(destinationInfo.getSpool());
+        dir.mkdirs();
+    }
 
     /**
      * Try to cancel a delivery task.
@@ -93,8 +103,8 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
         }
         DeliveryTask dt = retry.get(pubid);
         if (dt == null) {
-            for (int i = todoindex; i < todo.size(); i++) {
-                DeliveryTask xdt = todo.get(i);
+            for (int i = todoindex; i < todoList.size(); i++) {
+                DeliveryTask xdt = todoList.get(i);
                 if (xdt.getPublishId().equals(pubid)) {
                     dt = xdt;
                     break;
@@ -210,13 +220,13 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
             }
         }
         while (true) {
-            if (todoindex >= todo.size()) {
+            if (todoindex >= todoList.size()) {
                 todoindex = 0;
-                todo = new Vector<>();
+                todoList = new ArrayList<>();
                 String[] files = dir.list();
                 Arrays.sort(files);
                 scanForNextTask(files);
-                retry = new Hashtable<>();
+                retry = new HashMap<>();
             }
             DeliveryTask dt = getDeliveryTask(mindate);
             if (dt != null) {
@@ -227,16 +237,6 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
         }
     }
 
-    /**
-     * Create a delivery queue for a given destination info.
-     */
-    DeliveryQueue(DeliveryQueueHelper deliveryQueueHelper, DestInfo destinationInfo) {
-        this.deliveryQueueHelper = deliveryQueueHelper;
-        this.destinationInfo = destinationInfo;
-        dir = new File(destinationInfo.getSpool());
-        dir.mkdirs();
-    }
-
     /**
      * Update the destination info for this delivery queue.
      */
@@ -401,14 +401,14 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
             if (dt == null) {
                 dt = new DeliveryTask(this, pubId);
             }
-            todo.add(dt);
+            todoList.add(dt);
         }
     }
 
     @Nullable
     private DeliveryTask getDeliveryTask(long mindate) {
-        if (todoindex < todo.size()) {
-            DeliveryTask dt = todo.get(todoindex);
+        if (todoindex < todoList.size()) {
+            DeliveryTask dt = todoList.get(todoindex);
             if (dt.isCleaned()) {
                 todoindex++;
             }
@@ -449,4 +449,4 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
         }
         return fname2;
     }
-}
+}
\ No newline at end of file