7 |
|
import javax.swing.ImageIcon; |
8 |
|
import javax.swing.JTabbedPane; |
9 |
|
import javax.swing.JPanel; |
10 |
+ |
import java.util.StringTokenizer; |
11 |
+ |
import javax.swing.SwingUtilities; |
12 |
|
|
13 |
|
/** |
14 |
|
* This thread reads data from the DataReader |
31 |
|
|
32 |
|
//---CONSTRUCTORS--- |
33 |
|
|
34 |
+ |
/** |
35 |
+ |
* Constructs the data panel |
36 |
+ |
*/ |
37 |
+ |
public DataPanel() { |
38 |
+ |
add(_tabbedPane); |
39 |
+ |
} |
40 |
+ |
|
41 |
|
//---PUBLIC METHODS--- |
42 |
|
|
43 |
|
/** |
44 |
|
* Starts the DataPanel running |
45 |
|
*/ |
46 |
|
public void run() { |
47 |
< |
// add the tabbed pane to ourselves |
48 |
< |
add(_tabbedPane); |
47 |
> |
// setup the host list we will be using |
48 |
> |
refreshHostList(); |
49 |
> |
|
50 |
|
|
41 |
– |
// the hosts we are interested in go here |
42 |
– |
HashMap hostList = new HashMap(); |
43 |
– |
|
51 |
|
try { |
52 |
|
while(_running) { |
53 |
|
|
72 |
|
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
73 |
|
|
74 |
|
// if we want to debug the packets |
75 |
< |
if(!Configuration.getInstance().getProperty("packetDump").equals("0")) { |
76 |
< |
System.out.println("[DEBUG]\n" + packet.printAll()); |
75 |
> |
if(Configuration.getInstance().getProperty("packetDump").equals("1")) { |
76 |
> |
System.out.println("[PACKET DUMP]\n" + packet.printAll()); |
77 |
|
} |
78 |
|
|
79 |
|
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 |
< |
if(!hostList.containsKey(hostName)) { |
83 |
< |
|
84 |
< |
HostDisplayPanel host = new HostDisplayPanel(hostName); |
85 |
< |
_tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName); |
86 |
< |
hostList.put(hostName, host); |
87 |
< |
Conient.addMessage("New Host added: " + hostName); |
82 |
> |
// 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 |
|
} |
94 |
< |
if (!((HostDisplayPanel) hostList.get(hostName)).updateHost(packet)) { |
95 |
< |
//throw new Exception(hostName + " sent an invalid data packet stopping data update!"); |
96 |
< |
Conient.addMessage("WARNING{data panel}: " + hostName + " sent an invalid data or heartbeat packet"); |
94 |
> |
// 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 |
|
} |
104 |
|
} else if (packetType.equals("queueStat")) { |
105 |
|
// check to config to see if we want queueStat packets to be processed or not |
106 |
< |
if(!Configuration.getInstance().getProperty("displayQueueInformation").equals("0")) { |
107 |
< |
if (qFrame == null) { |
108 |
< |
qFrame = new QueueFrame(); |
106 |
> |
if(Configuration.getInstance().getProperty("displayQueueInformation").equals("1")) { |
107 |
> |
if (_qFrame == null) { |
108 |
> |
_qFrame = new QueueFrame(); |
109 |
|
} |
110 |
< |
qFrame.update(packet); |
110 |
> |
if (!_qFrame.isVisible()) { |
111 |
> |
_qFrame.setVisible(true); |
112 |
> |
} |
113 |
> |
_qFrame.update(packet); |
114 |
|
} |
115 |
|
} else { |
116 |
|
Conient.addMessage("WARNING{data panel}: and unknown packet type was received - " + packetType); |
133 |
|
|
134 |
|
//---PRIVATE METHODS--- |
135 |
|
|
136 |
+ |
/** |
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 |
|
//---ACCESSOR/MUTATOR METHODS--- |
197 |
|
|
198 |
|
//---ATTRIBUTES--- |
247 |
|
* A frame to display Queue information |
248 |
|
* may not always be used - loaded according to config |
249 |
|
*/ |
250 |
< |
QueueFrame qFrame = null; |
250 |
> |
QueueFrame _qFrame = null; |
251 |
|
|
252 |
+ |
/** |
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 |
|
} |