View Javadoc
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 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   * Starts up the Data Pruner when the servlet container
32   * starts
33   *
34   * @author AO
35   */
36  public class DataPrunerStarter implements ServletContextListener {
37  
38      public static final String JOB_NAME = "Data Pruner";
39      public static final String TRIGGER_NAME = "Data Pruner 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  
52          try {
53              sc = new StdSchedulerFactory().getScheduler(AuxConstants.QUARTZ_SCHEDULER_NAME);
54              if (sc == null) {
55                  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);
56              }
57  
58              if (!AuxConstants.QuartzJobExists(JOB_NAME, sc)) {
59                  job = new JobDetail(JOB_NAME, AuxConstants.QUARTZ_GROUP_NAME, org.miloss.fgsms.auxsrv.DataPrunerScheduler.class);
60                  job.setRequestsRecovery(true);
61                  triger = TriggerUtils.makeMinutelyTrigger(2);
62                  triger.setGroup(AuxConstants.QUARTZ_TRIGGER_GROUP_NAME);
63                  triger.setName(TRIGGER_NAME);
64                  sc.scheduleJob(job, triger);
65                  log.log(Level.INFO, "Data Pruner job 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 data pruner", ex);
73          }
74      }
75  
76      public void contextDestroyed(ServletContextEvent sce) {
77      }
78  }