X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fuk%2Fac%2Fvamsas%2Fclient%2Fsimpleclient%2FWatcherElement.java;h=b3235d54af0f3fb0f5cf534cb04a2dd39f88a2a2;hb=1e940bf58bbd9f228ff991b5ee6e5b38c36a78fe;hp=54a31bef52fcae411559a33a408f41d9ac98ae7d;hpb=951950b43682e270a94c1213d67c3918adc414fc;p=vamsas.git diff --git a/src/uk/ac/vamsas/client/simpleclient/WatcherElement.java b/src/uk/ac/vamsas/client/simpleclient/WatcherElement.java index 54a31be..b3235d5 100644 --- a/src/uk/ac/vamsas/client/simpleclient/WatcherElement.java +++ b/src/uk/ac/vamsas/client/simpleclient/WatcherElement.java @@ -10,7 +10,7 @@ public abstract class WatcherElement { /** * set this to false to stop the thread */ - private boolean watchForChange = true; + protected boolean watchForChange = true; /** * true when the handler is being called for this watcher */ @@ -24,13 +24,13 @@ public abstract class WatcherElement { * before returning. If no thread is running then it returns immediately. */ public void haltWatch() { - if (log.isDebugEnabled()) - log.debug("haltWatch on "+watcher.getSubject()); // set the flag to skip this watch element. watchForChange=false; + if (log.isDebugEnabled()) + log.debug("haltWatch on "+watcher.getSubject()); endWatch(); - // watcher=null; - + if (log.isDebugEnabled()) + log.debug("haltWatch completed on "+watcher.getSubject()); } /** * called by haltWatch before @@ -54,6 +54,8 @@ public abstract class WatcherElement { * enablewatch */ protected void enableWatch() { + if (log.isDebugEnabled()) + log.debug("enableWatch on "+getSubject()); watchForChange=true; initWatch(); if (log.isDebugEnabled()) @@ -78,7 +80,7 @@ public abstract class WatcherElement { } if (doclock==null) return false; - handlerCalled=true; + /* handlerCalled=true; if (log.isDebugEnabled()) log.debug("Triggering watchEvent for change on "+watcher.getSubject()); boolean finish=!handler.handleWatchEvent(this, doclock); @@ -87,11 +89,30 @@ public abstract class WatcherElement { haltWatch(); else enableWatch(); - handlerCalled=false; + handlerCalled=false;*/ + this.callHandler(doclock); return true; } /** + * Calls the current eventhandler + * + * @param doclock the lock on the watch file + */ + protected void callHandler(Lock doclock) + { + if (log.isDebugEnabled()) + log.debug("Triggering watchEvent for change on "+watcher.getSubject()); + boolean finish=!handler.handleWatchEvent(this, doclock); + doclock=null; // TODO: check that lock should really be released rather than dereferenced + if (finish) + haltWatch(); + else + enableWatch(); + handlerCalled=false; + } + + /** * @return the handler */ public WatcherCallBack getHandler() {