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.19
Committed: Wed Mar 14 16:32:27 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.18: +14 -20 lines
Log Message:
Now uses the new style XML Packet creation mechanism.

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