ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/DataPanel.java
Revision: 1.23
Committed: Mon Mar 19 00:49:11 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.22: +19 -16 lines
Log Message:
fixed the bug where the gc code to remove all the old panels caused the panels to never actually get displayed doh!

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.conient;
3
4 //---IMPORTS---
5 import uk.org.iscream.util.*;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Collections;
9 import javax.swing.ImageIcon;
10 import javax.swing.JPanel;
11 import javax.swing.BorderFactory;
12 import java.awt.CardLayout;
13 import javax.swing.JSplitPane;
14 import java.util.StringTokenizer;
15 import javax.swing.SwingUtilities;
16 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
24 /**
25 * This thread reads data from the DataReader
26 * it then asks the appropriate HostDisplayPanel
27 * to update its data.
28 *
29 * @author $Author: ajm4 $
30 * @version $Id: DataPanel.java,v 1.22 2001/03/19 00:23:50 ajm4 Exp $
31 */
32 public class DataPanel extends JSplitPane implements Runnable {
33
34 //---FINAL ATTRIBUTES---
35
36 /**
37 * The current CVS revision of this class
38 */
39 public final String REVISION = "$Revision: 1.22 $";
40
41 //---STATIC METHODS---
42
43 //---CONSTRUCTORS---
44
45 /**
46 * Constructs the data panel
47 */
48 public DataPanel() {
49 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 _xmlPacketMaker = new XMLPacketMaker();
59 }
60
61 //---PUBLIC METHODS---
62
63 /**
64 * Starts the DataPanel running
65 */
66 public void run() {
67 // setup the host list we will be using
68 refreshHostList();
69 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
78 try {
79 while(_running) {
80
81 String xml = (String) _dataQueue.get(_myQueue);
82 // 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 Conient.setQueueStatus(_dataQueue.queueSize(_myQueue), _dataQueue.elementCount());
88 if (xml == null) {
89 // shouldn't really happen...but not sure
90 //_status.insert("No XML to update...",0);
91 } else {
92
93 // Use XMLPacketMaker to make an XMLPacket object.
94
95 XMLPacket packet = _xmlPacketMaker.createXMLPacket(xml);
96
97 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 // 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 }
112 // 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 }
122 } else if (packetType.equals("queueStat")) {
123 // check to config to see if we want queueStat packets to be processed or not
124 if(Configuration.getInstance().getProperty("displayQueueInformation").equals("1") && _qFrame != null) {
125 if (_qFrame.isVisible()) _qFrame.update(packet);
126 }
127 } else {
128 Conient.addMessage("WARNING{data panel}: and unknown packet type was received - " + packetType);
129 }
130 }
131 }
132 } catch (Exception e) {
133 Conient.addMessage("ERROR{data panel}: +" + e);
134 e.printStackTrace();
135 }
136 }
137
138 /**
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 /**
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 *
186 * @param host the host to add
187 */
188 private void addHostPanel(String host) {
189 HostDisplayPanel hostPanel = new HostDisplayPanel(host);
190 //SwingSafeAdd task = new SwingSafeAdd(_displayPane, hostPanel);
191 //SwingUtilities.invokeLater(task);
192 _displayPane.add(hostPanel, host);
193 _hostList.put(host, hostPanel);
194
195 // we need to reconstruct the displayed host list, so its
196 // sorted.
197
198 _hostChooserList.setListData((new java.util.TreeSet(_hostList.keySet())).toArray());
199
200 Conient.addMessage("New Host added: " + host);
201 }
202
203 /**
204 * If we are in "discovery" mode, we want to keep a list
205 * of all new hosts we find, so we can add it to our list.
206 * This method simply adds the host to the end of the
207 * "knownHostList" property.
208 *
209 * @param host the host to add
210 */
211 private void addToKnownHosts(String host) {
212 String knownHosts = _config.getProperty("knownHostsList");
213 if (knownHosts.indexOf(host) == -1) {
214 _config.setProperty("knownHostsList", knownHosts + host + ";");
215 }
216 }
217
218 /**
219 * Removes all the tabs on display
220 * Used to tidy up when a new data
221 * channel is opened.
222 */
223 public void cleanUpTabs() {
224 _displayPaneLayout = new CardLayout();
225 _displayPane = new JPanel(_displayPaneLayout);
226 JScrollPane right = new JScrollPane(_displayPane);
227 setRightComponent(right);
228 }
229
230 //---ACCESSOR/MUTATOR METHODS---
231
232 /**
233 * Assigns the queue that this panel
234 * will use to obtain data
235 *
236 * @param queue the queue
237 */
238 public void setQueue(Queue queue) {
239 _dataQueue = queue;
240 _myQueue = _dataQueue.getQueue();
241 }
242
243 //---ATTRIBUTES---
244
245 /**
246 * The state of this thread.
247 */
248 boolean _running = true;
249
250 /**
251 * This card layout is used for the _displayPane
252 * it allows the chooser list to select which
253 * host to display
254 */
255 private CardLayout _displayPaneLayout = new CardLayout();
256
257 /**
258 * The panel where HostDisplayPanel's
259 * are placed, it uses a CardLayout
260 */
261 private JPanel _displayPane = new JPanel(_displayPaneLayout);
262
263 /**
264 * The host list allows the user to select which
265 * host pane is topmost
266 */
267 private JList _hostChooserList = new JList();
268 {
269 _hostChooserList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
270 _hostChooserList.addListSelectionListener(new ListSelectionListener() {
271 public void valueChanged(ListSelectionEvent e) {
272 int selection = _hostChooserList.getSelectedIndex();
273 if (selection > -1) {
274 _displayPaneLayout.show(_displayPane, (String) _hostChooserList.getSelectedValue());
275 }
276 }
277 });
278 }
279 /**
280 * The queue new data will be read from
281 */
282 private Queue _dataQueue;
283
284 /**
285 * Our queue number
286 */
287 int _myQueue;
288
289 /**
290 * An icon to represent a host
291 */
292 private ImageIcon _serverIcon = new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif");
293
294 /**
295 * A frame to display Queue information
296 * may not always be used - loaded according to config
297 */
298 private QueueFrame _qFrame = null;
299
300 /**
301 * A reference to the configuraton object
302 */
303 private Configuration _config = Configuration.getInstance();
304
305 /**
306 * Contains a list of hosts that the data panel will use
307 * or build during its operation.
308 */
309 private HashMap _hostList = null;
310
311 /**
312 * If we should be using a configured list or just accepting
313 * all the hosts we get
314 */
315 boolean _usingConfiguredList = false;
316
317 private XMLPacketMaker _xmlPacketMaker;
318 }