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   *  U.S. Government, Department of the Army
15   *  Army Materiel Command
16   *  Research Development Engineering Command
17   *  Communications Electronics Research Development and Engineering Center
18   *  ---------------------------------------------------------------------------
19   */
20  package org.miloss.fgsms.services.rs.impl;
21  
22  import java.util.Queue;
23  import org.apache.log4j.Level;
24  import org.miloss.fgsms.services.interfaces.automatedreportingservice.ReportDefinition;
25  import org.miloss.fgsms.common.Logger;;
26  
27  /**
28   * Performs alerting functions when not running in Jboss (i.e. thread
29   * pooling)
30   *
31   * @author AO
32   */
33  public class RSRunner implements Runnable {
34  
35      private Queue<ReportDefinitionExtension> queue = null;
36  
37      RSRunner(Queue<ReportDefinitionExtension> q) {
38          queue = q;
39      }
40      static final Logger log = Logger.getLogger("fgsms.RSProcessor");
41  
42      @Override
43      public void run() {
44  
45          ReportDefinitionExtension poll = queue.poll();
46          while (poll != null) {
47              try {
48                  FgsmsReportGenerator r = new FgsmsReportGenerator();
49                  String id = r.GenerateReport(poll.def, poll.pooled);
50                  r.ProcessAlerts(poll.def, id, poll.pooled);
51              } catch (Exception e) {
52                  log.log(Level.ERROR, "Error trapped running the reporting job", e);
53              }
54              poll = queue.poll();
55  
56          }
57  
58          RSProcessorSingleton.running = false;
59          log.log(org.apache.log4j.Level.INFO, "fgsms RSProcessor Alerting thread is terminating, queue is empty.");
60      }
61  }