From 895130c6f3d027f9976f55b8ed162dca5c0726b1 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 12 Jan 2007 15:39:22 +0000 Subject: [PATCH] untested watcherElement for spotting changes in SessionFlagFile presence/absence. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@337 be28352e-c001-0410-b1a7-c7978e42abec --- .../simpleclient/SessionFlagWatcherElement.java | 54 ++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/uk/ac/vamsas/client/simpleclient/SessionFlagWatcherElement.java diff --git a/src/uk/ac/vamsas/client/simpleclient/SessionFlagWatcherElement.java b/src/uk/ac/vamsas/client/simpleclient/SessionFlagWatcherElement.java new file mode 100644 index 0000000..8d70d9f --- /dev/null +++ b/src/uk/ac/vamsas/client/simpleclient/SessionFlagWatcherElement.java @@ -0,0 +1,54 @@ +package uk.ac.vamsas.client.simpleclient; + + +/** + * Element of the VamsasFileWatcherThread event generator chain. + * Keep a reference to this element before adding it to the chain + * in order to control the generation of events with halt and enable. + * + * doWatch will do nothing if the element is not enabled. + * TODO: TEST THIS CLASS - not yet used in SimpleClient + */ +public class SessionFlagWatcherElement extends WatcherElement { + SessionFlagFile watched=null; + /** + * create a new, enabled watch element + * @param watcher file being watched + * @param handler handler to call on state change + */ + public SessionFlagWatcherElement(SessionFlagFile watcher, WatcherCallBack handler) { + this(watcher, handler, true); + } + protected void initWatch() { + if (watched==null) + return; + watcher = new FileWatcher(watched.flagFile); + } + protected void endWatch() { + // leaves watcher in state its in. + } + /** + * new watcher with flag to initially skip watching this sessionfile + * @param watcher + * @param handler + * @param enableWatching + */ + public SessionFlagWatcherElement(SessionFlagFile watcher, WatcherCallBack handler, boolean enableWatching) { + super(handler); + this.watched = watcher; + if (enableWatching) + enableWatch(); + else + haltWatch(); + } + /** + * @return the watched + */ + public SessionFlagFile getWatched() { + return watched; + } + protected String getSubject() { + + return watched.flagFile.toString(); + } +} -- 1.7.10.2