1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.conient; |
2 |
> |
package uk.org.iscream.conient; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.util.*; |
6 |
< |
import uk.ac.ukc.iscream.conient.datacomponents.*; |
5 |
> |
import uk.org.iscream.util.*; |
6 |
> |
import uk.org.iscream.conient.datacomponents.*; |
7 |
|
import javax.swing.*; |
8 |
|
import javax.swing.border.*; |
9 |
|
import java.util.*; |
11 |
|
import java.awt.event.*; |
12 |
|
|
13 |
|
/** |
14 |
+ |
* This class allows a window to be shown which displays |
15 |
+ |
* internel server queue information as sent by the i-scream |
16 |
+ |
* server. |
17 |
|
* |
18 |
+ |
* This allows a check to be made on the current performance of |
19 |
+ |
* the internal queues. |
20 |
+ |
* |
21 |
|
* @author $Author$ |
22 |
|
* @version $Id$ |
23 |
|
*/ |
35 |
|
//---CONSTRUCTORS--- |
36 |
|
|
37 |
|
/** |
38 |
< |
* |
38 |
> |
* Constructs a new frame |
39 |
|
*/ |
40 |
|
public QueueFrame() { |
41 |
|
super("Server Queue Status"); |
42 |
< |
//addVisibleDataComponent(_conent, new StringDataComponent("Host Name", "packet.attributes.machine_name")); |
43 |
< |
|
38 |
< |
getContentPane().add(_content, "Center"); |
42 |
> |
JScrollPane scrollPane = new JScrollPane(_content,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED , JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
43 |
> |
getContentPane().add(scrollPane, "Center"); |
44 |
|
JButton close = new JButton("Close Window"); |
45 |
|
close.addActionListener(new ActionListener() { |
46 |
|
public void actionPerformed(ActionEvent e) { |
65 |
|
public boolean update(XMLPacket packet) { |
66 |
|
// iterate over the packets data |
67 |
|
boolean displaySucessful = true; |
68 |
< |
String queueName = packet.getParam("packet.attributes.name"); |
68 |
> |
String queueHashCode = packet.getParam("packet.attributes.hashCode"); |
69 |
|
|
70 |
|
// if there are no components looking after this data |
71 |
|
// create a new StringDataComponent for it |
72 |
< |
if(!_queues.containsKey(queueName)) { |
72 |
> |
if(!_queues.containsKey(queueHashCode)) { |
73 |
|
addQueue(packet); |
74 |
|
} |
75 |
|
|
86 |
|
|
87 |
|
//---PRIVATE METHODS--- |
88 |
|
|
89 |
+ |
/** |
90 |
+ |
* Constructs and adds a new Queue panel to the |
91 |
+ |
* current window. This happens when a new queue packet |
92 |
+ |
* is detected |
93 |
+ |
* |
94 |
+ |
* @param packet the packet to obtain the queue data from |
95 |
+ |
*/ |
96 |
|
private void addQueue(XMLPacket packet) { |
97 |
|
HashMap newQueue = new HashMap(); |
98 |
|
String queueName = packet.getParam("packet.attributes.name"); |
99 |
+ |
String queueHashCode = packet.getParam("packet.attributes.hashCode"); |
100 |
|
VisibleDataComponent date = new DateDataComponent("Last timestamp", "packet.attributes.date"); |
101 |
|
VisibleDataComponent total = new StringDataComponent("Total queued to date", "packet.queue.attributes.total"); |
102 |
+ |
VisibleDataComponent max = new StringDataComponent("Maximum queue size", "packet.queue.attributes.maxSize"); |
103 |
|
newQueue.put("packet.attributes.name", new StringDataComponent("Name", "packet.attributes.name")); |
104 |
|
newQueue.put("packet.queue.attributes.total", total); |
105 |
+ |
newQueue.put("packet.queue.attributes.maxSize", max); |
106 |
|
newQueue.put("packet.attributes.date", date); |
107 |
+ |
|
108 |
|
JPanel newQueueDisplay = new JPanel(); |
109 |
|
newQueueDisplay.setLayout(new BoxLayout(newQueueDisplay, BoxLayout.Y_AXIS)); |
110 |
|
newQueueDisplay.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), queueName)); |
111 |
|
newQueueDisplay.add(date); |
112 |
+ |
newQueueDisplay.add(max); |
113 |
|
newQueueDisplay.add(total); |
114 |
< |
_queuesDisplays.put(queueName, newQueueDisplay); |
114 |
> |
_queuesDisplays.put(queueHashCode, newQueueDisplay); |
115 |
|
try { |
116 |
|
SwingSafeAdd task = new SwingSafeAdd(_content, newQueueDisplay); |
117 |
|
SwingUtilities.invokeAndWait(task); |
119 |
|
// don't care |
120 |
|
} |
121 |
|
pack(); |
122 |
< |
_queues.put(queueName, newQueue); |
122 |
> |
_queues.put(queueHashCode, newQueue); |
123 |
|
} |
124 |
< |
|
124 |
> |
|
125 |
> |
/** |
126 |
> |
* Updates a queue panel with new data |
127 |
> |
* |
128 |
> |
* @param packet the packet to obtain the new data from |
129 |
> |
* @throws DataFormatException if the packet contains invalid data |
130 |
> |
*/ |
131 |
|
private void updateQueueInformation(XMLPacket packet) throws DataFormatException { |
132 |
< |
String queueName = packet.getParam("packet.attributes.name"); |
132 |
> |
String queueHashCode = packet.getParam("packet.attributes.hashCode"); |
133 |
|
|
134 |
|
// if it was a shutdown packet, remove the display |
135 |
|
if (packet.getParam("packet.attributes.shutdown") != null) { |
136 |
|
// *** !!! MAY NOT BE SWING SAFE !!! *** |
137 |
< |
JPanel temp = (JPanel)_queuesDisplays.get(queueName); |
137 |
> |
JPanel temp = (JPanel)_queuesDisplays.get(queueHashCode); |
138 |
|
temp.setVisible(false); |
139 |
|
_content.remove(temp); |
140 |
|
_queuesDisplays.remove(temp); |
142 |
|
|
143 |
|
// else update the display |
144 |
|
} else { |
145 |
< |
HashMap components = (HashMap) _queues.get(queueName); |
145 |
> |
HashMap components = (HashMap) _queues.get(queueHashCode); |
146 |
|
Set packetSet = packet.getSet(); |
147 |
|
Iterator i = packetSet.iterator(); |
148 |
|
while (i.hasNext()) { |
150 |
|
// if there are no components looking after this data |
151 |
|
// create a new StringDataComponent for it |
152 |
|
if(!components.containsKey(dataKey)) { |
153 |
< |
// check if its a disk drive, if it is then we need to deal with it |
153 |
> |
// check if its a queue, if it is then we need to deal with it |
154 |
|
if(dataKey.startsWith("packet.queue.attributes.queue")) { |
155 |
|
VisibleDataComponent queue = new StringDataComponent("Current length of " + dataKey.substring(dataKey.lastIndexOf('.') + 1), dataKey); |
156 |
|
components.put(dataKey, queue); |
157 |
|
try { |
158 |
< |
SwingSafeAdd task = new SwingSafeAdd((JPanel)_queuesDisplays.get(queueName), queue); |
158 |
> |
SwingSafeAdd task = new SwingSafeAdd((JPanel)_queuesDisplays.get(queueHashCode), queue); |
159 |
|
SwingUtilities.invokeAndWait(task); |
160 |
|
} catch (Exception e) { |
161 |
< |
// don't care |
161 |
> |
// if there was a problem |
162 |
> |
System.err.println("ERROR Failed To Add Component - " + e); |
163 |
|
} |
164 |
|
pack(); |
165 |
|
} |
166 |
|
// note we ignore all other attributes |
167 |
|
} |
168 |
|
if(components.containsKey(dataKey)) { |
169 |
< |
((DataComponent) components.get(dataKey)).setValue(packet.getParam(dataKey)); |
169 |
> |
((DataComponent) components.get(dataKey)).setValue(packet); |
170 |
|
} |
171 |
|
} |
172 |
|
} |
182 |
|
* are stored here. |
183 |
|
*/ |
184 |
|
private HashMap _queues = new HashMap(); |
185 |
+ |
|
186 |
+ |
/** |
187 |
+ |
* The Panels on the display hooked to the queue hashid |
188 |
+ |
*/ |
189 |
|
private HashMap _queuesDisplays = new HashMap(); |
190 |
|
|
191 |
+ |
/** |
192 |
+ |
* The box to lay queue panels into. |
193 |
+ |
*/ |
194 |
|
private Box _content = Box.createVerticalBox(); |
195 |
|
|
196 |
|
//---STATIC ATTRIBUTES--- |