ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/java/JavaHost.java
(Generate patch)

Comparing projects/cms/source/host/java/JavaHost.java (file contents):
Revision 1.2 by ab11, Mon Nov 27 20:36:20 2000 UTC vs.
Revision 1.8 by tdb, Sat May 18 18:15:57 2002 UTC

# Line 1 | Line 1
1 + /*
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   //---PACKAGE DECLARATION---
21  
22   //---IMPORTS---
# Line 20 | Line 39 | class JavaHost {
39      
40      /**
41       * Constructor for the class. Takes in the hostname and port number
42 <     * of the Configuration Manager.
42 >     * of the Filter Manager.
43       *
44       */
45      public JavaHost( String serverName, int port ){
46 <        // create a connection to the configurator
46 >        // create a connection to the filter manager
47 >        System.out.println("Creating connection with Filter Manager");
48          Config config = new Config(serverName, port);
49          // the config class knows what values it wants to get from
50 <        // the configurator
50 >        // the configuration system
51          
52 <        // create a SystemMonitor object and pass the confifurator
52 >        // create a SystemMonitor object and pass the config
53          // as a param so it knows what to do!
54 +        System.out.println("Creating System Monitor");
55          SystemMonitor sysMon = new SystemMonitor(config);
56          
57 +        try {
58 +            udpcheckInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000;
59 +            System.out.println("Configured UDPUpdateTime");
60 +        }
61 +        catch ( NumberFormatException e ){
62 +            System.out.println("The value for UDPUpdateTime is invalid, using a default");
63 +            // 1 mins
64 +            udpcheckInterval = 1000 * 60;  // 1 minute
65 +        }
66 +        
67 +        try {
68 +            tcpcheckInterval = Long.parseLong(config.getProperty("TCPUpdateTime")) * 1000;
69 +            System.out.println("Configured TCPUpdateTime");
70 +        }
71 +        catch ( NumberFormatException e ){
72 +            System.out.println("The value for UDPUpdateTime is invalid, using a default");
73 +            // 10 mins
74 +            tcpcheckInterval = 10000 * 60;  // 5 minutes
75 +        }
76 +        
77 +        // the current time..
78 +        long currentTime = System.currentTimeMillis();
79 +        long nextUDP = currentTime + udpcheckInterval;
80 +        long nextTCP = currentTime + tcpcheckInterval;
81 +        
82          while ( true ){
83 +            currentTime = System.currentTimeMillis();
84              // keep going for ever and ever ;)
85 <            // send a udp packet to the filter declared in config
86 <            // send it the xml packet created by getInfo()
87 <            LowLevelNet.sendUDPPacket(config, sysMon.getInfo());    
88 <        }
85 >            
86 >            if ( nextTCP < nextUDP ){
87 >                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 >                        System.out.print("+");
96 >                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 >            }
106 >            else {
107 >                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 >            
118 >         }
119 >         catch ( InterruptedException e ){
120 >            // do nothing
121 >         }  
122 >            }
123 >            
124 >            
125 >            
126 >        } // while
127          
128 +          
129      } // public javahost
130  
131  
# Line 50 | Line 136 | class JavaHost {
136   //---ACCESSOR/MUTATOR METHODS---
137  
138   //---ATTRIBUTES---
139 +
140 +    private long udpcheckInterval;
141 +    private long tcpcheckInterval;
142 +    private final long defaultUpdateTime = 60000;
143 +
144  
145   //---STATIC ATTRIBUTES---
146  
147 < } // class
147 > } // class

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines