KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > job > support > ExecutionTimeUpdater


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.job.support;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.riotfamily.riot.job.JobContext;
29
30 /**
31  * Task that updates the executionTime of active jobs. This is also done when
32  * {@link JobContext#stepCompleted() JobContext.stepCompleted()} is invoked,
33  * but in case a job takes a very long time to complete a step or it does not
34  * inform the JobContext about its progress, this fallback ensures that the
35  * executionTime is properly updated.
36  */

37 public class ExecutionTimeUpdater implements Runnable JavaDoc {
38
39     private Log log = LogFactory.getLog(ExecutionTimeUpdater.class);
40     
41     private TaskList taskList;
42     
43     private long updateInterval = 15000;
44     
45     private volatile Thread JavaDoc thread;
46     
47     public ExecutionTimeUpdater(TaskList taskList) {
48         this.taskList = taskList;
49     }
50
51     public void setUpdateInterval(long updateInterval) {
52         this.updateInterval = updateInterval;
53     }
54
55     public void stop() {
56         Thread JavaDoc thread = this.thread;
57         this.thread = null;
58         thread.interrupt();
59     }
60     
61     public void run() {
62         thread = Thread.currentThread();
63         while (thread != null) {
64             taskList.updateExecutionTimes();
65             try {
66                 Thread.sleep(updateInterval);
67                 taskList.waitForTasks();
68             }
69             catch (InterruptedException JavaDoc e) {
70             }
71         }
72         log.info("ExecutionTimeUpdater has been stopped.");
73     }
74
75 }
76
Popular Tags