From: jprocter Date: Fri, 20 Jan 2006 11:05:28 +0000 (+0000) Subject: VamsasArchive tested. Locked IO routines to be implemented in ArchiveFile X-Git-Tag: Release_0.2~367 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=330f112412c4d3f1540fb6d4b1d898a9bbca3b7a;p=vamsas.git VamsasArchive tested. Locked IO routines to be implemented in ArchiveFile git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@153 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/client/simpleclient/FileWatcher.java b/src/org/vamsas/client/simpleclient/FileWatcher.java index e2a3ad0..83b7b93 100644 --- a/src/org/vamsas/client/simpleclient/FileWatcher.java +++ b/src/org/vamsas/client/simpleclient/FileWatcher.java @@ -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) { diff --git a/src/org/vamsas/test/simpleclient/VamsasArchive.java b/src/org/vamsas/test/simpleclient/VamsasArchive.java index ccef739..354f9af 100644 --- a/src/org/vamsas/test/simpleclient/VamsasArchive.java +++ b/src/org/vamsas/test/simpleclient/VamsasArchive.java @@ -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