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 java.util.Date;
24  import java.util.GregorianCalendar;
25  import java.util.logging.Level;
26  import java.util.logging.Logger;
27  import org.miloss.fgsms.common.DBSettingsLoader;
28  import org.miloss.fgsms.services.interfaces.common.PolicyType;
29  import org.miloss.fgsms.services.interfaces.policyconfiguration.KeyNameValueEnc;
30  import org.miloss.fgsms.sla.AuxHelper;
31  import org.miloss.fgsms.sla.SLACommon;
32  import org.miloss.fgsms.statistics.FgsmsStatsv2;
33  import org.quartz.*;
34  
35  /**
36   * Quartz Job that kicks off the Statistics Aggregator
37   *
38   * @author AO
39   */
40  public class StatisticsAggregatorScheduler implements StatefulJob {
41  
42      public void execute(JobExecutionContext jec) throws JobExecutionException {
43          try {
44              org.miloss.fgsms.statistics.FgsmsStatsv2 s = new FgsmsStatsv2();
45              s.doWork(true);
46              AuxHelper.TryUpdateStatus(true, "urn:fgsms:StatisticsAggregator:" + SLACommon.GetHostName(), "OK", true, PolicyType.TRANSACTIONAL, AuxHelper.UNSPECIFIED, SLACommon.GetHostName());
47          } catch (Exception ex) {
48              AuxHelper.TryUpdateStatus(false, "urn:fgsms:StatisticsAggregator:" + SLACommon.GetHostName(), ex.getMessage(), true, PolicyType.TRANSACTIONAL, AuxHelper.UNSPECIFIED, SLACommon.GetHostName());
49          }
50  
51          try {
52              KeyNameValueEnc interval = DBSettingsLoader.GetPropertiesFromDB(true, "StatisticsAggregator", "Interval");
53              //defautl is 5 minutes
54              long intinterval = 5 * 60 * 1000;
55              if (interval != null) {
56                  try {
57                      intinterval = Long.parseLong(interval.getKeyNameValue().getPropertyValue());
58                      if (intinterval < 1000) {
59                          intinterval = 5 * 60 * 1000;
60                      }
61                  } catch (Exception ex) {
62                  }
63              }
64  /*
65              Scheduler sc = jec.getScheduler();
66              if (sc.deleteJob(StatisticsStarter.JOB_NAME, AuxConstants.QUARTZ_GROUP_NAME)) {
67                  JobDetail job = new JobDetail(StatisticsStarter.JOB_NAME, AuxConstants.QUARTZ_GROUP_NAME, this.getClass());
68                  Trigger triger = TriggerUtils.makeMinutelyTrigger((int) (intinterval / 60000));
69                  triger.setStartTime(new Date());
70                  triger.setName(StatisticsStarter.TRIGGER_NAME);
71                  triger.setGroup(AuxConstants.QUARTZ_TRIGGER_GROUP_NAME);
72                  job.setRequestsRecovery(true);
73                  GregorianCalendar gcal = new GregorianCalendar();
74                  gcal.setTimeInMillis(System.currentTimeMillis() + intinterval);
75                  triger.setStartTime(gcal.getTime());
76                  Date scheduleJob = sc.scheduleJob(job, triger);
77              }*/
78          } catch (Exception ex) {
79              Logger.getLogger(StatisticsAggregatorScheduler.class.getName()).log(Level.WARNING, "Error adjusting schedule", ex);
80          }
81  
82      }
83  }