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

# Content
1 //---PACKAGE DECLARATION---
2 package uk.ac.ukc.iscream.conient;
3
4 //---IMPORTS---
5 import uk.ac.ukc.iscream.util.*;
6 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 * @author $Author: ajm4 $
17 * @version $Id: DataPanel.java,v 1.12 2001/02/25 21:23:38 ajm4 Exp $
18 */
19 public class DataPanel extends JPanel implements Runnable {
20
21 //---FINAL ATTRIBUTES---
22
23 /**
24 * The current CVS revision of this class
25 */
26 public final String REVISION = "$Revision: 1.12 $";
27
28 //---STATIC METHODS---
29
30 //---CONSTRUCTORS---
31
32 //---PUBLIC METHODS---
33
34 /**
35 * Starts the DataPanel running
36 */
37 public void run() {
38 // add the tabbed pane to ourselves
39 add(_tabbedPane);
40
41 // the hosts we are interested in go here
42 HashMap hostList = new HashMap();
43
44 try {
45 while(_running) {
46
47 String xml = (String) _dataQueue.get(_myQueue);
48 Conient.setQueueStatus(_dataQueue.queueSize(_myQueue), _dataQueue.elementCount());
49 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
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 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
77 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 } 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 } else {
95 Conient.addMessage("WARNING{data panel}: and unknown packet type was received - " + packetType);
96 }
97 }
98 }
99 } catch (Exception e) {
100 Conient.addMessage("ERROR{data panel}: +" + e);
101 e.printStackTrace();
102 }
103 }
104
105 /**
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 public void setQueue(Queue queue) {
131 _dataQueue = queue;
132 _myQueue = _dataQueue.getQueue();
133 }
134
135 /**
136 * Removes all the tabs on display
137 * Used to tidy up when a new data
138 * channel is opened.
139 */
140 public void cleanUpTabs() {
141 _tabbedPane.removeAll();
142 }
143
144 /**
145 * The tabbed pane is where HostDisplayPanel's
146 * are placed
147 */
148 JTabbedPane _tabbedPane = new JTabbedPane();
149
150 /**
151 * The queue new data will be read from
152 */
153 Queue _dataQueue;
154
155 /**
156 * Our queue number
157 */
158 int _myQueue;
159
160 /**
161 * An icon to represent a host
162 */
163 ImageIcon _serverIcon = new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif");
164
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 }