1 |
ajm |
1.5 |
//---PACKAGE DECLARATION--- |
2 |
tdb |
1.26 |
package uk.org.iscream.cms.conient; |
3 |
ajm |
1.5 |
|
4 |
|
|
//---IMPORTS--- |
5 |
tdb |
1.26 |
import uk.org.iscream.cms.server.util.*; |
6 |
ajm |
1.5 |
import java.util.HashMap; |
7 |
ajm |
1.22 |
import java.util.List; |
8 |
|
|
import java.util.Collections; |
9 |
ajm |
1.5 |
import javax.swing.ImageIcon; |
10 |
|
|
import javax.swing.JPanel; |
11 |
ajm |
1.22 |
import javax.swing.BorderFactory; |
12 |
|
|
import java.awt.CardLayout; |
13 |
|
|
import javax.swing.JSplitPane; |
14 |
ajm |
1.15 |
import java.util.StringTokenizer; |
15 |
|
|
import javax.swing.SwingUtilities; |
16 |
ajm |
1.22 |
import javax.swing.DefaultListModel; |
17 |
|
|
import javax.swing.JList; |
18 |
|
|
import javax.swing.JScrollPane; |
19 |
|
|
import java.awt.Dimension; |
20 |
|
|
import javax.swing.event.ListSelectionListener; |
21 |
|
|
import javax.swing.event.ListSelectionEvent; |
22 |
|
|
import javax.swing.ListSelectionModel; |
23 |
ajm |
1.5 |
|
24 |
|
|
/** |
25 |
|
|
* This thread reads data from the DataReader |
26 |
|
|
* it then asks the appropriate HostDisplayPanel |
27 |
|
|
* to update its data. |
28 |
|
|
* |
29 |
ajm |
1.6 |
* @author $Author: ajm4 $ |
30 |
tdb |
1.26 |
* @version $Id: DataPanel.java,v 1.25 2001/03/23 03:27:07 ajm4 Exp $ |
31 |
ajm |
1.5 |
*/ |
32 |
ajm |
1.22 |
public class DataPanel extends JSplitPane implements Runnable { |
33 |
ajm |
1.1 |
|
34 |
ajm |
1.5 |
//---FINAL ATTRIBUTES--- |
35 |
ajm |
1.2 |
|
36 |
ajm |
1.5 |
/** |
37 |
|
|
* The current CVS revision of this class |
38 |
|
|
*/ |
39 |
tdb |
1.26 |
public final String REVISION = "$Revision: 1.25 $"; |
40 |
ajm |
1.5 |
|
41 |
|
|
//---STATIC METHODS--- |
42 |
|
|
|
43 |
|
|
//---CONSTRUCTORS--- |
44 |
|
|
|
45 |
ajm |
1.15 |
/** |
46 |
|
|
* Constructs the data panel |
47 |
|
|
*/ |
48 |
|
|
public DataPanel() { |
49 |
ajm |
1.22 |
super(JSplitPane.HORIZONTAL_SPLIT); |
50 |
|
|
|
51 |
|
|
JScrollPane left = new JScrollPane(_hostChooserList); |
52 |
|
|
JScrollPane right = new JScrollPane(_displayPane); |
53 |
|
|
|
54 |
|
|
setOneTouchExpandable(true); |
55 |
|
|
setLeftComponent(left); |
56 |
|
|
setRightComponent(right); |
57 |
|
|
setDividerLocation(150); |
58 |
ajm |
1.19 |
_xmlPacketMaker = new XMLPacketMaker(); |
59 |
ajm |
1.15 |
} |
60 |
|
|
|
61 |
ajm |
1.5 |
//---PUBLIC METHODS--- |
62 |
|
|
|
63 |
|
|
/** |
64 |
|
|
* Starts the DataPanel running |
65 |
|
|
*/ |
66 |
ajm |
1.1 |
public void run() { |
67 |
ajm |
1.15 |
// setup the host list we will be using |
68 |
|
|
refreshHostList(); |
69 |
ajm |
1.16 |
if(Configuration.getInstance().getProperty("displayQueueInformation").equals("1")) { |
70 |
|
|
if (_qFrame == null) { |
71 |
|
|
_qFrame = new QueueFrame(); |
72 |
|
|
} |
73 |
|
|
if (!_qFrame.isVisible()) { |
74 |
|
|
_qFrame.setVisible(true); |
75 |
|
|
} |
76 |
|
|
} |
77 |
ajm |
1.5 |
|
78 |
ajm |
1.1 |
try { |
79 |
ajm |
1.5 |
while(_running) { |
80 |
ajm |
1.1 |
|
81 |
|
|
String xml = (String) _dataQueue.get(_myQueue); |
82 |
ajm |
1.18 |
// if we want to debug the packets |
83 |
|
|
if(Configuration.getInstance().getProperty("packetDump").equals("1")) { |
84 |
|
|
System.out.println("[PACKET DUMP]\n" + xml); |
85 |
|
|
} |
86 |
|
|
|
87 |
ajm |
1.6 |
Conient.setQueueStatus(_dataQueue.queueSize(_myQueue), _dataQueue.elementCount()); |
88 |
ajm |
1.1 |
if (xml == null) { |
89 |
|
|
// shouldn't really happen...but not sure |
90 |
|
|
//_status.insert("No XML to update...",0); |
91 |
|
|
} else { |
92 |
|
|
|
93 |
ajm |
1.19 |
// Use XMLPacketMaker to make an XMLPacket object. |
94 |
ajm |
1.1 |
|
95 |
ajm |
1.19 |
XMLPacket packet = _xmlPacketMaker.createXMLPacket(xml); |
96 |
ajm |
1.13 |
|
97 |
ajm |
1.11 |
String packetType = packet.getParam("packet.attributes.type"); |
98 |
|
|
if (packetType.equals("heartbeat") || packetType.equals("data")) { |
99 |
|
|
String hostName = packet.getParam("packet.attributes.machine_name"); |
100 |
ajm |
1.15 |
// if we're not using a fixed list |
101 |
|
|
if(!_usingConfiguredList) { |
102 |
|
|
// if we don't know about this host |
103 |
|
|
// add it. |
104 |
|
|
if(!_hostList.containsKey(hostName)) { |
105 |
|
|
addHostPanel(hostName); |
106 |
|
|
// if we want to remember new hosts (ie, in "discovery" mode) |
107 |
|
|
if(_config.getProperty("hostDiscoveryMode").equals("1")) { |
108 |
|
|
addToKnownHosts(hostName); |
109 |
|
|
} |
110 |
|
|
} |
111 |
ajm |
1.11 |
} |
112 |
ajm |
1.15 |
// one final check that we know about the host |
113 |
|
|
// if we don't by now, then the server must have sent something odd |
114 |
|
|
if(_hostList.containsKey(hostName)) { |
115 |
|
|
if (!((HostDisplayPanel) _hostList.get(hostName)).updateHost(packet)) { |
116 |
|
|
//throw new Exception(hostName + " sent an invalid data packet stopping data update!"); |
117 |
|
|
Conient.addMessage("WARNING{data panel}: " + hostName + " sent an invalid data or heartbeat packet"); |
118 |
|
|
} |
119 |
|
|
} else { |
120 |
|
|
Conient.addMessage("WARNING{data panel}: server sent data for an unexpected host - " + hostName); |
121 |
ajm |
1.11 |
} |
122 |
ajm |
1.12 |
} else if (packetType.equals("queueStat")) { |
123 |
|
|
// check to config to see if we want queueStat packets to be processed or not |
124 |
ajm |
1.17 |
if(Configuration.getInstance().getProperty("displayQueueInformation").equals("1") && _qFrame != null) { |
125 |
|
|
if (_qFrame.isVisible()) _qFrame.update(packet); |
126 |
ajm |
1.12 |
} |
127 |
ajm |
1.11 |
} else { |
128 |
|
|
Conient.addMessage("WARNING{data panel}: and unknown packet type was received - " + packetType); |
129 |
ajm |
1.5 |
} |
130 |
ajm |
1.1 |
} |
131 |
|
|
} |
132 |
|
|
} catch (Exception e) { |
133 |
ajm |
1.8 |
Conient.addMessage("ERROR{data panel}: +" + e); |
134 |
ajm |
1.10 |
e.printStackTrace(); |
135 |
ajm |
1.1 |
} |
136 |
|
|
} |
137 |
|
|
|
138 |
ajm |
1.5 |
/** |
139 |
|
|
* This method allows other classes |
140 |
|
|
* to shutdown this data panel. |
141 |
|
|
*/ |
142 |
|
|
public void shutdown() { |
143 |
|
|
_running = false; |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
//---PRIVATE METHODS--- |
147 |
|
|
|
148 |
ajm |
1.15 |
/** |
149 |
|
|
* Build the host list according to the configuration. |
150 |
|
|
* If we're set to use one, it populates the display. |
151 |
|
|
* If we're using one and its empty, or if we're not using |
152 |
|
|
* one, we set that we're not so that we use all host we detect. |
153 |
|
|
* |
154 |
|
|
* See the run method for information on host discovery if we're |
155 |
|
|
* getting all the hosts. |
156 |
|
|
*/ |
157 |
|
|
private void refreshHostList() { |
158 |
|
|
// reset the list |
159 |
|
|
_hostList = new HashMap(); |
160 |
|
|
// check we're using a set list |
161 |
|
|
if (_config.getProperty("useHostList").equals("1")) { |
162 |
|
|
// if we are get it and set up the display |
163 |
|
|
String hostList = _config.getProperty("hostList"); |
164 |
|
|
if (!hostList.equals("")) { |
165 |
|
|
StringTokenizer st = new StringTokenizer(hostList, ";"); |
166 |
|
|
while(st.hasMoreTokens()) { |
167 |
|
|
String host = st.nextToken(); |
168 |
|
|
addHostPanel(host); |
169 |
|
|
} |
170 |
|
|
_usingConfiguredList = true; |
171 |
|
|
// if we've got no list setup, we set that we're taking all |
172 |
|
|
// hosts that might come in. |
173 |
|
|
} else { |
174 |
|
|
_usingConfiguredList = false; |
175 |
|
|
} |
176 |
|
|
// we're not using a list |
177 |
|
|
} else { |
178 |
|
|
_usingConfiguredList = false; |
179 |
|
|
} |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
/** |
183 |
|
|
* Adds a new Host to the hostList and adds its |
184 |
|
|
* display to the tabbed pane. |
185 |
ajm |
1.25 |
* Ensures the host list is in alphabetical order. |
186 |
ajm |
1.15 |
* |
187 |
|
|
* @param host the host to add |
188 |
|
|
*/ |
189 |
|
|
private void addHostPanel(String host) { |
190 |
ajm |
1.22 |
HostDisplayPanel hostPanel = new HostDisplayPanel(host); |
191 |
ajm |
1.24 |
SwingSafeAddCard task = new SwingSafeAddCard(_displayPane, hostPanel, host); |
192 |
|
|
SwingUtilities.invokeLater(task); |
193 |
ajm |
1.22 |
_displayPane.add(hostPanel, host); |
194 |
ajm |
1.15 |
_hostList.put(host, hostPanel); |
195 |
ajm |
1.22 |
|
196 |
|
|
// we need to reconstruct the displayed host list, so its |
197 |
|
|
// sorted. |
198 |
|
|
|
199 |
|
|
_hostChooserList.setListData((new java.util.TreeSet(_hostList.keySet())).toArray()); |
200 |
|
|
|
201 |
ajm |
1.15 |
Conient.addMessage("New Host added: " + host); |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
/** |
205 |
|
|
* If we are in "discovery" mode, we want to keep a list |
206 |
|
|
* of all new hosts we find, so we can add it to our list. |
207 |
|
|
* This method simply adds the host to the end of the |
208 |
|
|
* "knownHostList" property. |
209 |
|
|
* |
210 |
|
|
* @param host the host to add |
211 |
|
|
*/ |
212 |
|
|
private void addToKnownHosts(String host) { |
213 |
ajm |
1.17 |
String knownHosts = _config.getProperty("knownHostsList"); |
214 |
|
|
if (knownHosts.indexOf(host) == -1) { |
215 |
|
|
_config.setProperty("knownHostsList", knownHosts + host + ";"); |
216 |
|
|
} |
217 |
ajm |
1.15 |
} |
218 |
ajm |
1.23 |
|
219 |
|
|
/** |
220 |
|
|
* Removes all the tabs on display |
221 |
|
|
* Used to tidy up when a new data |
222 |
|
|
* channel is opened. |
223 |
|
|
*/ |
224 |
|
|
public void cleanUpTabs() { |
225 |
ajm |
1.24 |
int currloc = getDividerLocation(); |
226 |
ajm |
1.23 |
_displayPaneLayout = new CardLayout(); |
227 |
|
|
_displayPane = new JPanel(_displayPaneLayout); |
228 |
|
|
JScrollPane right = new JScrollPane(_displayPane); |
229 |
|
|
setRightComponent(right); |
230 |
ajm |
1.24 |
setDividerLocation(currloc); |
231 |
ajm |
1.23 |
} |
232 |
ajm |
1.15 |
|
233 |
ajm |
1.5 |
//---ACCESSOR/MUTATOR METHODS--- |
234 |
ajm |
1.23 |
|
235 |
ajm |
1.5 |
/** |
236 |
|
|
* Assigns the queue that this panel |
237 |
|
|
* will use to obtain data |
238 |
|
|
* |
239 |
|
|
* @param queue the queue |
240 |
|
|
*/ |
241 |
ajm |
1.1 |
public void setQueue(Queue queue) { |
242 |
|
|
_dataQueue = queue; |
243 |
|
|
_myQueue = _dataQueue.getQueue(); |
244 |
tdb |
1.4 |
} |
245 |
|
|
|
246 |
ajm |
1.23 |
//---ATTRIBUTES--- |
247 |
|
|
|
248 |
ajm |
1.5 |
/** |
249 |
ajm |
1.23 |
* The state of this thread. |
250 |
ajm |
1.5 |
*/ |
251 |
ajm |
1.23 |
boolean _running = true; |
252 |
ajm |
1.1 |
|
253 |
ajm |
1.22 |
/** |
254 |
|
|
* This card layout is used for the _displayPane |
255 |
|
|
* it allows the chooser list to select which |
256 |
|
|
* host to display |
257 |
|
|
*/ |
258 |
|
|
private CardLayout _displayPaneLayout = new CardLayout(); |
259 |
|
|
|
260 |
ajm |
1.5 |
/** |
261 |
ajm |
1.22 |
* The panel where HostDisplayPanel's |
262 |
|
|
* are placed, it uses a CardLayout |
263 |
ajm |
1.5 |
*/ |
264 |
ajm |
1.22 |
private JPanel _displayPane = new JPanel(_displayPaneLayout); |
265 |
ajm |
1.5 |
|
266 |
ajm |
1.22 |
/** |
267 |
|
|
* The host list allows the user to select which |
268 |
|
|
* host pane is topmost |
269 |
|
|
*/ |
270 |
|
|
private JList _hostChooserList = new JList(); |
271 |
|
|
{ |
272 |
|
|
_hostChooserList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
273 |
|
|
_hostChooserList.addListSelectionListener(new ListSelectionListener() { |
274 |
|
|
public void valueChanged(ListSelectionEvent e) { |
275 |
|
|
int selection = _hostChooserList.getSelectedIndex(); |
276 |
|
|
if (selection > -1) { |
277 |
|
|
_displayPaneLayout.show(_displayPane, (String) _hostChooserList.getSelectedValue()); |
278 |
|
|
} |
279 |
|
|
} |
280 |
|
|
}); |
281 |
|
|
} |
282 |
ajm |
1.5 |
/** |
283 |
|
|
* The queue new data will be read from |
284 |
|
|
*/ |
285 |
ajm |
1.19 |
private Queue _dataQueue; |
286 |
ajm |
1.5 |
|
287 |
|
|
/** |
288 |
|
|
* Our queue number |
289 |
|
|
*/ |
290 |
ajm |
1.1 |
int _myQueue; |
291 |
ajm |
1.5 |
|
292 |
|
|
/** |
293 |
|
|
* An icon to represent a host |
294 |
|
|
*/ |
295 |
ajm |
1.19 |
private ImageIcon _serverIcon = new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif"); |
296 |
ajm |
1.12 |
|
297 |
|
|
/** |
298 |
|
|
* A frame to display Queue information |
299 |
|
|
* may not always be used - loaded according to config |
300 |
|
|
*/ |
301 |
ajm |
1.19 |
private QueueFrame _qFrame = null; |
302 |
ajm |
1.12 |
|
303 |
ajm |
1.15 |
/** |
304 |
|
|
* A reference to the configuraton object |
305 |
|
|
*/ |
306 |
ajm |
1.19 |
private Configuration _config = Configuration.getInstance(); |
307 |
ajm |
1.15 |
|
308 |
|
|
/** |
309 |
|
|
* Contains a list of hosts that the data panel will use |
310 |
|
|
* or build during its operation. |
311 |
|
|
*/ |
312 |
ajm |
1.19 |
private HashMap _hostList = null; |
313 |
ajm |
1.15 |
|
314 |
|
|
/** |
315 |
|
|
* If we should be using a configured list or just accepting |
316 |
|
|
* all the hosts we get |
317 |
|
|
*/ |
318 |
ajm |
1.19 |
boolean _usingConfiguredList = false; |
319 |
|
|
|
320 |
|
|
private XMLPacketMaker _xmlPacketMaker; |
321 |
ajm |
1.7 |
} |