ceb1e659e88b31031c4cd9f84849437915379da1
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / VamsasFileWatcherElement.java
1 package uk.ac.vamsas.client.simpleclient;\r
2 \r
3 \r
4 /**\r
5  * Element of the VamsasFileWatcherThread event generator chain.\r
6  * Keep a reference to this element before adding it to the chain \r
7  * in order to control the generation of events with halt and enable.\r
8  * \r
9  * doWatch will do nothing if the element is not enabled.\r
10  * \r
11  */\r
12 public class VamsasFileWatcherElement extends WatcherElement {\r
13   VamsasFile watched=null;\r
14   /**\r
15    * create a new, enabled watch element\r
16    * @param watcher file being watched\r
17    * @param handler handler to call on state change\r
18    */\r
19   public VamsasFileWatcherElement(VamsasFile watcher, WatcherCallBack handler) {\r
20     this(watcher, handler, true);\r
21   }\r
22   protected void initWatch() {\r
23     if (watched==null)\r
24       return;\r
25     watched.unLock(); // very very essential!\r
26     watcher = new FileWatcher(watched.getVamsasFile());\r
27   }\r
28   protected void endWatch() {\r
29     // leaves watcher in state its in.\r
30   }\r
31   /**\r
32    * new watcher with flag to initially skip watching this sessionfile\r
33    * @param watcher\r
34    * @param handler\r
35    * @param enableWatching\r
36    */\r
37   public VamsasFileWatcherElement(VamsasFile watcher, WatcherCallBack handler, boolean enableWatching) {\r
38     super(handler);\r
39     this.watched = watcher;\r
40     if (enableWatching)\r
41       enableWatch();\r
42     else\r
43       haltWatch();\r
44   }\r
45   /**\r
46    * @return the watched\r
47    */\r
48   public VamsasFile getWatched() {\r
49     return watched;\r
50   }\r
51   protected String getSubject() {\r
52     return watched.getVamsasFile().toString();\r
53   }\r
54 }\r