1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.conient; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.ac.ukc.iscream.util.*; |
6 |
import java.util.HashMap; |
7 |
import javax.swing.ImageIcon; |
8 |
import javax.swing.JTabbedPane; |
9 |
import javax.swing.JPanel; |
10 |
|
11 |
/** |
12 |
* This thread reads data from the DataReader |
13 |
* it then asks the appropriate HostDisplayPanel |
14 |
* to update its data. |
15 |
* |
16 |
* @author $Author: ajm4 $ |
17 |
* @version $Id: DataPanel.java,v 1.11 2001/02/12 13:20:29 ajm4 Exp $ |
18 |
*/ |
19 |
public class DataPanel extends JPanel implements Runnable { |
20 |
|
21 |
//---FINAL ATTRIBUTES--- |
22 |
|
23 |
/** |
24 |
* The current CVS revision of this class |
25 |
*/ |
26 |
public final String REVISION = "$Revision: 1.11 $"; |
27 |
|
28 |
//---STATIC METHODS--- |
29 |
|
30 |
//---CONSTRUCTORS--- |
31 |
|
32 |
//---PUBLIC METHODS--- |
33 |
|
34 |
/** |
35 |
* Starts the DataPanel running |
36 |
*/ |
37 |
public void run() { |
38 |
// add the tabbed pane to ourselves |
39 |
add(_tabbedPane); |
40 |
|
41 |
// the hosts we are interested in go here |
42 |
HashMap hostList = new HashMap(); |
43 |
|
44 |
try { |
45 |
while(_running) { |
46 |
|
47 |
String xml = (String) _dataQueue.get(_myQueue); |
48 |
Conient.setQueueStatus(_dataQueue.queueSize(_myQueue), _dataQueue.elementCount()); |
49 |
if (xml == null) { |
50 |
// shouldn't really happen...but not sure |
51 |
//_status.insert("No XML to update...",0); |
52 |
} else { |
53 |
|
54 |
// Get a string without any null characters in it. |
55 |
// -- maybe String.trim() would be better ? |
56 |
if (xml.indexOf(0) != -1) { |
57 |
xml = xml.substring(0, xml.indexOf(0)); |
58 |
} |
59 |
else { |
60 |
xml = xml.substring(0, xml.length()); |
61 |
} |
62 |
|
63 |
// Use XMLPacketMaker to make an XMLPacket object. |
64 |
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
65 |
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
66 |
String packetType = packet.getParam("packet.attributes.type"); |
67 |
|
68 |
if (packetType.equals("heartbeat") || packetType.equals("data")) { |
69 |
String hostName = packet.getParam("packet.attributes.machine_name"); |
70 |
if(!hostList.containsKey(hostName)) { |
71 |
|
72 |
HostDisplayPanel host = new HostDisplayPanel(hostName); |
73 |
_tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName); |
74 |
hostList.put(hostName, host); |
75 |
Conient.addMessage("New Host added: " + hostName); |
76 |
} |
77 |
if (!((HostDisplayPanel) hostList.get(hostName)).updateHost(packet)) { |
78 |
//throw new Exception(hostName + " sent an invalid data packet stopping data update!"); |
79 |
Conient.addMessage("WARNING{data panel}: " + hostName + " sent an invalid data or heartbeat packet"); |
80 |
} |
81 |
} else if (packetType.equals("queueStat")) { |
82 |
// check to config to see if we want queueStat packets to be processed or not |
83 |
if(Configuration.getInstance().getProperty("displayQueueInformation") != null) { |
84 |
if (qFrame == null) { |
85 |
qFrame = new QueueFrame(); |
86 |
} |
87 |
qFrame.update(packet); |
88 |
} |
89 |
} else { |
90 |
Conient.addMessage("WARNING{data panel}: and unknown packet type was received - " + packetType); |
91 |
} |
92 |
} |
93 |
} |
94 |
} catch (Exception e) { |
95 |
Conient.addMessage("ERROR{data panel}: +" + e); |
96 |
e.printStackTrace(); |
97 |
} |
98 |
} |
99 |
|
100 |
/** |
101 |
* This method allows other classes |
102 |
* to shutdown this data panel. |
103 |
*/ |
104 |
public void shutdown() { |
105 |
_running = false; |
106 |
} |
107 |
|
108 |
//---PRIVATE METHODS--- |
109 |
|
110 |
//---ACCESSOR/MUTATOR METHODS--- |
111 |
|
112 |
//---ATTRIBUTES--- |
113 |
|
114 |
/** |
115 |
* The state of this thread. |
116 |
*/ |
117 |
boolean _running = true; |
118 |
|
119 |
/** |
120 |
* Assigns the queue that this panel |
121 |
* will use to obtain data |
122 |
* |
123 |
* @param queue the queue |
124 |
*/ |
125 |
public void setQueue(Queue queue) { |
126 |
_dataQueue = queue; |
127 |
_myQueue = _dataQueue.getQueue(); |
128 |
} |
129 |
|
130 |
/** |
131 |
* Removes all the tabs on display |
132 |
* Used to tidy up when a new data |
133 |
* channel is opened. |
134 |
*/ |
135 |
public void cleanUpTabs() { |
136 |
_tabbedPane.removeAll(); |
137 |
} |
138 |
|
139 |
/** |
140 |
* The tabbed pane is where HostDisplayPanel's |
141 |
* are placed |
142 |
*/ |
143 |
JTabbedPane _tabbedPane = new JTabbedPane(); |
144 |
|
145 |
/** |
146 |
* The queue new data will be read from |
147 |
*/ |
148 |
Queue _dataQueue; |
149 |
|
150 |
/** |
151 |
* Our queue number |
152 |
*/ |
153 |
int _myQueue; |
154 |
|
155 |
/** |
156 |
* An icon to represent a host |
157 |
*/ |
158 |
ImageIcon _serverIcon = new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif"); |
159 |
|
160 |
/** |
161 |
* A frame to display Queue information |
162 |
* may not always be used - loaded according to config |
163 |
*/ |
164 |
QueueFrame qFrame = null; |
165 |
|
166 |
} |