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
30 * methods for setting and checking binary flags in a vamsas session directory.
\r
31 * all methods apart from the constructor will throw a fatal error if the
\r
32 * flagFile is not a valid java.io.File object. LATER: extract SessionFlag
\r
33 * interface for generalizing the vamsas session code
\r
38 public class SessionFlagFile {
\r
39 private static Log log = LogFactory.getLog(SessionFlagFile.class);
\r
41 protected File flagFile = null;
\r
43 private void checkFlagFile() {
\r
44 if (flagFile == null) {
\r
45 log.fatal("Implementation error - uninitialized SessionFlagFile",
\r
46 new Error("Implementation error - uninitialized SessionFlagFile"));
\r
51 * will log a warning if exceptions occur during flag creation.
\r
53 * @return true if flag was set successfully
\r
55 public boolean setFlag() {
\r
58 if (flagFile.createNewFile()) {
\r
59 log.debug("Set session flag " + flagFile);
\r
61 log.debug("Session flag already set " + flagFile);
\r
64 } catch (Exception e) {
\r
65 log.warn("Couldn't set session flag " + flagFile, e);
\r
72 * @return true if flag was cleared successfully
\r
74 public boolean clearFlag() {
\r
76 if (flagFile.exists()) {
\r
77 log.debug("clearing session flag " + flagFile);
\r
78 if (!flagFile.delete()) {
\r
79 log.warn("failed to clear session flag " + flagFile);
\r
83 log.debug("clearFlag called for already cleared flag " + flagFile);
\r
90 * @return state of session flag
\r
92 public boolean checkFlag() {
\r
94 if (flagFile.exists()) {
\r
95 if (log.isDebugEnabled())
\r
96 log.debug("Flag '" + flagFile + "' is set.");
\r
99 if (log.isDebugEnabled())
\r
100 log.debug("Flag '" + flagFile + "' is not set.");
\r
107 public SessionFlagFile(File flagFile) {
\r
109 this.flagFile = flagFile;
\r