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