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 org.miloss.fgsms.common.DBSettingsLoader;
24  import org.miloss.fgsms.common.Logger;
25  import org.miloss.fgsms.services.interfaces.common.PolicyType;
26  import org.miloss.fgsms.services.interfaces.policyconfiguration.KeyNameValueEnc;
27  import org.miloss.fgsms.sla.AuxHelper;
28  import org.miloss.fgsms.sla.SLACommon;
29  import org.quartz.*;
30  
31  /**
32   * Quartz Job that kicks off the Apache ServiceMix and ActiveMQ
33   * agent
34   *
35   * @author AO
36   */
37  public class SMXJMXScheduler implements StatefulJob {
38  
39      private static Logger log = Logger.getLogger("fgsms.Agents");
40  
41      public void execute(JobExecutionContext jec) throws JobExecutionException {
42  
43          AuxHelper.TryUpdateStatus(true, "urn:fgsms:ServiceMixJMXAgent:" + SLACommon.GetHostName(), "OK", true, PolicyType.STATUS, AuxHelper.UNSPECIFIED, SLACommon.GetHostName());
44  
45          try {
46              KeyNameValueEnc item = DBSettingsLoader.GetPropertiesFromDB(true, "SMXJMXAgent", "URLs");
47              String t = null;
48              String[] urls = null;
49              try {
50                  if (item != null) {
51                      t = item.getKeyNameValue().getPropertyValue();
52                      urls = t.split("\\|");
53                  }
54              } catch (Exception ex) {
55              }
56  
57              if (urls != null) {
58                  for (int i = 0; i < urls.length; i++) {
59                      String connecturl = urls[i];
60                      String modifiedurl = org.miloss.fgsms.common.IpAddressUtility.modifyURL(connecturl, true);
61  
62                      org.miloss.fgsms.agents.smxviajmxagent.FgsmsSMXviaJMXAgent.Fire(true, connecturl, modifiedurl);
63  
64                  }
65              }
66          } catch (Exception ex) {
67              log.log(org.apache.log4j.Level.WARN, "Could not start the SMX JMX Agent ", ex);
68          }
69  
70          try {
71              KeyNameValueEnc interval = DBSettingsLoader.GetPropertiesFromDB(true, "SMXJMXAgent", "Interval");
72              long intinterval = 30000;
73              if (interval != null) {
74                  try {
75                      intinterval = Long.parseLong(interval.getKeyNameValue().getPropertyValue());
76                      if (intinterval < 1000) {
77                          intinterval = 1000;
78                      }
79                  } catch (Exception ex) {
80                  }
81              }
82  /*
83              Scheduler sc = jec.getScheduler();
84              if (sc.deleteJob(SMXJMXStarter.JOB_NAME, AuxConstants.QUARTZ_GROUP_NAME)) {
85                  JobDetail job = new JobDetail(SMXJMXStarter.JOB_NAME, AuxConstants.QUARTZ_GROUP_NAME, this.getClass());
86                  Trigger triger = TriggerUtils.makeSecondlyTrigger((int) (intinterval / 1000));
87                  triger.setStartTime(new Date());
88                  triger.setName(SMXJMXStarter.TRIGGER_NAME);
89                  triger.setGroup(AuxConstants.QUARTZ_TRIGGER_GROUP_NAME);
90                  job.setRequestsRecovery(true);
91                  GregorianCalendar gcal = new GregorianCalendar();
92                  gcal.setTimeInMillis(System.currentTimeMillis() + intinterval);
93                  triger.setStartTime(gcal.getTime());
94                  Date scheduleJob = sc.scheduleJob(job, triger);
95              }*/
96          } catch (Exception ex) {
97                  log.log(org.apache.log4j.Level.WARN, "Error adjusting schedule for SMX JMX Agent ", ex);
98          }
99      }
100 }