ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/java/SystemMonitor.java
Revision: 1.3
Committed: Thu Nov 30 04:11:00 2000 UTC (23 years, 11 months ago) by ab11
Branch: MAIN
Changes since 1.2: +20 -10 lines
Log Message:
Fixed waiting with Thread.sleep() added some randomiminty to the XML packets

File Contents

# Content
1 //---PACKAGE DECLARATION---
2
3 //---IMPORTS---
4
5 import java.util.Random;
6
7 /**
8 * Gathers system information then outputs it as XML
9 * Collects data based on properties gained from the configurator
10 * then packages these up using XMLFormatter and outputs them if
11 * the timeout has passed.
12 *
13 * @author $Author: ab11 $
14 * @version $Id: SystemMonitor.java,v 1.2 2000/11/27 20:36:30 ab11 Exp $
15 */
16 class SystemMonitor {
17
18 //---FINAL ATTRIBUTES---
19
20 //---STATIC METHODS---
21
22 //---CONSTRUCTORS---
23
24 /**
25 * Public constructor for the class. Takes in a Config object to gain its
26 * properties from.
27 *
28 */
29 public SystemMonitor( Config config ){
30 // create a new instace, get the info we need out of config
31 // like things to monitor
32
33 lastCheck = System.currentTimeMillis();
34 sequence = 0;
35
36
37 // why oh why wont ultra edit let me put Long in the next line? oh its trying to
38 // correct keywords =|
39 checkInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000;
40 // make the check interval into seconds
41
42 }
43
44 //---PUBLIC METHODS---
45
46 /**
47 * Gathers system information and will black until the timeout has passed.
48 *
49 * @return the system information in an XML packet
50 */
51 public String getInfo(){
52 // called to retrieve the stored averages and output them as a XML string
53 XMLFormatter xml = new XMLFormatter("packet");
54
55 Random rand = new Random();
56
57 // just send some dummy info for now.
58 xml.addNest("packet_info");
59 String currentTime = Long.toString(System.currentTimeMillis());
60 xml.addElement("date_time", currentTime );
61 xml.addElement("sequence", Integer.toString(sequence));
62 xml.closeNest();
63 xml.addNest("core");
64 xml.addElement("cpu",""+rand.nextInt(100));
65 xml.addElement("memory",""+rand.nextInt(100));
66 xml.closeNest();
67 if ( rand.nextBoolean() ){
68 xml.addNest("additional");
69 xml.addElement("users",""+rand.nextInt(30));
70 xml.closeNest();
71 }
72 // MUST FIX THIS..!!!!
73 try {
74 Thread.sleep(( lastCheck + checkInterval )-System.currentTimeMillis());
75 }
76 catch( InterruptedException e ){
77 System.out.println("Sleep interrupted");
78 }
79
80 // increment sequence.
81 sequence++;
82 lastCheck = System.currentTimeMillis();
83
84 // finally return a string
85 return xml.returnXML();
86 } // getinfo()
87
88 //---PRIVATE METHODS---
89
90 //---ACCESSOR/MUTATOR METHODS---
91
92 //---ATTRIBUTES---
93
94 private long lastCheck;
95 private int sequence;
96 private long checkInterval;
97
98 //---STATIC ATTRIBUTES---
99
100 } // class