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

Comparing projects/cms/source/host/java/SystemMonitor.java (file contents):
Revision 1.1 by ab11, Mon Nov 27 19:44:32 2000 UTC vs.
Revision 1.3 by ab11, Thu Nov 30 04:11:00 2000 UTC

# Line 1 | Line 1
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$
14 + * @version $Id$
15 + */
16   class SystemMonitor {
17  
18 <        public SystemMonitor( Config config ){
4 <                // create a new instace, get the info we need out of config
5 <                // like things to monitor
6 <                
7 <                lastCheck = System.currentTimeMillis();
8 <                sequence = 0;
18 > //---FINAL ATTRIBUTES---
19  
20 + //---STATIC METHODS---
21  
22 <                // why oh why wont ultra edit let me put Long in the next line? oh its trying to
12 <                // correct keywords =|
13 <                checkInterval = Long.parseLong(config.getProperty("UDPINTEVAL"));
14 <                
15 <        }
22 > //---CONSTRUCTORS---
23  
24 <        public String getInfo(){
25 <                // called to retrieve the stored averages and output them as a XML string
26 <                XMLFormatter xml = new XMLFormatter("packet");
27 <                
28 <                // just send some dummy info for now.
29 <                xml.addNest("packet_info");
30 <                    String currentTime = Long.toString(System.currentTimeMillis());
31 <                    xml.addElement("date_time", currentTime );
32 <                    xml.addElement("sequence", Integer.toString(sequence));
33 <                xml.closeNest();
34 <                xml.addNest("core");
28 <                    xml.addElement("cpu","100");
29 <                    xml.addElement("memory","200");
30 <                xml.closeNest();
31 <                xml.addNest("additional");
32 <                    xml.addElement("users","20");
33 <                xml.closeNest();
34 <                
35 <                // MUST FIX THIS..!!!!
36 <                while ( System.currentTimeMillis() < ( lastCheck + checkInterval ) ){
37 <                  // errm do nothing.. block or something.          
38 <                }
39 <                
40 <                // increment sequence.
41 <                sequence++;
42 <                                
43 <                // finally return a string
44 <                return xml.returnXML();
45 <        } // getinfo()
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 <    // last time the system data was returned.
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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines