| 1 | 
 tdb | 
 1.8 | 
 /*  | 
 
 
 
 
 
 | 2 | 
   | 
   | 
  * i-scream central monitoring system | 
 
 
 
 
 
 | 3 | 
   | 
   | 
  * Copyright (C) 2000-2002 i-scream | 
 
 
 
 
 
 | 4 | 
   | 
   | 
  *  | 
 
 
 
 
 
 | 5 | 
   | 
   | 
  * This program is free software; you can redistribute it and/or | 
 
 
 
 
 
 | 6 | 
   | 
   | 
  * modify it under the terms of the GNU General Public License | 
 
 
 
 
 
 | 7 | 
   | 
   | 
  * as published by the Free Software Foundation; either version 2 | 
 
 
 
 
 
 | 8 | 
   | 
   | 
  * of the License, or (at your option) any later version. | 
 
 
 
 
 
 | 9 | 
   | 
   | 
  *  | 
 
 
 
 
 
 | 10 | 
   | 
   | 
  * This program is distributed in the hope that it will be useful, | 
 
 
 
 
 
 | 11 | 
   | 
   | 
  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 
 
 
 
 
 | 12 | 
   | 
   | 
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 
 
 
 
 
 | 13 | 
   | 
   | 
  * GNU General Public License for more details. | 
 
 
 
 
 
 | 14 | 
   | 
   | 
  *  | 
 
 
 
 
 
 | 15 | 
   | 
   | 
  * You should have received a copy of the GNU General Public License | 
 
 
 
 
 
 | 16 | 
   | 
   | 
  * along with this program; if not, write to the Free Software | 
 
 
 
 
 
 | 17 | 
   | 
   | 
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
 
 
 
 
 
 | 18 | 
   | 
   | 
  */ | 
 
 
 
 
 
 | 19 | 
   | 
   | 
  | 
 
 
 
 
 
 
 
 
 | 20 | 
 ab11 | 
 1.2 | 
 //---PACKAGE DECLARATION--- | 
 
 
 
 
 
 
 
 
 | 21 | 
 ab11 | 
 1.1 | 
  | 
 
 
 
 
 
 
 
 
 | 22 | 
 ab11 | 
 1.2 | 
 //---IMPORTS--- | 
 
 
 
 
 
 | 23 | 
   | 
   | 
  | 
 
 
 
 
 
 | 24 | 
   | 
   | 
 /** | 
 
 
 
 
 
 | 25 | 
   | 
   | 
  * A small efficient JavaHost | 
 
 
 
 
 
 | 26 | 
   | 
   | 
  * Designed to be used as a working design to build the C++ hosts on. | 
 
 
 
 
 
 | 27 | 
   | 
   | 
  * Hopefully fully functional and thus can be used as part of a test rig. | 
 
 
 
 
 
 | 28 | 
   | 
   | 
  * | 
 
 
 
 
 
 
 
 
 | 29 | 
 tdb | 
 1.8 | 
  * @author  $Author: ab11 $ | 
 
 
 
 
 
 | 30 | 
   | 
   | 
  * @version $Id: JavaHost.java,v 1.7 2001/03/19 17:30:17 ab11 Exp $ | 
 
 
 
 
 
 
 
 
 | 31 | 
 ab11 | 
 1.2 | 
  */ | 
 
 
 
 
 
 
 
 
 | 32 | 
 ab11 | 
 1.1 | 
 class JavaHost { | 
 
 
 
 
 
 
 
 
 | 33 | 
 ab11 | 
 1.2 | 
      | 
 
 
 
 
 
 | 34 | 
   | 
   | 
 //---FINAL ATTRIBUTES--- | 
 
 
 
 
 
 | 35 | 
   | 
   | 
  | 
 
 
 
 
 
 | 36 | 
   | 
   | 
 //---STATIC METHODS--- | 
 
 
 
 
 
 | 37 | 
   | 
   | 
  | 
 
 
 
 
 
 | 38 | 
   | 
   | 
 //---CONSTRUCTORS--- | 
 
 
 
 
 
 | 39 | 
   | 
   | 
      | 
 
 
 
 
 
 | 40 | 
   | 
   | 
     /** | 
 
 
 
 
 
 | 41 | 
   | 
   | 
      * Constructor for the class. Takes in the hostname and port number | 
 
 
 
 
 
 
 
 
 | 42 | 
 tdb | 
 1.4 | 
      * of the Filter Manager. | 
 
 
 
 
 
 
 
 
 | 43 | 
 ab11 | 
 1.2 | 
      * | 
 
 
 
 
 
 | 44 | 
   | 
   | 
      */ | 
 
 
 
 
 
 | 45 | 
   | 
   | 
     public JavaHost( String serverName, int port ){ | 
 
 
 
 
 
 
 
 
 | 46 | 
 tdb | 
 1.4 | 
         // create a connection to the filter manager | 
 
 
 
 
 
 | 47 | 
   | 
   | 
         System.out.println("Creating connection with Filter Manager"); | 
 
 
 
 
 
 
 
 
 | 48 | 
 ab11 | 
 1.2 | 
         Config config = new Config(serverName, port); | 
 
 
 
 
 
 | 49 | 
   | 
   | 
         // the config class knows what values it wants to get from | 
 
 
 
 
 
 
 
 
 | 50 | 
 tdb | 
 1.4 | 
         // the configuration system | 
 
 
 
 
 
 
 
 
 | 51 | 
 ab11 | 
 1.2 | 
          | 
 
 
 
 
 
 
 
 
 | 52 | 
 tdb | 
 1.4 | 
         // create a SystemMonitor object and pass the config | 
 
 
 
 
 
 
 
 
 | 53 | 
 ab11 | 
 1.2 | 
         // as a param so it knows what to do! | 
 
 
 
 
 
 
 
 
 | 54 | 
 ab11 | 
 1.3 | 
         System.out.println("Creating System Monitor"); | 
 
 
 
 
 
 
 
 
 | 55 | 
 ab11 | 
 1.2 | 
         SystemMonitor sysMon = new SystemMonitor(config); | 
 
 
 
 
 
 | 56 | 
   | 
   | 
          | 
 
 
 
 
 
 
 
 
 | 57 | 
 ab11 | 
 1.5 | 
         try { | 
 
 
 
 
 
 
 
 
 | 58 | 
 ab11 | 
 1.7 | 
             udpcheckInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000; | 
 
 
 
 
 
 | 59 | 
   | 
   | 
             System.out.println("Configured UDPUpdateTime"); | 
 
 
 
 
 
 
 
 
 | 60 | 
 ab11 | 
 1.5 | 
         } | 
 
 
 
 
 
 | 61 | 
   | 
   | 
         catch ( NumberFormatException e ){ | 
 
 
 
 
 
 
 
 
 | 62 | 
 ab11 | 
 1.7 | 
             System.out.println("The value for UDPUpdateTime is invalid, using a default"); | 
 
 
 
 
 
 | 63 | 
   | 
   | 
             // 1 mins | 
 
 
 
 
 
 | 64 | 
   | 
   | 
             udpcheckInterval = 1000 * 60;  // 1 minute | 
 
 
 
 
 
 
 
 
 | 65 | 
 ab11 | 
 1.5 | 
         } | 
 
 
 
 
 
 | 66 | 
   | 
   | 
          | 
 
 
 
 
 
 | 67 | 
   | 
   | 
         try { | 
 
 
 
 
 
 
 
 
 | 68 | 
 ab11 | 
 1.7 | 
             tcpcheckInterval = Long.parseLong(config.getProperty("TCPUpdateTime")) * 1000; | 
 
 
 
 
 
 | 69 | 
   | 
   | 
             System.out.println("Configured TCPUpdateTime"); | 
 
 
 
 
 
 
 
 
 | 70 | 
 ab11 | 
 1.5 | 
         } | 
 
 
 
 
 
 | 71 | 
   | 
   | 
         catch ( NumberFormatException e ){ | 
 
 
 
 
 
 
 
 
 | 72 | 
 ab11 | 
 1.7 | 
             System.out.println("The value for UDPUpdateTime is invalid, using a default"); | 
 
 
 
 
 
 | 73 | 
   | 
   | 
             // 10 mins | 
 
 
 
 
 
 | 74 | 
   | 
   | 
             tcpcheckInterval = 10000 * 60;  // 5 minutes | 
 
 
 
 
 
 
 
 
 | 75 | 
 ab11 | 
 1.5 | 
         } | 
 
 
 
 
 
 | 76 | 
   | 
   | 
          | 
 
 
 
 
 
 | 77 | 
   | 
   | 
         // the current time.. | 
 
 
 
 
 
 | 78 | 
   | 
   | 
         long currentTime = System.currentTimeMillis(); | 
 
 
 
 
 
 | 79 | 
   | 
   | 
         long nextUDP = currentTime + udpcheckInterval; | 
 
 
 
 
 
 | 80 | 
   | 
   | 
         long nextTCP = currentTime + tcpcheckInterval; | 
 
 
 
 
 
 | 81 | 
   | 
   | 
          | 
 
 
 
 
 
 
 
 
 | 82 | 
 ab11 | 
 1.2 | 
         while ( true ){ | 
 
 
 
 
 
 
 
 
 | 83 | 
 ab11 | 
 1.5 | 
             currentTime = System.currentTimeMillis(); | 
 
 
 
 
 
 
 
 
 | 84 | 
 ab11 | 
 1.2 | 
             // keep going for ever and ever ;) | 
 
 
 
 
 
 
 
 
 | 85 | 
 ab11 | 
 1.5 | 
              | 
 
 
 
 
 
 | 86 | 
   | 
   | 
             if ( nextTCP < nextUDP ){ | 
 
 
 
 
 
 
 
 
 | 87 | 
 ab11 | 
 1.7 | 
                 try { | 
 
 
 
 
 
 | 88 | 
   | 
   | 
                     long sleeptime = nextTCP - currentTime; | 
 
 
 
 
 
 | 89 | 
   | 
   | 
                     if ( sleeptime > 0 ){ | 
 
 
 
 
 
 | 90 | 
   | 
   | 
                         Thread.sleep(sleeptime); | 
 
 
 
 
 
 | 91 | 
   | 
   | 
                     } | 
 
 
 
 
 
 | 92 | 
   | 
   | 
                     nextTCP += tcpcheckInterval; | 
 
 
 
 
 
 | 93 | 
   | 
   | 
                     // send a heartbeat | 
 
 
 
 
 
 | 94 | 
   | 
   | 
                     //System.out.println("Sending Heartbeat"); | 
 
 
 
 
 
 
 
 
 | 95 | 
 tdb | 
 1.6 | 
                         System.out.print("+"); | 
 
 
 
 
 
 
 
 
 | 96 | 
 ab11 | 
 1.7 | 
                 config.sendHeartBeat(); | 
 
 
 
 
 
 | 97 | 
   | 
   | 
                 if ( config.reloadConfig() ){ | 
 
 
 
 
 
 | 98 | 
   | 
   | 
                     System.out.println("\nRestarting System"); | 
 
 
 
 
 
 | 99 | 
   | 
   | 
                     break;   | 
 
 
 
 
 
 | 100 | 
   | 
   | 
                 } | 
 
 
 
 
 
 | 101 | 
   | 
   | 
          } | 
 
 
 
 
 
 | 102 | 
   | 
   | 
          catch ( InterruptedException e ){ | 
 
 
 
 
 
 | 103 | 
   | 
   | 
             // do nothing | 
 
 
 
 
 
 | 104 | 
   | 
   | 
          } | 
 
 
 
 
 
 
 
 
 | 105 | 
 ab11 | 
 1.3 | 
             } | 
 
 
 
 
 
 
 
 
 | 106 | 
 ab11 | 
 1.5 | 
             else { | 
 
 
 
 
 
 
 
 
 | 107 | 
 ab11 | 
 1.7 | 
                 try { | 
 
 
 
 
 
 | 108 | 
   | 
   | 
                     long sleeptime = nextUDP - currentTime; | 
 
 
 
 
 
 | 109 | 
   | 
   | 
                     if ( sleeptime > 0 ){ | 
 
 
 
 
 
 | 110 | 
   | 
   | 
                         Thread.sleep(sleeptime); | 
 
 
 
 
 
 | 111 | 
   | 
   | 
                     } | 
 
 
 
 
 
 | 112 | 
   | 
   | 
                     nextUDP += udpcheckInterval; | 
 
 
 
 
 
 | 113 | 
   | 
   | 
                     // send a heartbeat | 
 
 
 
 
 
 | 114 | 
   | 
   | 
                 //System.out.println("Sending UDP Packet"); | 
 
 
 
 
 
 | 115 | 
   | 
   | 
                 System.out.print("."); | 
 
 
 
 
 
 | 116 | 
   | 
   | 
                     LowLevelNet.sendUDPPacket(config, sysMon.getInfo());   | 
 
 
 
 
 
 
 
 
 | 117 | 
 ab11 | 
 1.5 | 
              | 
 
 
 
 
 
 
 
 
 | 118 | 
 ab11 | 
 1.7 | 
          } | 
 
 
 
 
 
 | 119 | 
   | 
   | 
          catch ( InterruptedException e ){ | 
 
 
 
 
 
 | 120 | 
   | 
   | 
             // do nothing | 
 
 
 
 
 
 | 121 | 
   | 
   | 
          }   | 
 
 
 
 
 
 
 
 
 | 122 | 
 ab11 | 
 1.5 | 
             } | 
 
 
 
 
 
 | 123 | 
   | 
   | 
              | 
 
 
 
 
 
 | 124 | 
   | 
   | 
              | 
 
 
 
 
 
 | 125 | 
   | 
   | 
              | 
 
 
 
 
 
 
 
 
 | 126 | 
 ab11 | 
 1.3 | 
         } // while | 
 
 
 
 
 
 
 
 
 | 127 | 
 ab11 | 
 1.2 | 
          | 
 
 
 
 
 
 
 
 
 | 128 | 
 ab11 | 
 1.3 | 
             | 
 
 
 
 
 
 
 
 
 | 129 | 
 ab11 | 
 1.2 | 
     } // public javahost | 
 
 
 
 
 
 | 130 | 
   | 
   | 
  | 
 
 
 
 
 
 | 131 | 
   | 
   | 
  | 
 
 
 
 
 
 | 132 | 
   | 
   | 
 //---PUBLIC METHODS--- | 
 
 
 
 
 
 | 133 | 
   | 
   | 
  | 
 
 
 
 
 
 | 134 | 
   | 
   | 
 //---PRIVATE METHODS--- | 
 
 
 
 
 
 | 135 | 
   | 
   | 
  | 
 
 
 
 
 
 | 136 | 
   | 
   | 
 //---ACCESSOR/MUTATOR METHODS--- | 
 
 
 
 
 
 | 137 | 
   | 
   | 
  | 
 
 
 
 
 
 | 138 | 
   | 
   | 
 //---ATTRIBUTES--- | 
 
 
 
 
 
 
 
 
 | 139 | 
 ab11 | 
 1.5 | 
  | 
 
 
 
 
 
 | 140 | 
   | 
   | 
     private long udpcheckInterval; | 
 
 
 
 
 
 | 141 | 
   | 
   | 
     private long tcpcheckInterval; | 
 
 
 
 
 
 | 142 | 
   | 
   | 
     private final long defaultUpdateTime = 60000; | 
 
 
 
 
 
 | 143 | 
   | 
   | 
  | 
 
 
 
 
 
 
 
 
 | 144 | 
 ab11 | 
 1.2 | 
  | 
 
 
 
 
 
 | 145 | 
   | 
   | 
 //---STATIC ATTRIBUTES--- | 
 
 
 
 
 
 | 146 | 
   | 
   | 
  | 
 
 
 
 
 
 
 
 
 | 147 | 
 tdb | 
 1.6 | 
 } // class |