1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.miloss.fgsms.auxsrv;
21
22 import java.util.Date;
23 import javax.servlet.ServletContextEvent;
24 import javax.servlet.ServletContextListener;
25 import org.apache.log4j.Level;
26 import org.miloss.fgsms.common.Logger;;
27 import org.quartz.*;
28 import org.quartz.impl.StdSchedulerFactory;
29
30
31
32
33
34
35
36 public class ReportGenStarter implements ServletContextListener {
37
38 public static final String JOB_NAME = "Report Generator";
39 public static final String TRIGGER_NAME = "Report Generator Trigger";
40 private static Scheduler sc;
41 static Logger log = Logger.getLogger("fgsms.Aux");
42
43 public void contextInitialized(ServletContextEvent sce) {
44 StartupCheck();
45
46 }
47
48 protected static void StartupCheck() {
49 JobDetail job = null;
50 Trigger triger = null;
51 try {
52 sc = new StdSchedulerFactory().getScheduler(AuxConstants.QUARTZ_SCHEDULER_NAME);
53 if (sc == null) {
54 log.fatal("Unable to reference the Quartz instance of " + AuxConstants.QUARTZ_SCHEDULER_NAME + " ensure that it exists and is started. Unable to schedule job for " + JOB_NAME);
55 }
56
57 if (!AuxConstants.QuartzJobExists(JOB_NAME, sc)) {
58 job = new JobDetail(JOB_NAME, AuxConstants.QUARTZ_GROUP_NAME, org.miloss.fgsms.auxsrv.ReportGenScheduler.class);
59 job.setRequestsRecovery(true);
60 triger = TriggerUtils.makeMinutelyTrigger();
61 triger.setStartTime(new Date());
62 triger.setName(TRIGGER_NAME);
63 triger.setGroup(AuxConstants.QUARTZ_TRIGGER_GROUP_NAME);
64 sc.scheduleJob(job, triger);
65 log.log(Level.INFO, "Report Generator added");
66 if (sc.isShutdown()) {
67 log.log(Level.WARN, "starting quartz");
68 }
69 sc.start();
70 }
71 } catch (Exception ex) {
72 log.log(Level.WARN, "error scheduling Report Generator", ex);
73 }
74 }
75
76 public void contextDestroyed(ServletContextEvent sce) {
77
78
79
80
81
82
83
84
85
86
87
88
89 }
90 }