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.13
Committed: Mon Feb 26 00:25:00 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.12: +8 -3 lines
Log Message:
added support for debugging packets
fixed problem when connecting and starting data but not getting config ;)

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    
11     /**
12     * This thread reads data from the DataReader
13     * it then asks the appropriate HostDisplayPanel
14     * to update its data.
15     *
16 ajm 1.6 * @author $Author: ajm4 $
17 ajm 1.13 * @version $Id: DataPanel.java,v 1.12 2001/02/25 21:23:38 ajm4 Exp $
18 ajm 1.5 */
19     public class DataPanel extends JPanel implements Runnable {
20 ajm 1.1
21 ajm 1.5 //---FINAL ATTRIBUTES---
22 ajm 1.2
23 ajm 1.5 /**
24     * The current CVS revision of this class
25     */
26 ajm 1.13 public final String REVISION = "$Revision: 1.12 $";
27 ajm 1.5
28     //---STATIC METHODS---
29    
30     //---CONSTRUCTORS---
31    
32     //---PUBLIC METHODS---
33    
34     /**
35     * Starts the DataPanel running
36     */
37 ajm 1.1 public void run() {
38 ajm 1.5 // add the tabbed pane to ourselves
39 ajm 1.2 add(_tabbedPane);
40 ajm 1.5
41     // the hosts we are interested in go here
42 ajm 1.1 HashMap hostList = new HashMap();
43 ajm 1.5
44 ajm 1.1 try {
45 ajm 1.5 while(_running) {
46 ajm 1.1
47     String xml = (String) _dataQueue.get(_myQueue);
48 ajm 1.6 Conient.setQueueStatus(_dataQueue.queueSize(_myQueue), _dataQueue.elementCount());
49 ajm 1.1 if (xml == null) {
50     // shouldn't really happen...but not sure
51     //_status.insert("No XML to update...",0);
52     } else {
53    
54     // Get a string without any null characters in it.
55     // -- maybe String.trim() would be better ?
56     if (xml.indexOf(0) != -1) {
57     xml = xml.substring(0, xml.indexOf(0));
58     }
59     else {
60     xml = xml.substring(0, xml.length());
61     }
62    
63     // Use XMLPacketMaker to make an XMLPacket object.
64     XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
65     XMLPacket packet = xmlPacketMaker.createXMLPacket();
66 ajm 1.13
67     // if we want to debug the packets
68     if(Configuration.getInstance().getProperty("packetDump") != null) {
69     System.out.println("[DEBUG]\n" + packet.printAll());
70     }
71    
72 ajm 1.11 String packetType = packet.getParam("packet.attributes.type");
73     if (packetType.equals("heartbeat") || packetType.equals("data")) {
74     String hostName = packet.getParam("packet.attributes.machine_name");
75     if(!hostList.containsKey(hostName)) {
76 ajm 1.1
77 ajm 1.11 HostDisplayPanel host = new HostDisplayPanel(hostName);
78     _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
79     hostList.put(hostName, host);
80     Conient.addMessage("New Host added: " + hostName);
81     }
82     if (!((HostDisplayPanel) hostList.get(hostName)).updateHost(packet)) {
83     //throw new Exception(hostName + " sent an invalid data packet stopping data update!");
84     Conient.addMessage("WARNING{data panel}: " + hostName + " sent an invalid data or heartbeat packet");
85     }
86 ajm 1.12 } else if (packetType.equals("queueStat")) {
87     // check to config to see if we want queueStat packets to be processed or not
88     if(Configuration.getInstance().getProperty("displayQueueInformation") != null) {
89     if (qFrame == null) {
90     qFrame = new QueueFrame();
91     }
92     qFrame.update(packet);
93     }
94 ajm 1.11 } else {
95     Conient.addMessage("WARNING{data panel}: and unknown packet type was received - " + packetType);
96 ajm 1.5 }
97 ajm 1.1 }
98     }
99     } catch (Exception e) {
100 ajm 1.8 Conient.addMessage("ERROR{data panel}: +" + e);
101 ajm 1.10 e.printStackTrace();
102 ajm 1.1 }
103     }
104    
105 ajm 1.5 /**
106     * This method allows other classes
107     * to shutdown this data panel.
108     */
109     public void shutdown() {
110     _running = false;
111     }
112    
113     //---PRIVATE METHODS---
114    
115     //---ACCESSOR/MUTATOR METHODS---
116    
117     //---ATTRIBUTES---
118    
119     /**
120     * The state of this thread.
121     */
122     boolean _running = true;
123    
124     /**
125     * Assigns the queue that this panel
126     * will use to obtain data
127     *
128     * @param queue the queue
129     */
130 ajm 1.1 public void setQueue(Queue queue) {
131     _dataQueue = queue;
132     _myQueue = _dataQueue.getQueue();
133 tdb 1.4 }
134    
135 ajm 1.5 /**
136     * Removes all the tabs on display
137     * Used to tidy up when a new data
138     * channel is opened.
139     */
140 tdb 1.4 public void cleanUpTabs() {
141     _tabbedPane.removeAll();
142 ajm 1.1 }
143    
144 ajm 1.5 /**
145     * The tabbed pane is where HostDisplayPanel's
146     * are placed
147     */
148 ajm 1.1 JTabbedPane _tabbedPane = new JTabbedPane();
149 ajm 1.5
150     /**
151     * The queue new data will be read from
152     */
153 ajm 1.1 Queue _dataQueue;
154 ajm 1.5
155     /**
156     * Our queue number
157     */
158 ajm 1.1 int _myQueue;
159 ajm 1.5
160     /**
161     * An icon to represent a host
162     */
163 ajm 1.7 ImageIcon _serverIcon = new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif");
164 ajm 1.12
165     /**
166     * A frame to display Queue information
167     * may not always be used - loaded according to config
168     */
169     QueueFrame qFrame = null;
170    
171 ajm 1.7 }