remove old ebi packages
[vamsas.git] / src / org / vamsas / test / simpleclient / ArchiveClient.java
index da555af..c681fe0 100644 (file)
@@ -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);