locking for windows (XP) partly debugged. ClientsFileTest watchers do not behave...
[vamsas.git] / src / org / vamsas / client / simpleclient / SessionFile.java
index 0eabf6d..d33f2f8 100644 (file)
@@ -27,8 +27,10 @@ public class SessionFile {
   protected boolean lockFile(Lock extantlock) {
     if (fileLock!=null && !fileLock.isLocked()) {
       fileLock.release();// tidy up invalid lock
+      fileLock=null;
     }
-    fileLock=extantlock;
+    if (extantlock!=null)
+      fileLock=extantlock;
     return lockFile();
   }
 
@@ -60,11 +62,15 @@ public class SessionFile {
       }
       // TODO: see if we need to loop-wait for locks or they just block until
       // lock is made...
+      long tries=500;
       do {
-        if (fileLock!=null)
+        tries--;
+        if (fileLock!=null && !fileLock.isLocked())
           fileLock.release();
           fileLock = new Lock(sessionFile); // TODO: wait around if we can't get the lock.
-      } while (!fileLock.isLocked());
+      } while (tries>0 && !fileLock.isLocked());
+      if (!fileLock.isLocked())
+        log.error("Failed to get lock for "+sessionFile);
       // fileLock = new Lock(sessionFile);
       return fileLock.isLocked();    
     } else