Vamsas Archive Reader and simple test class.
[vamsas.git] / src / org / vamsas / client / simpleclient / Lock.java
index ab159ba..175728e 100644 (file)
@@ -8,7 +8,7 @@ import java.nio.channels.FileLock;
 
 /**
  * transient object representing a file lock
- * 
+ * This lock should hold for all processes interacting in a session.
  * 
  * @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());