KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > scheduler > impl > Scheduler


1 package org.jbpm.scheduler.impl;
2
3 import java.util.Date JavaDoc;
4 import java.util.LinkedList JavaDoc;
5 import java.util.List JavaDoc;
6
7 import org.apache.commons.logging.Log;
8 import org.apache.commons.logging.LogFactory;
9 import org.jbpm.scheduler.exe.Timer;
10
11 public class Scheduler {
12   
13   SchedulerThread schedulerThread = null;
14   LinkedList JavaDoc historyLogs = new LinkedList JavaDoc();
15   int interval = 5000;
16   int historyMaxSize = 30;
17   
18   public void start() {
19     log.debug("starting the scheduler");
20     schedulerThread = new SchedulerThread();
21     schedulerThread.setInterval(interval);
22     schedulerThread.addListener(new HistoryListener());
23     schedulerThread.start();
24   }
25
26   public void stop() {
27     if (isRunning()) {
28       log.debug("stopping the scheduler");
29       schedulerThread.keepRunning = false;
30       schedulerThread.interrupt();
31       schedulerThread = null;
32     } else {
33       log.debug("scheduler can't be stopped cause it was not running");
34     }
35   }
36   
37   public boolean isRunning() {
38     return ( (schedulerThread!=null)
39              && (schedulerThread.isAlive()) );
40   }
41   
42   public List JavaDoc getSchedulerHistoryLogs() {
43     return historyLogs;
44   }
45
46   public void clearSchedulerHistoryLogs() {
47     historyLogs.clear();
48   }
49
50   class HistoryListener implements SchedulerListener {
51     public void timerExecuted(Date JavaDoc date, Timer timer) {
52       historyLogs.add(new SchedulerHistoryLog(date, timer));
53       if (historyLogs.size()>historyMaxSize) {
54         historyLogs.removeLast();
55       }
56     }
57   }
58   
59   public int getHistoryMaxSize() {
60     return historyMaxSize;
61   }
62   public void setHistoryMaxSize(int historyMaxSize) {
63     this.historyMaxSize = historyMaxSize;
64   }
65   public int getInterval() {
66     return interval;
67   }
68   public void setInterval(int interval) {
69     this.interval = interval;
70   }
71   public SchedulerThread getSchedulerThread() {
72     return schedulerThread;
73   }
74   
75   private static final Log log = LogFactory.getLog(Scheduler.class);
76 }
77
Popular Tags