1 |
< |
package uk.ac.ukc.iscream.client; |
1 |
> |
/* |
2 |
> |
* i-scream central monitoring system |
3 |
> |
* http://www.i-scream.org.uk |
4 |
> |
* Copyright (C) 2000-2002 i-scream |
5 |
> |
* |
6 |
> |
* This program is free software; you can redistribute it and/or |
7 |
> |
* modify it under the terms of the GNU General Public License |
8 |
> |
* as published by the Free Software Foundation; either version 2 |
9 |
> |
* of the License, or (at your option) any later version. |
10 |
> |
* |
11 |
> |
* This program is distributed in the hope that it will be useful, |
12 |
> |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
> |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
> |
* GNU General Public License for more details. |
15 |
> |
* |
16 |
> |
* You should have received a copy of the GNU General Public License |
17 |
> |
* along with this program; if not, write to the Free Software |
18 |
> |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
> |
*/ |
20 |
|
|
21 |
< |
import uk.ac.ukc.iscream.client.*; |
22 |
< |
import uk.ac.ukc.iscream.clientinterface.*; |
5 |
< |
import uk.ac.ukc.iscream.util.*; |
6 |
< |
import org.omg.CosNaming.*; |
7 |
< |
import org.omg.CORBA.*; |
8 |
< |
import org.omg.PortableServer.*; |
9 |
< |
import java.io.*; |
21 |
> |
//---PACKAGE DECLARATION--- |
22 |
> |
package uk.org.iscream.cms.server.client; |
23 |
|
|
24 |
+ |
//---IMPORTS--- |
25 |
+ |
import uk.org.iscream.cms.server.componentmanager.*; |
26 |
+ |
import uk.org.iscream.cms.server.core.*; |
27 |
+ |
import uk.org.iscream.cms.util.*; |
28 |
+ |
|
29 |
+ |
/** |
30 |
+ |
* A servant for the LocalClient. |
31 |
+ |
* This represents the Client interface for CORBA |
32 |
+ |
* clients connecting to the i-scream system on the ClientInterface. |
33 |
+ |
* |
34 |
+ |
* The i-scream ClientInterface pumps data over CORBA into the |
35 |
+ |
* queue, using the recieveXML method. The MonitorManager |
36 |
+ |
* then handles pulling the data out of this queue. |
37 |
+ |
* |
38 |
+ |
* @author $Author$ |
39 |
+ |
* @version $Id$ |
40 |
+ |
*/ |
41 |
|
class ClientServant extends ClientPOA { |
42 |
+ |
|
43 |
+ |
//---FINAL ATTRIBUTES--- |
44 |
+ |
|
45 |
+ |
/** |
46 |
+ |
* The current CVS revision of this class |
47 |
+ |
*/ |
48 |
+ |
public static final String REVISION = "$Revision$"; |
49 |
+ |
|
50 |
+ |
//---STATIC METHODS--- |
51 |
+ |
|
52 |
+ |
//---CONSTRUCTORS--- |
53 |
+ |
|
54 |
+ |
/** |
55 |
+ |
* Construct a new ClientServant, with a given Queue. |
56 |
+ |
* |
57 |
+ |
* @param queue The Queue that will link this class to the MonitorManager |
58 |
+ |
*/ |
59 |
+ |
public ClientServant(Queue queue) { |
60 |
+ |
_queue = queue; |
61 |
+ |
} |
62 |
+ |
|
63 |
+ |
//---PUBLIC METHODS--- |
64 |
+ |
|
65 |
+ |
/** |
66 |
+ |
* Adds the inbound data to our queue when the CORBA method is called. |
67 |
+ |
* |
68 |
+ |
* @param xml The String of XML data |
69 |
+ |
*/ |
70 |
|
public void receiveXML(String xml) { |
71 |
< |
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 |
< |
} |
71 |
> |
_queue.add(xml); |
72 |
|
} |
37 |
– |
} |
73 |
|
|
74 |
+ |
/** |
75 |
+ |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
76 |
+ |
* method to provide clean logging (every class should have this). |
77 |
+ |
* |
78 |
+ |
* This uses the uk.org.iscream.cms.util.FormatName class |
79 |
+ |
* to format the toString() |
80 |
+ |
* |
81 |
+ |
* @return the name of this class and its CVS revision |
82 |
+ |
*/ |
83 |
+ |
public String toString() { |
84 |
+ |
return FormatName.getName( |
85 |
+ |
_name, |
86 |
+ |
getClass().getName(), |
87 |
+ |
REVISION); |
88 |
+ |
} |
89 |
+ |
|
90 |
+ |
//---PRIVATE METHODS--- |
91 |
+ |
|
92 |
+ |
//---ACCESSOR/MUTATOR METHODS--- |
93 |
+ |
|
94 |
+ |
//---ATTRIBUTES--- |
95 |
+ |
|
96 |
+ |
/** |
97 |
+ |
* This is the friendly identifier of the |
98 |
+ |
* component this class is running in. |
99 |
+ |
* eg, a Filter may be called "filter1", |
100 |
+ |
* If this class does not have an owning |
101 |
+ |
* component, a name from the configuration |
102 |
+ |
* can be placed here. This name could also |
103 |
+ |
* be changed to null for utility classes. |
104 |
+ |
*/ |
105 |
+ |
private String _name = ClientMain.NAME; |
106 |
+ |
|
107 |
+ |
/** |
108 |
+ |
* This holds a reference to the |
109 |
+ |
* system logger that is being used. |
110 |
+ |
*/ |
111 |
+ |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
112 |
+ |
|
113 |
+ |
/** |
114 |
+ |
* A reference to our Queue to place the inbond data into. |
115 |
+ |
*/ |
116 |
+ |
private Queue _queue; |
117 |
+ |
|
118 |
+ |
//---STATIC ATTRIBUTES--- |
119 |
+ |
|
120 |
+ |
} |