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.bueller;
22  
23  import java.util.List;
24  import javax.resource.spi.work.Work;
25  import org.apache.log4j.Level;
26  import org.miloss.fgsms.sla.AuxHelper;
27  import org.miloss.fgsms.sla.SLACommon;
28  
29  /**
30   *
31   * @author AO
32   */
33  public class BuellerWorker implements Work {
34  
35      private String url = "";
36      private boolean pooled = false;
37      private Bueller reference=null;
38      public BuellerWorker(String connecturl, boolean pooled, Bueller ref) {
39          this.pooled = pooled;
40          url = connecturl;
41          reference = ref;
42      }
43  
44      @Override
45      public void release() {
46      }
47  
48      @Override
49      public void run() {
50          try {
51              String s = reference.sendGetRequest(pooled, url,0);
52              Boolean currenstatus = s.equalsIgnoreCase("ok");
53              //log.log(Level.INFO, (i + 1) + "/" + urls.size() + " " + urls.get(i) + " status is " + s);
54              if (!currenstatus) {
55                  List<String> alts = reference.GetAlternateUrls(url, pooled);
56                  for (int k = 0; k < alts.size(); k++) {
57                      if (currenstatus) {
58                          break;
59                      }
60                      s = reference.sendGetRequest(pooled, alts.get(k),0);
61                      currenstatus = s.equalsIgnoreCase("ok");
62                      reference.log.log(Level.INFO, url + " via alternate URL " + alts.get(k) + " status is " + s);
63                  }
64              }
65              reference.log.log(Level.INFO, url + " status is " + s);
66              AuxHelper.TryUpdateStatus(currenstatus, url, s, pooled, AuxHelper.UNSPECIFIED, SLACommon.GetHostName());
67  
68          } catch (Exception ex) {
69              reference.log.log(Level.ERROR, "error setting status in config db for uri " + url + ex.getLocalizedMessage(), ex);
70          }
71      }
72  }