small updates.
[vamsas.git] / src / org / vamsas / client / simpleclient / Lock.java
index ab159ba..dfc978e 100644 (file)
@@ -8,8 +8,8 @@ import java.nio.channels.FileLock;
 
 /**
  * transient object representing a file lock
- * 
- * 
+ * This lock should hold for all processes interacting in a session.
+ * TODO: currently implemented for local filesystem style locking - need a fallback mechanism for systems without file locks.
  * @author jimp
  * 
  */
@@ -33,6 +33,9 @@ public class Lock {
         }
       
       lock = (rafile=new RandomAccessFile(lockfile,"rw")).getChannel().tryLock();
+      if (lock==null || !lock.isValid())
+        // failed to get lock. Close the file channel
+        rafile.getChannel().close();
     } catch (FileNotFoundException e) {
       System.err.println("Error! Couldn't create a lockfile at "
           + lockfile.getAbsolutePath());
@@ -52,6 +55,7 @@ public class Lock {
   }
   public void release() {
     try {
+      // TODO: verify that channel.close should be called after release() for rigourous locking. 
       if (lock!=null && lock.isValid())
         lock.release();
       if (rafile!=null && rafile.getChannel().isOpen())