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.miloss.fgsms.sla.AuxHelper;
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 the UDDI Publisher when the servlet container
33   * starts
34   *
35   * @author AO
36   */
37  public class FederationStarter implements ServletContextListener {
38  
39      private static Scheduler sc;
40      static final Logger log = Logger.getLogger("fgsms.Aux");
41      public static final String JOB_NAME = "Federation Publisher";
42      public static final String TRIGGER_NAME = "Federation Publisher Trigger";
43  
44      public void contextInitialized(ServletContextEvent sce) {
45      }
46  
47      protected static void StartupCheck() {
48          try {
49  
50              sc = new StdSchedulerFactory().getScheduler(AuxConstants.QUARTZ_SCHEDULER_NAME);
51              if (sc == null) {
52                  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);
53              }
54  
55              JobDetail job = null;
56              Trigger triger = null;
57  
58              if (!AuxConstants.QuartzJobExists(JOB_NAME, sc)) {
59                  job = new JobDetail(JOB_NAME, AuxConstants.QUARTZ_GROUP_NAME, org.miloss.fgsms.auxsrv.FederationScheduler.class);
60                  triger = TriggerUtils.makeMinutelyTrigger(2);
61                  triger.setName(TRIGGER_NAME);
62                  triger.setGroup(AuxConstants.QUARTZ_TRIGGER_GROUP_NAME);
63                  sc.scheduleJob(job, triger);
64                  log.log(Level.INFO, "Federation Publisher job added");
65                  if (sc.isShutdown()) {
66                      log.log(Level.WARN, "starting quartz");
67                  }
68                  sc.start();
69              }
70          } catch (Exception ex) {
71              log.log(Level.WARN, "error scheduling Federation Publisher", ex);
72          }
73  
74      }
75  
76      public void contextDestroyed(ServletContextEvent sce) {
77          /*
78           * try { sc = new StdSchedulerFactory().getScheduler();
79           *
80           * sc.unscheduleJob("Uddi Publisher", "fgsms Aux Services ");
81           * sc.deleteJob("Uddi Publisher", "fgsms Aux Services ");
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 UDDI Publisher", ex); }
85           */
86      }
87  }