034aae6c31dad977f3f7f21e305d56afa0a3f9d6
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / SessionFileWatcherElement.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 SessionFileWatcherElement extends WatcherElement {\r
13   SessionFile 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 SessionFileWatcherElement(SessionFile 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     if (watcher==null || !watcher.getSubject().equals(watched.sessionFile)) \r
26       watcher=new FileWatcher(watched.sessionFile);\r
27     else\r
28       watcher.setState();\r
29   }\r
30   protected void endWatch() {\r
31     // leaves watcher in state its in.\r
32   }\r
33   /**\r
34    * new watcher with flag to initially skip watching this sessionfile\r
35    * @param watcher\r
36    * @param handler\r
37    * @param enableWatching\r
38    */\r
39   public SessionFileWatcherElement(SessionFile watcher, WatcherCallBack handler, boolean enableWatching) {\r
40     super(handler);\r
41     this.watched = watcher;\r
42     if (enableWatching)\r
43       enableWatch();\r
44     else\r
45       haltWatch();\r
46   }\r
47   /**\r
48    * @return the watched\r
49    */\r
50   public SessionFile getWatched() {\r
51     return watched;\r
52   }\r
53   protected String getSubject() {\r
54     return watched.sessionFile.toString();\r
55   }\r
56 }\r