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 |
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("UDPINTEVAL")); |
39 |
> |
checkInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000; |
40 |
> |
// make the check interval into seconds |
41 |
|
|
42 |
|
} |
43 |
|
|
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()); |
61 |
|
xml.addElement("sequence", Integer.toString(sequence)); |
62 |
|
xml.closeNest(); |
63 |
|
xml.addNest("core"); |
64 |
< |
xml.addElement("cpu","100"); |
65 |
< |
xml.addElement("memory","200"); |
64 |
> |
xml.addElement("cpu",""+rand.nextInt(100)); |
65 |
> |
xml.addElement("memory",""+rand.nextInt(100)); |
66 |
|
xml.closeNest(); |
67 |
< |
xml.addNest("additional"); |
68 |
< |
xml.addElement("users","20"); |
69 |
< |
xml.closeNest(); |
70 |
< |
|
67 |
> |
if ( rand.nextBoolean() ){ |
68 |
> |
xml.addNest("additional"); |
69 |
> |
xml.addElement("users",""+rand.nextInt(30)); |
70 |
> |
xml.closeNest(); |
71 |
> |
} |
72 |
|
// MUST FIX THIS..!!!! |
73 |
< |
while ( System.currentTimeMillis() < ( lastCheck + checkInterval ) ){ |
74 |
< |
// errm do nothing.. block or something. |
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(); |