VamsasArchive tested. Locked IO routines to be implemented in ArchiveFile
authorjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 20 Jan 2006 11:05:28 +0000 (11:05 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 20 Jan 2006 11:05:28 +0000 (11:05 +0000)
git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@153 be28352e-c001-0410-b1a7-c7978e42abec

src/org/vamsas/client/simpleclient/FileWatcher.java
src/org/vamsas/test/simpleclient/VamsasArchive.java

index e2a3ad0..83b7b93 100644 (file)
@@ -22,13 +22,19 @@ public class FileWatcher {
    * to preserve new state of file for immediate reading.
    */
   private Lock subjectLock = null;
-  
+  /**
+   * clear local locks on subject.
+   *
+   */
   private void clearLock() {
     if (subjectLock!=null)
       subjectLock.release();
     subjectLock=null;
   }
-  
+  /**
+   * 
+   * @return true if subject exists and is locked by another process.
+   */
   private boolean checkLock() {
     if (subject!=null && subject.exists()) {
       if (subjectLock!=null) {
index ccef739..354f9af 100644 (file)
@@ -126,15 +126,21 @@ public class VamsasArchive {
         while (newf.exists()); 
       } */
       log.info("Now writing new Archive into "+newf.getAbsolutePath());
-      org.vamsas.client.simpleclient.VamsasArchive va = new org.vamsas.client.simpleclient.VamsasArchive(newf, true);
-      // open another and...
-      ApplicationData appdata = makeDemoAppdata(va, 
-          "org.vamsas.test.simpleclient.VamsasArchive", "arnold Bugger esq", "disOrganised");
-      log.info("Preparing to write new document.");
-      doc.addApplicationData(appdata);
-      doc.addVAMSAS(Core.getDemoVamsas());
-      va.putVamsasDocument(doc); // gets stream and puts it.
-      va.closeArchive();
+      org.vamsas.client.simpleclient.VamsasArchive va=null;
+      { // hold lock over deletion and write of new archive.
+        Lock wlock = sfile.getLock();
+        newf.delete(); // clear out old file.
+        va = new org.vamsas.client.simpleclient.VamsasArchive(newf, true, wlock);
+        // open another and...
+        ApplicationData appdata = makeDemoAppdata(va, 
+            "org.vamsas.test.simpleclient.VamsasArchive", "arnold Bugger esq", "disOrganised");
+        log.info("Preparing to write new document.");
+        doc.addApplicationData(appdata);
+        doc.addVAMSAS(Core.getDemoVamsas());
+        va.putVamsasDocument(doc); // gets stream and puts it.
+        va.closeArchive();
+        sfile.unLock();
+      }
       log.info("Dump of new vamsas document :");
       log.info("Testing update: ");
       {
@@ -145,8 +151,7 @@ public class VamsasArchive {
         VamsasArchiveReader vreader = new VamsasArchiveReader(newf);
         SimpleDocument sdoc = new SimpleDocument("testing new vamsas write");
         ArchiveReports.reportDocument(sdoc.getVamsasDocument(vreader), vreader, true, System.out);
-        lock.release();
-        lock = null;
+        sfile.unLock();
       }
       // backup.delete(); // tidy up