updated test cases for spring 2006 schema, and major debug of locking system
[vamsas.git] / src / org / vamsas / client / simpleclient / LockFactory.java
index 72cbe66..5fdde6c 100644 (file)
@@ -1,5 +1,7 @@
 package org.vamsas.client.simpleclient;
 
+import java.io.File;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -20,15 +22,31 @@ public class LockFactory {
         log.warn("System property vamsas.locktype takes one of "+lt);
         log.warn("Defaulting to Locktype of "+locktypes[locktype]);
       }
-    }
+    } else
+      log.debug("Defaulting to Locktype of "+locktypes[locktype]);
   }
-  
+  /**
+   * lock target (blocks until lock is obtained)
+   * @param target
+   * @return lock
+   */
   public static Lock getLock(java.io.File target) {
+    return getLock(target, true);
+  }
+  public static Lock getLock(java.io.File target, boolean block) { 
     if (locktype==0)
-      return new FileLock(target);
+      return new FileLock(target, block);
     if (locktype==1)
-      return new NativeLock(target);
+      return new NativeLock(target, block);
     log.fatal("Implementation Error! No valid Locktype value");
     return null;
   }
+  /**
+   * try to lock target 
+   * @param target
+   * @return null if lock was not possible
+   */
+  public static Lock tryLock(File target) {
+    return getLock(target, false);
+  }
 }