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.15
Committed: Tue Feb 27 23:31:32 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.14: +120 -23 lines
Log Message:
added support for 1.1 PROTOCOL
initial support for using it, though the configuration
of the actually host list is in GUI form, it currently doesn't work.
The option boxes of "discover" and "use host list" do though.
The configuration options for the list (if you want to hand edit) are:
hostList and knownHostList

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