1 /**
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * If it is not possible or desirable to put the notice in a particular
7 * file, then You may include the notice in a location (such as a LICENSE
8 * file in a relevant directory) where a recipient would be likely to look
9 * for such a notice.
10
11 *
12 */
13
14 /* ---------------------------------------------------------------------------
15 * U.S. Government, Department of the Army
16 * Army Materiel Command
17 * Research Development Engineering Command
18 * Communications Electronics Research Development and Engineering Center
19 * ---------------------------------------------------------------------------
20 */
21 package org.miloss.fgsms.auxsrv;
22
23 import java.util.Date;
24 import javax.servlet.ServletContextEvent;
25 import javax.servlet.ServletContextListener;
26 import org.apache.log4j.Level;
27 import org.miloss.fgsms.common.Logger;;
28 import org.quartz.*;
29 import org.quartz.impl.StdSchedulerFactory;
30
31 /**
32 * Starts up DependencyScannerStarter when the servlet container
33 * starts
34 *
35 * @author AO
36 */
37 public class DependencyScannerStarter implements ServletContextListener {
38
39 public static final String JOB_NAME = "DependencyScanner";
40 public static final String TRIGGER_NAME = "DependencyScannerTrigger";
41 private static Scheduler sc;
42 static Logger log = Logger.getLogger("fgsms.Aux");
43
44 public void contextInitialized(ServletContextEvent sce) {
45 }
46
47 protected static void StartupCheck() {
48 JobDetail job = null;
49 Trigger triger = null;
50
51 try {
52 sc = new StdSchedulerFactory().getScheduler(AuxConstants.QUARTZ_SCHEDULER_NAME);
53 if (!AuxConstants.QuartzJobExists(JOB_NAME, sc)) {
54 job = new JobDetail(JOB_NAME, AuxConstants.QUARTZ_GROUP_NAME, org.miloss.fgsms.auxsrv.DependencyScannerScheduler.class);
55 triger = TriggerUtils.makeMinutelyTrigger(1);
56 triger.setStartTime(new Date());
57 triger.setName(TRIGGER_NAME);
58 triger.setGroup(AuxConstants.QUARTZ_TRIGGER_GROUP_NAME);
59 job.setRequestsRecovery(true);
60 sc.scheduleJob(job, triger);
61 log.log(Level.INFO, "DependencyScanner added");
62
63 if (sc.isShutdown()) {
64 log.log(Level.WARN, "starting quartz");
65 }
66 sc.start();
67 }
68 } catch (Exception ex) {
69 log.log(Level.WARN, "error scheduling ", ex);
70 }
71
72 }
73
74 public void contextDestroyed(ServletContextEvent sce) {
75 /*
76 * try { sc = new StdSchedulerFactory().getScheduler();
77 *
78 * sc.unscheduleJob("Status Bueller", "fgsms Aux Services ");
79 * sc.deleteJob("Status Bueller", "fgsms Aux Services ");
80 *
81 *
82 * log.log(Level.WARN, "Undeploying fgsms Aux Services Succeeded. Jobs
83 * removed from Quartz scheduler."); } catch (SchedulerException ex) {
84 * log.log(Level.WARN, "error unscheduling bueller", ex); }
85 */
86 }
87 }