1 package org.jbpm.scheduler.impl; 2 3 import java.text.DateFormat ; 4 import java.text.SimpleDateFormat ; 5 import java.util.Date ; 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 SchedulerMain { 12 13 static DateFormat dateFormat = null; 14 15 public static void main(String [] args) { 16 18 Scheduler scheduler = new Scheduler(); 20 21 int interval = Integer.parseInt(getParameter(args, 0, "5000")); 23 scheduler.setInterval(interval); 24 int historyMaxSize = Integer.parseInt(getParameter(args, 1, "50")); 25 scheduler.setHistoryMaxSize(historyMaxSize); 26 dateFormat = new SimpleDateFormat (getParameter(args, 2, "dd/MM/yyyy HH:mm:ss")); 27 28 scheduler.getSchedulerThread().addListener(new LogListener()); 30 31 scheduler.start(); 33 } 34 35 private static final String NEWLINE = System.getProperty("line.separator"); 36 private static class LogListener implements SchedulerListener { 37 public void timerExecuted(Date date, Timer timer) { 38 StringBuffer buffer = new StringBuffer (); 39 buffer.append(dateFormat.format(date)); 40 buffer.append(" | "); 41 buffer.append(timer.toString()); 42 buffer.append(" | "); 43 if (timer.getException()==null) { 44 buffer.append("OK |"); 45 } else { 46 buffer.append("exception..."); 47 buffer.append(NEWLINE); 48 buffer.append(timer.getException()); 49 buffer.append(NEWLINE); 50 } 51 log.info(buffer.toString()); 52 } 53 } 54 55 private static String getParameter(String [] args, int index, String defaultValue) { 56 String value = null; 57 if ( (args!=null) 58 && (args.length>index) 59 ) { 60 value = args[index]; 61 } else { 62 value = defaultValue; 63 } 64 return value; 65 } 66 67 private static final Log log = LogFactory.getLog(SchedulerMain.class); 68 } 69 | Popular Tags |