2 * This file is part of the Vamsas Client version 0.1.
\r
3 * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite,
\r
4 * Andrew Waterhouse and Dominik Lindner.
\r
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\r
9 * The Vamsas Client is free software: you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation, either version 3 of the License, or
\r
12 * (at your option) any later version.
\r
14 * The Vamsas Client is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public License
\r
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
\r
22 package uk.ac.vamsas.client.simpleclient;
\r
24 import java.io.File;
\r
26 import org.apache.commons.logging.Log;
\r
27 import org.apache.commons.logging.LogFactory;
\r
29 public class LockFactory {
\r
30 protected static Log log = LogFactory.getLog(LockFactory.class);
\r
32 public static int locktype = 0; // use file lock by default
\r
34 public static String[] locktypes = { "file", "native" };
\r
36 String lockt = System.getProperty("vamsas.locktype");
\r
37 if (lockt != null) {
\r
39 for (i = 0, j = locktypes.length; i < j
\r
40 && locktypes[i].equalsIgnoreCase(lockt); i++)
\r
43 String lt = "'" + locktypes[0] + "'";
\r
44 for (i = 1; i < j; i++)
\r
45 lt += ",'" + locktypes[i] + "'";
\r
46 log.warn("System property vamsas.locktype takes one of " + lt);
\r
47 log.warn("Defaulting to Locktype of " + locktypes[locktype]);
\r
50 log.debug("Defaulting to Locktype of " + locktypes[locktype]);
\r
54 * lock target (blocks until lock is obtained)
\r
59 public static Lock getLock(java.io.File target) {
\r
60 return getLock(target, true);
\r
63 public static Lock getLock(java.io.File target, boolean block) {
\r
65 return new FileLock(target, block);
\r
67 return new NativeLock(target, block);
\r
68 log.fatal("Implementation Error! No valid Locktype value");
\r
73 * try to lock target
\r
76 * @return null if lock was not possible
\r
78 public static Lock tryLock(File target) {
\r
79 return getLock(target, false);
\r