1 package org.jbpm.scheduler.impl; 2 3 import java.util.Date ; 4 import java.util.LinkedList ; 5 import java.util.List ; 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 historyLogs = new LinkedList (); 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 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 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 |