ensured single instance of vamsasarchive io handler to prevent lock contention.
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / VamsasSession.java
index c849893..05014ab 100644 (file)
@@ -294,7 +294,10 @@ public class VamsasSession {
     newdoc.unlockFile();
     log.debug("Transfer complete.");
   }
-  
+  /**
+        * extant archive IO handler
+        */
+  VamsasArchive _va=null;
   /**
    * Creates a VamsasArchive Vobject for accessing and updating document
    * Note: this will lock the Vamsas Document for exclusive access to the client.
@@ -302,7 +305,9 @@ public class VamsasSession {
    * @throws IOException if locks fail or vamsas document read fails.
    */
   protected VamsasArchive getVamsasDocument() throws IOException {
-    // TODO: check we haven't already done this once - probably should be done by caller
+    // check we haven't already done this once - probably should be done by caller
+    if (_va!=null)
+      return _va;
     // patiently wait for a lock on the document. (from ArchiveClient.getUpdateable())
     long tries=5000;
     while (vamArchive.getLock()==null && --tries>0) {
@@ -321,8 +326,12 @@ public class VamsasSession {
    * @throws IOException
    */
   protected void unlockVamsasDocument() throws IOException {
+    if (_va!=null)
+      _va.closeArchive();
+    _va=null;
     if (vamArchive!=null)
       vamArchive.unLock();
+    
   }
   /**
    * create a uniquely named uk.ac.vamsas.client.simpleclient.ClientsFile.addClient(ClientHandle)ile in the session Directory