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