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.
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);
}
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.");
}
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();
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);