1 |
< |
package uk.ac.ukc.iscream.client; |
1 |
> |
//---PACKAGE DECLARATION--- |
2 |
> |
package uk.org.iscream.client; |
3 |
|
|
4 |
< |
import uk.ac.ukc.iscream.client.*; |
5 |
< |
import uk.ac.ukc.iscream.clientinterface.*; |
6 |
< |
import uk.ac.ukc.iscream.util.*; |
7 |
< |
import org.omg.CosNaming.*; |
7 |
< |
import org.omg.CORBA.*; |
8 |
< |
import org.omg.PortableServer.*; |
9 |
< |
import java.io.*; |
4 |
> |
//---IMPORTS--- |
5 |
> |
import uk.org.iscream.componentmanager.*; |
6 |
> |
import uk.org.iscream.core.*; |
7 |
> |
import uk.org.iscream.util.*; |
8 |
|
|
9 |
+ |
/** |
10 |
+ |
* A servant for the LocalClient. |
11 |
+ |
* This represents the Client interface for CORBA |
12 |
+ |
* clients connecting to the i-scream system on the ClientInterface. |
13 |
+ |
* |
14 |
+ |
* The i-scream ClientInterface pumps data over CORBA into the |
15 |
+ |
* queue, using the recieveXML method. The MonitorManager |
16 |
+ |
* then handles pulling the data out of this queue. |
17 |
+ |
* |
18 |
+ |
* @author $Author$ |
19 |
+ |
* @version $Id$ |
20 |
+ |
*/ |
21 |
|
class ClientServant extends ClientPOA { |
22 |
+ |
|
23 |
+ |
//---FINAL ATTRIBUTES--- |
24 |
+ |
|
25 |
+ |
/** |
26 |
+ |
* The current CVS revision of this class |
27 |
+ |
*/ |
28 |
+ |
public static final String REVISION = "$Revision$"; |
29 |
+ |
|
30 |
+ |
//---STATIC METHODS--- |
31 |
+ |
|
32 |
+ |
//---CONSTRUCTORS--- |
33 |
+ |
|
34 |
+ |
/** |
35 |
+ |
* Construct a new ClientServant, with a given Queue. |
36 |
+ |
* |
37 |
+ |
* @param queue The Queue that will link this class to the MonitorManager |
38 |
+ |
*/ |
39 |
+ |
public ClientServant(Queue queue) { |
40 |
+ |
_queue = queue; |
41 |
+ |
} |
42 |
+ |
|
43 |
+ |
//---PUBLIC METHODS--- |
44 |
+ |
|
45 |
+ |
/** |
46 |
+ |
* Adds the inbound data to our queue when the CORBA method is called. |
47 |
+ |
* |
48 |
+ |
* @param xml The String of XML data |
49 |
+ |
*/ |
50 |
|
public void receiveXML(String xml) { |
51 |
< |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
14 |
< |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
15 |
< |
String machine_name = packet.getParam("packet.attributes.machine_name"); |
16 |
< |
String cpuuser = packet.getParam("packet.cpu.user"); |
17 |
< |
System.out.println("Hostname: " + machine_name + "\t\tUser CPU: " + cpuuser); |
18 |
< |
System.out.println("Uptime: "+DateUtils.formatTime(new Long(packet.getParam("packet.os.uptime")).longValue())); |
19 |
< |
if(cpuuser != null) { |
20 |
< |
double c = new Double(cpuuser).doubleValue(); |
21 |
< |
if (c > 80.0) { |
22 |
< |
String alert = "WARNING: Host "+machine_name+" has reached "+cpuuser+"% user CPU, which exceeds the threshold of 80%"; |
23 |
< |
try { |
24 |
< |
Smtp smtp = new Smtp("mercury.ukc.ac.uk"); |
25 |
< |
smtp.setSender("tdb1@ukc.ac.uk"); |
26 |
< |
smtp.setTo("dev@i-scream.org.uk"); |
27 |
< |
PrintWriter out = smtp.getOutputStream(); |
28 |
< |
out.println("Subject: i-scream Local Client proof-of-concept Test"); |
29 |
< |
out.println(); |
30 |
< |
out.println(alert); |
31 |
< |
smtp.sendMessage(); |
32 |
< |
smtp.close(); |
33 |
< |
} catch(IOException e) {System.out.println(e);} |
34 |
< |
} |
35 |
< |
} |
51 |
> |
_queue.add(xml); |
52 |
|
} |
37 |
– |
} |
53 |
|
|
54 |
+ |
/** |
55 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
56 |
+ |
* method to provide clean logging (every class should have this). |
57 |
+ |
* |
58 |
+ |
* This uses the uk.org.iscream.util.FormatName class |
59 |
+ |
* to format the toString() |
60 |
+ |
* |
61 |
+ |
* @return the name of this class and its CVS revision |
62 |
+ |
*/ |
63 |
+ |
public String toString() { |
64 |
+ |
return FormatName.getName( |
65 |
+ |
_name, |
66 |
+ |
getClass().getName(), |
67 |
+ |
REVISION); |
68 |
+ |
} |
69 |
+ |
|
70 |
+ |
//---PRIVATE METHODS--- |
71 |
+ |
|
72 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
73 |
+ |
|
74 |
+ |
//---ATTRIBUTES--- |
75 |
+ |
|
76 |
+ |
/** |
77 |
+ |
* This is the friendly identifier of the |
78 |
+ |
* component this class is running in. |
79 |
+ |
* eg, a Filter may be called "filter1", |
80 |
+ |
* If this class does not have an owning |
81 |
+ |
* component, a name from the configuration |
82 |
+ |
* can be placed here. This name could also |
83 |
+ |
* be changed to null for utility classes. |
84 |
+ |
*/ |
85 |
+ |
private String _name = ClientMain.NAME; |
86 |
+ |
|
87 |
+ |
/** |
88 |
+ |
* This holds a reference to the |
89 |
+ |
* system logger that is being used. |
90 |
+ |
*/ |
91 |
+ |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
92 |
+ |
|
93 |
+ |
/** |
94 |
+ |
* A reference to our Queue to place the inbond data into. |
95 |
+ |
*/ |
96 |
+ |
private Queue _queue; |
97 |
+ |
|
98 |
+ |
//---STATIC ATTRIBUTES--- |
99 |
+ |
|
100 |
+ |
} |