KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.scheduler.impl;
2
3 import java.text.DateFormat JavaDoc;
4 import java.text.SimpleDateFormat JavaDoc;
5 import java.util.Date 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 SchedulerMain {
12
13   static DateFormat JavaDoc dateFormat = null;
14
15   public static void main(String JavaDoc[] args) {
16     // java SchedulerMain <interval> <historyMaxSize> <dateFormat>
17

18     // create a new scheduler
19
Scheduler scheduler = new Scheduler();
20     
21     // initialize it with the command line parameters
22
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 JavaDoc(getParameter(args, 2, "dd/MM/yyyy HH:mm:ss"));
27     
28     // register the console listener
29
scheduler.getSchedulerThread().addListener(new LogListener());
30     
31     // start the scheduler
32
scheduler.start();
33   }
34
35   private static final String JavaDoc NEWLINE = System.getProperty("line.separator");
36   private static class LogListener implements SchedulerListener {
37     public void timerExecuted(Date JavaDoc date, Timer timer) {
38       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
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 JavaDoc getParameter(String JavaDoc[] args, int index, String JavaDoc defaultValue) {
56     String JavaDoc 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