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 |
< |
|
44 |
< |
getContentPane().add(_content, "Center"); |
43 |
> |
JScrollPane scrollPane = new JScrollPane(_content,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED , JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
44 |
> |
getContentPane().add(scrollPane, "Center"); |
45 |
|
JButton close = new JButton("Close Window"); |
46 |
|
close.addActionListener(new ActionListener() { |
47 |
|
public void actionPerformed(ActionEvent e) { |
48 |
< |
dispose(); |
48 |
> |
setVisible(false); |
49 |
|
} |
50 |
|
}); |
51 |
|
getContentPane().add(close, "South"); |
66 |
|
public boolean update(XMLPacket packet) { |
67 |
|
// iterate over the packets data |
68 |
|
boolean displaySucessful = true; |
69 |
< |
String queueName = packet.getParam("packet.attributes.name"); |
69 |
> |
String queueHashCode = packet.getParam("packet.attributes.hashCode"); |
70 |
|
|
71 |
|
// if there are no components looking after this data |
72 |
|
// create a new StringDataComponent for it |
73 |
< |
if(!_queues.containsKey(queueName)) { |
73 |
> |
if(!_queues.containsKey(queueHashCode)) { |
74 |
|
addQueue(packet); |
75 |
|
} |
76 |
|
|
87 |
|
|
88 |
|
//---PRIVATE METHODS--- |
89 |
|
|
90 |
+ |
/** |
91 |
+ |
* Constructs and adds a new Queue panel to the |
92 |
+ |
* current window. This happens when a new queue packet |
93 |
+ |
* is detected |
94 |
+ |
* |
95 |
+ |
* @param packet the packet to obtain the queue data from |
96 |
+ |
*/ |
97 |
|
private void addQueue(XMLPacket packet) { |
98 |
|
HashMap newQueue = new HashMap(); |
99 |
|
String queueName = packet.getParam("packet.attributes.name"); |
100 |
+ |
String queueHashCode = packet.getParam("packet.attributes.hashCode"); |
101 |
|
VisibleDataComponent date = new DateDataComponent("Last timestamp", "packet.attributes.date"); |
102 |
|
VisibleDataComponent total = new StringDataComponent("Total queued to date", "packet.queue.attributes.total"); |
103 |
|
newQueue.put("packet.attributes.name", new StringDataComponent("Name", "packet.attributes.name")); |
108 |
|
newQueueDisplay.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), queueName)); |
109 |
|
newQueueDisplay.add(date); |
110 |
|
newQueueDisplay.add(total); |
111 |
< |
_queuesDisplays.put(queueName, newQueueDisplay); |
111 |
> |
_queuesDisplays.put(queueHashCode, newQueueDisplay); |
112 |
|
try { |
113 |
|
SwingSafeAdd task = new SwingSafeAdd(_content, newQueueDisplay); |
114 |
|
SwingUtilities.invokeAndWait(task); |
116 |
|
// don't care |
117 |
|
} |
118 |
|
pack(); |
119 |
< |
_queues.put(queueName, newQueue); |
119 |
> |
_queues.put(queueHashCode, newQueue); |
120 |
|
} |
121 |
< |
|
121 |
> |
|
122 |
> |
/** |
123 |
> |
* Updates a queue panel with new data |
124 |
> |
* |
125 |
> |
* @param packet the packet to obtain the new data from |
126 |
> |
* @throws DataFormatException if the packet contains invalid data |
127 |
> |
*/ |
128 |
|
private void updateQueueInformation(XMLPacket packet) throws DataFormatException { |
129 |
< |
String queueName = packet.getParam("packet.attributes.name"); |
129 |
> |
String queueHashCode = packet.getParam("packet.attributes.hashCode"); |
130 |
|
|
131 |
|
// if it was a shutdown packet, remove the display |
132 |
|
if (packet.getParam("packet.attributes.shutdown") != null) { |
133 |
|
// *** !!! MAY NOT BE SWING SAFE !!! *** |
134 |
< |
JPanel temp = (JPanel)_queuesDisplays.get(queueName); |
134 |
> |
JPanel temp = (JPanel)_queuesDisplays.get(queueHashCode); |
135 |
|
temp.setVisible(false); |
136 |
|
_content.remove(temp); |
137 |
|
_queuesDisplays.remove(temp); |
139 |
|
|
140 |
|
// else update the display |
141 |
|
} else { |
142 |
< |
HashMap components = (HashMap) _queues.get(queueName); |
142 |
> |
HashMap components = (HashMap) _queues.get(queueHashCode); |
143 |
|
Set packetSet = packet.getSet(); |
144 |
|
Iterator i = packetSet.iterator(); |
145 |
|
while (i.hasNext()) { |
147 |
|
// if there are no components looking after this data |
148 |
|
// create a new StringDataComponent for it |
149 |
|
if(!components.containsKey(dataKey)) { |
150 |
< |
// check if its a disk drive, if it is then we need to deal with it |
150 |
> |
// check if its a queue, if it is then we need to deal with it |
151 |
|
if(dataKey.startsWith("packet.queue.attributes.queue")) { |
152 |
|
VisibleDataComponent queue = new StringDataComponent("Current length of " + dataKey.substring(dataKey.lastIndexOf('.') + 1), dataKey); |
153 |
|
components.put(dataKey, queue); |
154 |
|
try { |
155 |
< |
SwingSafeAdd task = new SwingSafeAdd((JPanel)_queuesDisplays.get(queueName), queue); |
155 |
> |
SwingSafeAdd task = new SwingSafeAdd((JPanel)_queuesDisplays.get(queueHashCode), queue); |
156 |
|
SwingUtilities.invokeAndWait(task); |
157 |
|
} catch (Exception e) { |
158 |
< |
// don't care |
158 |
> |
// if there was a problem |
159 |
> |
System.err.println("ERROR Failed To Add Component - " + e); |
160 |
|
} |
161 |
|
pack(); |
162 |
|
} |
163 |
|
// note we ignore all other attributes |
164 |
|
} |
165 |
|
if(components.containsKey(dataKey)) { |
166 |
< |
((DataComponent) components.get(dataKey)).setValue(packet.getParam(dataKey)); |
166 |
> |
((DataComponent) components.get(dataKey)).setValue(packet); |
167 |
|
} |
168 |
|
} |
169 |
|
} |
179 |
|
* are stored here. |
180 |
|
*/ |
181 |
|
private HashMap _queues = new HashMap(); |
182 |
+ |
|
183 |
+ |
/** |
184 |
+ |
* The Panels on the display hooked to the queue hashid |
185 |
+ |
*/ |
186 |
|
private HashMap _queuesDisplays = new HashMap(); |
187 |
|
|
188 |
+ |
/** |
189 |
+ |
* The box to lay queue panels into. |
190 |
+ |
*/ |
191 |
|
private Box _content = Box.createVerticalBox(); |
192 |
|
|
193 |
|
//---STATIC ATTRIBUTES--- |