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.9 by tdb, Tue May 21 16:47:12 2002 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines