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 |
+ |
* |
12 |
+ |
* @author $Author$ |
13 |
+ |
* @version $Id$ |
14 |
+ |
*/ |
15 |
|
class ClientServant extends ClientPOA { |
16 |
+ |
|
17 |
+ |
//---FINAL ATTRIBUTES--- |
18 |
+ |
|
19 |
+ |
/** |
20 |
+ |
* The current CVS revision of this class |
21 |
+ |
*/ |
22 |
+ |
public static final String REVISION = "$Revision$"; |
23 |
+ |
|
24 |
+ |
//---STATIC METHODS--- |
25 |
+ |
|
26 |
+ |
//---CONSTRUCTORS--- |
27 |
+ |
|
28 |
+ |
/** |
29 |
+ |
* Construct a new ClientServant, with a given Queue. |
30 |
+ |
* |
31 |
+ |
* @param queue The Queue that will link this class to the MonitorManager |
32 |
+ |
*/ |
33 |
+ |
public ClientServant(Queue queue) { |
34 |
+ |
_queue = queue; |
35 |
+ |
} |
36 |
+ |
|
37 |
+ |
//---PUBLIC METHODS--- |
38 |
+ |
|
39 |
+ |
/** |
40 |
+ |
* This should deal with the data... :) |
41 |
+ |
* |
42 |
+ |
* @param xml The String of XML data |
43 |
+ |
*/ |
44 |
|
public void receiveXML(String xml) { |
45 |
< |
System.out.println(" --- received XML --- "); |
14 |
< |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
15 |
< |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
16 |
< |
String machine_name = packet.getParam("packet.attributes.machine_name"); |
17 |
< |
String cpuuser = packet.getParam("packet.cpu.user"); |
18 |
< |
System.out.println("Hostname: " + machine_name + " User CPU: " + cpuuser); |
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.from("tdb1@ukc.ac.uk"); |
26 |
< |
smtp.to("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) {} |
34 |
< |
} |
35 |
< |
} |
45 |
> |
_queue.add(xml); |
46 |
|
} |
37 |
– |
} |
47 |
|
|
48 |
+ |
/** |
49 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
50 |
+ |
* method to provide clean logging (every class should have this). |
51 |
+ |
* |
52 |
+ |
* This uses the uk.org.iscream.util.FormatName class |
53 |
+ |
* to format the toString() |
54 |
+ |
* |
55 |
+ |
* @return the name of this class and its CVS revision |
56 |
+ |
*/ |
57 |
+ |
public String toString() { |
58 |
+ |
return FormatName.getName( |
59 |
+ |
_name, |
60 |
+ |
getClass().getName(), |
61 |
+ |
REVISION); |
62 |
+ |
} |
63 |
+ |
|
64 |
+ |
//---PRIVATE METHODS--- |
65 |
+ |
|
66 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
67 |
+ |
|
68 |
+ |
//---ATTRIBUTES--- |
69 |
+ |
|
70 |
+ |
/** |
71 |
+ |
* This is the friendly identifier of the |
72 |
+ |
* component this class is running in. |
73 |
+ |
* eg, a Filter may be called "filter1", |
74 |
+ |
* If this class does not have an owning |
75 |
+ |
* component, a name from the configuration |
76 |
+ |
* can be placed here. This name could also |
77 |
+ |
* be changed to null for utility classes. |
78 |
+ |
*/ |
79 |
+ |
private String _name = ClientMain.NAME; |
80 |
+ |
|
81 |
+ |
/** |
82 |
+ |
* This holds a reference to the |
83 |
+ |
* system logger that is being used. |
84 |
+ |
*/ |
85 |
+ |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
86 |
+ |
|
87 |
+ |
/** |
88 |
+ |
* A reference to our QUeue |
89 |
+ |
*/ |
90 |
+ |
private Queue _queue; |
91 |
+ |
|
92 |
+ |
//---STATIC ATTRIBUTES--- |
93 |
+ |
|
94 |
+ |
} |