X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Forg%2Fvamsas%2Ftest%2Fsimpleclient%2FArchiveClient.java;h=c681fe04d004f1a7c182a6dac5a664709b2041a8;hb=5c0c34895c290164caad28e0aeac86b5a52ee655;hp=da555af62aeb43d6104a12cbbf5b21941954d560;hpb=30801ef84cde704404d052f00c70ae129820bb0b;p=vamsas.git diff --git a/src/org/vamsas/test/simpleclient/ArchiveClient.java b/src/org/vamsas/test/simpleclient/ArchiveClient.java index da555af..c681fe0 100644 --- a/src/org/vamsas/test/simpleclient/ArchiveClient.java +++ b/src/org/vamsas/test/simpleclient/ArchiveClient.java @@ -83,6 +83,10 @@ public class ArchiveClient extends IdFactory { if (vsess==null) throw new Error("ArchiveClient instance is invalid!."); } + /** + * set this to false if watch loop should end immediately + */ + protected boolean watchForChange=true; public static int WATCH_SLEEP=300; /** * watch the document file for updates. @@ -93,21 +97,22 @@ public class ArchiveClient extends IdFactory { valid(); vsess.unLock(); // doh. FileWatcher watcher = new FileWatcher(vsess.getVamsasFile()); + // watcher.setState(); + watchForChange=true; long endtime=System.currentTimeMillis()+time; try { org.vamsas.client.simpleclient.Lock doclock; - //watcher.setState(); do { doclock=watcher.getChangedState(); if (doclock==null) Thread.sleep(WATCH_SLEEP); - } while (doclock==null && (time==0 || endtime>System.currentTimeMillis())); // tuning. + } while (watchForChange && doclock==null && (time==0 || endtime>System.currentTimeMillis())); // tuning. if (doclock==null) return null; else { - doclock = vsess.getLock(doclock); - VamsasArchiveReader varc = new VamsasArchiveReader(vsess.getVamsasFile()); - return _getReadonly(varc); + return getUpdateable(vsess.getLock(doclock)); + /*VamsasArchiveReader varc = new VamsasArchiveReader(vsess.getVamsasFile()); + return _getReadonly(varc);*/ } } catch (Exception e) { log.error("Whilst watching file "+vsess.getVamsasFile(), e); @@ -170,12 +175,15 @@ public class ArchiveClient extends IdFactory { } public ClientDoc getUpdateable() { + return getUpdateable(null); + } + public ClientDoc getUpdateable(org.vamsas.client.simpleclient.Lock lock) { + getVorbaIdHash().clear(); valid(); try { // patiently wait for a lock on the document. long tries=5000; - org.vamsas.client.simpleclient.Lock lock; - while (((lock=vsess.getLock())==null || !lock.isLocked()) && --tries>0) { + while (lock==null && ((lock=vsess.getLock())==null || !lock.isLocked()) && --tries>0) { // Thread.sleep(1); log.debug("Trying to get a document lock for the "+tries+"'th time."); } @@ -222,6 +230,7 @@ public class ArchiveClient extends IdFactory { cdoc.updateDocumentRoots(); cdoc.iohandler.putVamsasDocument(cdoc.doc); cdoc.iohandler.closeArchive(); + this.extantids.clear();// we forget our ids after we close the document. cdoc.iohandler=null; cdoc = null; vsess.unLock(); @@ -258,7 +267,7 @@ public class ArchiveClient extends IdFactory { int u=5; while (--u>0) { System.out.println("Watch for more... ("+u+" left)"); - ClientDoc ucdoc = client.watch(50000); + ClientDoc ucdoc = client.watch(0000); if (ucdoc!=null) { System.out.println("****\nUpdate detected at "+new Date()); ArchiveReports.reportDocument(ucdoc.doc, ucdoc.getReader(), true, System.out);