-
-package uk.ac.vamsas.client.simpleclient;
-
-
-public class ClientSessionFileWatcherElement extends SessionFileWatcherElement {
-
- private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(VamsasFileWatcherElement.class);
-
- /**
- * count of watch cycle before considering there is no other active client.
- */
- private int timeoutBeforeLastCycle = -1;
-
- private boolean isTimeOutEnable = false;
-
- /**
- * @param watcher
- * @param handler
- */
- public ClientSessionFileWatcherElement(SessionFile watcher,
- WatcherCallBack handler) {
- super(watcher, handler);
- }
-
- /**
- * @param watcher
- * @param handler
- * @param enableWatching
- */
- public ClientSessionFileWatcherElement(SessionFile watcher,
- WatcherCallBack handler, boolean enableWatching) {
- super(watcher, handler, enableWatching);
- }
-
- /**
- * @see uk.ac.vamsas.client.simpleclient.WatcherElement#doWatch()
- * * @return true if the handler was called for a changeEvent
- */
- public boolean doWatch()
- {
- if (!watchForChange || handler==null)
- { //log.debug("!watchForChange || handler==null");
- return false;
- }
- if (watcher==null)
- initWatch(); // somehow not done the first time
- handlerCalled=false;
- Lock doclock=null;
- try
- {
- doclock=watcher.getChangedState();
- }
- catch (Exception e) {
- log.error("Whilst watching "+watcher.getSubject(), e);
- }
- // log.debug("got lock watcher");
- if (doclock==null)
- {//no change detected
- this.cycleCountSinceModif ++;
- if (this.isTimeOutEnable && cycleCountSinceModif > timeoutBeforeLastCycle)
- {
- if(this.handler != null )
- synchronized (this.handler)
- {
- this.callHandler(doclock);
- }
- }
- //log.debug("no modification");
- return false;
- }
- if (this.isTimeOutEnable) this.cycleCountSinceModif =0; //change detected
- if(this.handler != null )
- synchronized (this.handler)
- {
- this.callHandler(doclock);
- }
-
- return true;
- }
-
-
- /**
- * count of cycles since last modification on the file
- */
- protected int cycleCountSinceModif =0;
-
- /**
- * resets count of watch cycles (default value : 0)
- *
- */
- protected void resetCycleCount ()
- {
- this.cycleCountSinceModif = 0;
- }
-
- /**
- * Increases the count of cycles
- *
- */
- protected void increaseCycleCount ()
- {
- this.cycleCountSinceModif ++;
- }
-
- /**
- * Enable the time out if the timeout is greater than zero
- * @param timeoutBeforeLastCycle the timeoutBeforeLastCycle to set
- */
- public void setTimeoutBeforeLastCycle(int timeoutBeforeLastCycle) {
-
- this.timeoutBeforeLastCycle = timeoutBeforeLastCycle;
- if (this.timeoutBeforeLastCycle>0)
- isTimeOutEnable = true;
- }
-
- /**
- * Disables the checking on the count of cycles
- *
- */
- public void disableCycleTimeOut ()
- {
- this.isTimeOutEnable = false;
- }
-}
+/*\r
+ * This file is part of the Vamsas Client version 0.1. \r
+ * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
+ * Andrew Waterhouse and Dominik Lindner.\r
+ * \r
+ * Earlier versions have also been incorporated into Jalview version 2.4 \r
+ * since 2008, and TOPALi version 2 since 2007.\r
+ * \r
+ * The Vamsas Client is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Lesser General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ * \r
+ * The Vamsas Client is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Lesser General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU Lesser General Public License\r
+ * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package uk.ac.vamsas.client.simpleclient;\r
+\r
+public class ClientSessionFileWatcherElement extends SessionFileWatcherElement {\r
+\r
+ private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory\r
+ .getLog(VamsasFileWatcherElement.class);\r
+\r
+ /**\r
+ * count of watch cycle before considering there is no other active client.\r
+ */\r
+ private int timeoutBeforeLastCycle = -1;\r
+\r
+ private boolean isTimeOutEnable = false;\r
+\r
+ /**\r
+ * @param watcher\r
+ * @param handler\r
+ */\r
+ public ClientSessionFileWatcherElement(SessionFile watcher,\r
+ WatcherCallBack handler) {\r
+ super(watcher, handler);\r
+ }\r
+\r
+ /**\r
+ * @param watcher\r
+ * @param handler\r
+ * @param enableWatching\r
+ */\r
+ public ClientSessionFileWatcherElement(SessionFile watcher,\r
+ WatcherCallBack handler, boolean enableWatching) {\r
+ super(watcher, handler, enableWatching);\r
+ }\r
+\r
+ /**\r
+ * @see uk.ac.vamsas.client.simpleclient.WatcherElement#doWatch() * @return\r
+ * true if the handler was called for a changeEvent\r
+ */\r
+ public boolean doWatch() {\r
+ if (!watchForChange || handler == null) { // log.debug("!watchForChange || handler==null");\r
+ return false;\r
+ }\r
+ if (watcher == null)\r
+ initWatch(); // somehow not done the first time\r
+ handlerCalled = false;\r
+ Lock doclock = null;\r
+ try {\r
+ doclock = watcher.getChangedState();\r
+ } catch (Exception e) {\r
+ log.error("Whilst watching " + watcher.getSubject(), e);\r
+ }\r
+ // log.debug("got lock watcher");\r
+ if (doclock == null) {// no change detected\r
+ this.cycleCountSinceModif++;\r
+ if (this.isTimeOutEnable && cycleCountSinceModif > timeoutBeforeLastCycle) {\r
+ if (this.handler != null)\r
+ synchronized (this.handler) {\r
+ this.callHandler(doclock);\r
+ }\r
+ }\r
+ // log.debug("no modification");\r
+ return false;\r
+ }\r
+ if (this.isTimeOutEnable)\r
+ this.cycleCountSinceModif = 0; // change detected\r
+ if (this.handler != null)\r
+ synchronized (this.handler) {\r
+ this.callHandler(doclock);\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ /**\r
+ * count of cycles since last modification on the file\r
+ */\r
+ protected int cycleCountSinceModif = 0;\r
+\r
+ /**\r
+ * resets count of watch cycles (default value : 0)\r
+ * \r
+ */\r
+ protected void resetCycleCount() {\r
+ this.cycleCountSinceModif = 0;\r
+ }\r
+\r
+ /**\r
+ * Increases the count of cycles\r
+ * \r
+ */\r
+ protected void increaseCycleCount() {\r
+ this.cycleCountSinceModif++;\r
+ }\r
+\r
+ /**\r
+ * Enable the time out if the timeout is greater than zero\r
+ * \r
+ * @param timeoutBeforeLastCycle\r
+ * the timeoutBeforeLastCycle to set\r
+ */\r
+ public void setTimeoutBeforeLastCycle(int timeoutBeforeLastCycle) {\r
+\r
+ this.timeoutBeforeLastCycle = timeoutBeforeLastCycle;\r
+ if (this.timeoutBeforeLastCycle > 0)\r
+ isTimeOutEnable = true;\r
+ }\r
+\r
+ /**\r
+ * Disables the checking on the count of cycles\r
+ * \r
+ */\r
+ public void disableCycleTimeOut() {\r
+ this.isTimeOutEnable = false;\r
+ }\r
+}\r