1 package org.vamsas.client.simpleclient;
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
8 public class LockFactory {
9 protected static Log log = LogFactory.getLog(LockFactory.class);
10 public static int locktype=0; // use file lock by default
11 public static String[] locktypes = {"file","native"};
13 String lockt = System.getProperty("vamsas.locktype");
16 for (i=0, j=locktypes.length; i<j && locktypes[i].equalsIgnoreCase(lockt); i++)
19 String lt = "'"+locktypes[0]+"'";
21 lt += ",'"+locktypes[i]+"'";
22 log.warn("System property vamsas.locktype takes one of "+lt);
23 log.warn("Defaulting to Locktype of "+locktypes[locktype]);
26 log.debug("Defaulting to Locktype of "+locktypes[locktype]);
29 * lock target (blocks until lock is obtained)
33 public static Lock getLock(java.io.File target) {
34 return getLock(target, true);
36 public static Lock getLock(java.io.File target, boolean block) {
38 return new FileLock(target, block);
40 return new NativeLock(target, block);
41 log.fatal("Implementation Error! No valid Locktype value");
47 * @return null if lock was not possible
49 public static Lock tryLock(File target) {
50 return getLock(target, false);