untested watcherElement for spotting changes in SessionFlagFile presence/absence.
authorjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 12 Jan 2007 15:39:22 +0000 (15:39 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Fri, 12 Jan 2007 15:39:22 +0000 (15:39 +0000)
git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@337 be28352e-c001-0410-b1a7-c7978e42abec

src/uk/ac/vamsas/client/simpleclient/SessionFlagWatcherElement.java [new file with mode: 0644]

diff --git a/src/uk/ac/vamsas/client/simpleclient/SessionFlagWatcherElement.java b/src/uk/ac/vamsas/client/simpleclient/SessionFlagWatcherElement.java
new file mode 100644 (file)
index 0000000..8d70d9f
--- /dev/null
@@ -0,0 +1,54 @@
+package uk.ac.vamsas.client.simpleclient;\r
+\r
+\r
+/**\r
+ * Element of the VamsasFileWatcherThread event generator chain.\r
+ * Keep a reference to this element before adding it to the chain \r
+ * in order to control the generation of events with halt and enable.\r
+ * \r
+ * doWatch will do nothing if the element is not enabled.\r
+ * TODO: TEST THIS CLASS - not yet used in SimpleClient\r
+ */\r
+public class SessionFlagWatcherElement extends WatcherElement {\r
+  SessionFlagFile watched=null;\r
+  /**\r
+   * create a new, enabled watch element\r
+   * @param watcher file being watched\r
+   * @param handler handler to call on state change\r
+   */\r
+  public SessionFlagWatcherElement(SessionFlagFile watcher, WatcherCallBack handler) {\r
+    this(watcher, handler, true);\r
+  }\r
+  protected void initWatch() {\r
+    if (watched==null)\r
+      return;\r
+    watcher = new FileWatcher(watched.flagFile);\r
+  }\r
+  protected void endWatch() {\r
+    // leaves watcher in state its in.\r
+  }\r
+  /**\r
+   * new watcher with flag to initially skip watching this sessionfile\r
+   * @param watcher\r
+   * @param handler\r
+   * @param enableWatching\r
+   */\r
+  public SessionFlagWatcherElement(SessionFlagFile watcher, WatcherCallBack handler, boolean enableWatching) {\r
+    super(handler);\r
+    this.watched = watcher;\r
+    if (enableWatching)\r
+      enableWatch();\r
+    else\r
+      haltWatch();\r
+  }\r
+  /**\r
+   * @return the watched\r
+   */\r
+  public SessionFlagFile getWatched() {\r
+    return watched;\r
+  }\r
+  protected String getSubject() {\r
+    \r
+    return watched.flagFile.toString();\r
+  }\r
+}\r