Merge "Re-adding version to parent pom"
[dmaap/datarouter.git] / datarouter-node / src / main / java / org / onap / dmaap / datarouter / node / DeliveryTask.java
index 2093d6d..91bd716 100644 (file)
@@ -39,6 +39,7 @@ import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.ProtocolException;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.UUID;
@@ -79,11 +80,11 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
 
 
     /**
-     * Create a delivery task for a given delivery queue and pub ID
+     * Create a delivery task for a given delivery queue and pub ID.
      *
      * @param deliveryTaskHelper The delivery task helper for the queue this task is in.
      * @param pubid The publish ID for this file.  This is used as the base for the file name in the spool directory and
-     * is of the form <milliseconds since 1970>.<fqdn of initial data router node>
+     *      is of the form (milliseconds since 1970).(fqdn of initial data router node)
      */
     DeliveryTask(DeliveryTaskHelper deliveryTaskHelper, String pubid) {
         this.deliveryTaskHelper = deliveryTaskHelper;
@@ -355,13 +356,27 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
      * Remove meta and data files.
      */
     void clean() {
-        datafile.delete();
-        metafile.delete();
+        deleteWithRetry(datafile);
+        deleteWithRetry(metafile);
         eelfLogger.info(EelfMsgs.INVOKE, newInvocationId);
         eelfLogger.info(EelfMsgs.EXIT);
         hdrs = null;
     }
 
+    private void deleteWithRetry(File file) {
+        int maxTries = 3;
+        int tryCount = 1;
+        while (tryCount <= maxTries) {
+            try {
+                Files.deleteIfExists(file.toPath());
+                break;
+            } catch (IOException e) {
+                eelfLogger.error("IOException : Failed to delete file :" + file.getName() + " on attempt " + tryCount, e);
+            }
+            tryCount++;
+        }
+    }
+
     /**
      * Get the resume time for a delivery task.
      */