ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/java/JavaHost.java
Revision: 1.8
Committed: Sat May 18 18:15:57 2002 UTC (22 years, 6 months ago) by tdb
Branch: MAIN
Changes since 1.7: +21 -2 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# Content
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---
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 * @author $Author: ab11 $
30 * @version $Id: JavaHost.java,v 1.7 2001/03/19 17:30:17 ab11 Exp $
31 */
32 class JavaHost {
33
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 * of the Filter Manager.
43 *
44 */
45 public JavaHost( String serverName, int port ){
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 configuration system
51
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
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
132 //---PUBLIC METHODS---
133
134 //---PRIVATE METHODS---
135
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