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);
58 this.cycleCountSinceModif ++;
59 if (this.isTimeOutEnable && cycleCountSinceModif > timeoutBeforeLastCycle)
61 if(this.handler != null )
62 synchronized (this.handler)
64 this.callHandler(doclock);
67 //log.debug("no modification");
70 this.cycleCountSinceModif =0; //change detected
71 if(this.handler != null )
72 synchronized (this.handler)
74 this.callHandler(doclock);
82 * count of cycles since last modification on the file
84 protected int cycleCountSinceModif =0;
87 * resets count of watch cycles (default value : 0)
90 protected void resetCycleCount ()
92 this.cycleCountSinceModif = 0;
96 * Increases the count of cycles
99 protected void increaseCycleCount ()
101 this.cycleCountSinceModif ++;
105 * Enable the time out if the timeout is greater than zero
106 * @param timeoutBeforeLastCycle the timeoutBeforeLastCycle to set
108 public void setTimeoutBeforeLastCycle(int timeoutBeforeLastCycle) {
110 this.timeoutBeforeLastCycle = timeoutBeforeLastCycle;
111 if (this.timeoutBeforeLastCycle>0)
112 isTimeOutEnable = true;
116 * Disables the checking on the count of cycles
119 public void disableCycleTimeOut ()
121 this.isTimeOutEnable = false;