01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: ExecutorThread.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.scheduler;
09:
10: import com.uwyn.rife.scheduler.exceptions.*;
11:
12: public class ExecutorThread implements Runnable {
13: private Executor mExecutor = null;
14: private Task mTask = null;
15:
16: public ExecutorThread(Executor executor, Task task) {
17: mExecutor = executor;
18: mTask = task;
19: }
20:
21: public void run() {
22: assert mTask != null;
23:
24: boolean successful_execution = false;
25: TaskManager manager = mExecutor.getScheduler().getTaskManager();
26:
27: try {
28: manager.activateTask(mTask.getId());
29: successful_execution = mExecutor.executeTask(mTask);
30: } catch (TaskManagerException e) {
31: successful_execution = false;
32: } finally {
33: try {
34: if (!successful_execution) {
35: manager.rescheduleTask(mTask, mExecutor
36: .getRescheduleDelay(), null);
37: }
38: manager.concludeTask(mTask);
39: } catch (TaskManagerException e) {
40: throw new FatalTaskExecutionException(mTask, e);
41: }
42: }
43: }
44: }
|