1 package uk.ac.vamsas.client.simpleclient;
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
9 * methods for setting and checking
10 * binary flags in a vamsas session directory.
11 * all methods apart from the constructor will
12 * throw a fatal error if the flagFile is not
13 * a valid java.io.File object.
14 * LATER: extract SessionFlag interface for generalizing the vamsas session code
18 public class SessionFlagFile {
19 private static Log log = LogFactory.getLog(SessionFlagFile.class);
20 protected File flagFile=null;
21 private void checkFlagFile() {
23 log.fatal("Implementation error - uninitialized SessionFlagFile",
24 new Error("Implementation error - uninitialized SessionFlagFile"));
28 * will log a warning if exceptions occur during flag creation.
29 * @return true if flag was set successfully
31 public boolean setFlag() {
34 if (flagFile.createNewFile()) {
35 log.debug("Set session flag "+flagFile);
37 log.debug("Session flag already set "+flagFile);
42 log.warn("Couldn't set session flag "+flagFile, e);
48 * @return true if flag was cleared successfully
50 public boolean clearFlag() {
52 if (flagFile.exists()) {
53 log.debug("clearing session flag "+flagFile);
54 if (!flagFile.delete()) {
55 log.warn("failed to clear session flag "+flagFile);
59 log.debug("clearFlag called for already cleared flag "+flagFile);
65 * @return state of session flag
67 public boolean checkFlag() {
69 if (flagFile.exists()) {
70 if (log.isDebugEnabled())
71 log.debug("Flag '"+flagFile+"' is set.");
74 if (log.isDebugEnabled())
75 log.debug("Flag '"+flagFile+"' is not set.");
81 public SessionFlagFile(File flagFile) {
83 this.flagFile = flagFile;