* 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) {
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: ");
{
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