2 package uk.ac.vamsas.client.simpleclient;
5 public class ClientSessionFileWatcherElement extends SessionFileWatcherElement {
7 private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(VamsasFileWatcherElement.class);
10 * count of watch cycle before considering there is no other active client.
12 private int timeoutBeforeLastCycle = -1;
14 private boolean isTimeOutEnable = false;
20 public ClientSessionFileWatcherElement(SessionFile watcher,
21 WatcherCallBack handler) {
22 super(watcher, handler);
28 * @param enableWatching
30 public ClientSessionFileWatcherElement(SessionFile watcher,
31 WatcherCallBack handler, boolean enableWatching) {
32 super(watcher, handler, enableWatching);
36 * @see uk.ac.vamsas.client.simpleclient.WatcherElement#doWatch()
37 * * @return true if the handler was called for a changeEvent
39 public boolean doWatch()
41 if (!watchForChange || handler==null)
42 { //log.debug("!watchForChange || handler==null");
46 initWatch(); // somehow not done the first time
51 doclock=watcher.getChangedState();
54 log.error("Whilst watching "+watcher.getSubject(), e);
56 // log.debug("got lock watcher");
59 this.cycleCountSinceModif ++;
60 if (this.isTimeOutEnable && cycleCountSinceModif > timeoutBeforeLastCycle)
62 if(this.handler != null )
63 synchronized (this.handler)
65 this.callHandler(doclock);
68 //log.debug("no modification");
71 if (this.isTimeOutEnable) this.cycleCountSinceModif =0; //change detected
72 if(this.handler != null )
73 synchronized (this.handler)
75 this.callHandler(doclock);
83 * count of cycles since last modification on the file
85 protected int cycleCountSinceModif =0;
88 * resets count of watch cycles (default value : 0)
91 protected void resetCycleCount ()
93 this.cycleCountSinceModif = 0;
97 * Increases the count of cycles
100 protected void increaseCycleCount ()
102 this.cycleCountSinceModif ++;
106 * Enable the time out if the timeout is greater than zero
107 * @param timeoutBeforeLastCycle the timeoutBeforeLastCycle to set
109 public void setTimeoutBeforeLastCycle(int timeoutBeforeLastCycle) {
111 this.timeoutBeforeLastCycle = timeoutBeforeLastCycle;
112 if (this.timeoutBeforeLastCycle>0)
113 isTimeOutEnable = true;
117 * Disables the checking on the count of cycles
120 public void disableCycleTimeOut ()
122 this.isTimeOutEnable = false;