added retry mechanism for opening of vamsas archives before it's assumed that the...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 18 Sep 2007 10:19:22 +0000 (10:19 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 18 Sep 2007 10:19:22 +0000 (10:19 +0000)
git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@471 be28352e-c001-0410-b1a7-c7978e42abec

src/uk/ac/vamsas/client/simpleclient/VamsasArchiveReader.java

index 819be18..7f9a008 100644 (file)
@@ -30,6 +30,8 @@ import uk.ac.vamsas.objects.utils.document.VersionEntries;
  *
  */
 public class VamsasArchiveReader {
+  private static final int JARFILE_OPEN_RETRIES = 50;
+  private static final int JARFILE_OPEN_RETRYWAIT = 1;
   private static Log log = LogFactory.getLog(VamsasArchiveReader.class);
   JarFile jfile=null;
   boolean stream=false; // true if we are seeking on the stream.
@@ -70,16 +72,27 @@ public class VamsasArchiveReader {
   
   public VamsasArchiveReader(File vamsasfile) {
     jfile=null;
+    int retries=JARFILE_OPEN_RETRIES;
+    Exception ex=null;
     if (vamsasfile.exists()) {
+      while (jfile==null && --retries>0)
+      {
       try {
         jfile=new JarFile(vamsasfile);
       }
       catch (Exception e) {
-        log.debug("non-serious? couldn't open new JarFile on "+vamsasfile,e);
+        ex = e;
         jfile=null;
+        try { 
+          Thread.sleep(JARFILE_OPEN_RETRYWAIT); 
+        } catch (Exception w) {};
+      }
+      }
+      if (jfile==null && ex!=null)
+      {
+        log.debug("non-serious? Exceptions when opening JarFile at "+vamsasfile,ex);
       }
     }
-    
   }
   /**
    * in an ideal world - this constructor will create a reader object