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.16
Committed: Wed Feb 28 23:57:17 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.15: +10 -9 lines
Log Message:
Fixed QFrame window not going away when told to

File Contents

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