1 |
ajm |
1.1 |
//---PACKAGE DECLARATION--- |
2 |
tdb |
1.16 |
package uk.org.iscream.cms.conient; |
3 |
ajm |
1.1 |
|
4 |
|
|
//---IMPORTS--- |
5 |
tdb |
1.16 |
import uk.org.iscream.cms.server.util.*; |
6 |
|
|
import uk.org.iscream.cms.conient.datacomponents.*; |
7 |
ajm |
1.1 |
import javax.swing.*; |
8 |
|
|
import javax.swing.border.*; |
9 |
|
|
import java.util.*; |
10 |
|
|
import java.awt.*; |
11 |
|
|
import java.awt.event.*; |
12 |
|
|
|
13 |
|
|
/** |
14 |
ajm |
1.13 |
* 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 |
ajm |
1.1 |
* |
21 |
|
|
* @author $Author: ajm4 $ |
22 |
tdb |
1.16 |
* @version $Id: QueueFrame.java,v 1.15 2001/03/22 00:50:22 ajm4 Exp $ |
23 |
ajm |
1.1 |
*/ |
24 |
|
|
public class QueueFrame extends JFrame { |
25 |
|
|
|
26 |
|
|
//---FINAL ATTRIBUTES--- |
27 |
|
|
|
28 |
|
|
/** |
29 |
|
|
* The current CVS revision of this class |
30 |
|
|
*/ |
31 |
tdb |
1.16 |
public final String REVISION = "$Revision: 1.15 $"; |
32 |
ajm |
1.1 |
|
33 |
|
|
//---STATIC METHODS--- |
34 |
|
|
|
35 |
|
|
//---CONSTRUCTORS--- |
36 |
|
|
|
37 |
|
|
/** |
38 |
ajm |
1.13 |
* Constructs a new frame |
39 |
ajm |
1.1 |
*/ |
40 |
|
|
public QueueFrame() { |
41 |
|
|
super("Server Queue Status"); |
42 |
ajm |
1.12 |
JScrollPane scrollPane = new JScrollPane(_content,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED , JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
43 |
ajm |
1.11 |
getContentPane().add(scrollPane, "Center"); |
44 |
ajm |
1.1 |
JButton close = new JButton("Close Window"); |
45 |
|
|
close.addActionListener(new ActionListener() { |
46 |
|
|
public void actionPerformed(ActionEvent e) { |
47 |
ajm |
1.5 |
setVisible(false); |
48 |
ajm |
1.1 |
} |
49 |
|
|
}); |
50 |
|
|
getContentPane().add(close, "South"); |
51 |
ajm |
1.4 |
setIconImage((new ImageIcon("./resources/server.gif")).getImage()); |
52 |
ajm |
1.1 |
pack(); |
53 |
|
|
setVisible(true); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
//---PUBLIC METHODS--- |
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
* Process an incoming packet, updates the components. |
60 |
|
|
* |
61 |
|
|
* @param packet the packet to process |
62 |
|
|
* |
63 |
|
|
* @return if the proceesing was successful |
64 |
|
|
*/ |
65 |
|
|
public boolean update(XMLPacket packet) { |
66 |
|
|
// iterate over the packets data |
67 |
|
|
boolean displaySucessful = true; |
68 |
ajm |
1.6 |
String queueHashCode = packet.getParam("packet.attributes.hashCode"); |
69 |
ajm |
1.1 |
|
70 |
|
|
// if there are no components looking after this data |
71 |
|
|
// create a new StringDataComponent for it |
72 |
ajm |
1.6 |
if(!_queues.containsKey(queueHashCode)) { |
73 |
ajm |
1.1 |
addQueue(packet); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
// try and update the component, if it doesn't like what it gets |
77 |
|
|
// warn the user and set that this was an unsucessful display |
78 |
|
|
try { |
79 |
|
|
updateQueueInformation(packet); |
80 |
|
|
} catch (DataFormatException e) { |
81 |
|
|
Conient.addMessage("WARNING{queue frame}: " + e.getMessage()); |
82 |
|
|
displaySucessful = false; |
83 |
|
|
} |
84 |
|
|
return displaySucessful; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
//---PRIVATE METHODS--- |
88 |
|
|
|
89 |
ajm |
1.13 |
/** |
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 |
ajm |
1.1 |
private void addQueue(XMLPacket packet) { |
97 |
|
|
HashMap newQueue = new HashMap(); |
98 |
|
|
String queueName = packet.getParam("packet.attributes.name"); |
99 |
ajm |
1.6 |
String queueHashCode = packet.getParam("packet.attributes.hashCode"); |
100 |
ajm |
1.1 |
VisibleDataComponent date = new DateDataComponent("Last timestamp", "packet.attributes.date"); |
101 |
|
|
VisibleDataComponent total = new StringDataComponent("Total queued to date", "packet.queue.attributes.total"); |
102 |
ajm |
1.14 |
VisibleDataComponent max = new StringDataComponent("Maximum queue size", "packet.queue.attributes.maxSize"); |
103 |
ajm |
1.1 |
newQueue.put("packet.attributes.name", new StringDataComponent("Name", "packet.attributes.name")); |
104 |
|
|
newQueue.put("packet.queue.attributes.total", total); |
105 |
ajm |
1.14 |
newQueue.put("packet.queue.attributes.maxSize", max); |
106 |
ajm |
1.1 |
newQueue.put("packet.attributes.date", date); |
107 |
ajm |
1.14 |
|
108 |
ajm |
1.1 |
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 |
ajm |
1.15 |
newQueueDisplay.add(total); |
113 |
ajm |
1.14 |
newQueueDisplay.add(max); |
114 |
ajm |
1.8 |
_queuesDisplays.put(queueHashCode, newQueueDisplay); |
115 |
ajm |
1.1 |
try { |
116 |
|
|
SwingSafeAdd task = new SwingSafeAdd(_content, newQueueDisplay); |
117 |
|
|
SwingUtilities.invokeAndWait(task); |
118 |
|
|
} catch (Exception e) { |
119 |
|
|
// don't care |
120 |
|
|
} |
121 |
|
|
pack(); |
122 |
ajm |
1.6 |
_queues.put(queueHashCode, newQueue); |
123 |
ajm |
1.1 |
} |
124 |
ajm |
1.13 |
|
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 |
ajm |
1.1 |
private void updateQueueInformation(XMLPacket packet) throws DataFormatException { |
132 |
ajm |
1.6 |
String queueHashCode = packet.getParam("packet.attributes.hashCode"); |
133 |
ajm |
1.3 |
|
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 |
ajm |
1.6 |
JPanel temp = (JPanel)_queuesDisplays.get(queueHashCode); |
138 |
ajm |
1.3 |
temp.setVisible(false); |
139 |
|
|
_content.remove(temp); |
140 |
|
|
_queuesDisplays.remove(temp); |
141 |
|
|
pack(); |
142 |
|
|
|
143 |
|
|
// else update the display |
144 |
|
|
} else { |
145 |
ajm |
1.6 |
HashMap components = (HashMap) _queues.get(queueHashCode); |
146 |
ajm |
1.3 |
Set packetSet = packet.getSet(); |
147 |
|
|
Iterator i = packetSet.iterator(); |
148 |
|
|
while (i.hasNext()) { |
149 |
|
|
String dataKey = (String) i.next(); |
150 |
|
|
// if there are no components looking after this data |
151 |
|
|
// create a new StringDataComponent for it |
152 |
|
|
if(!components.containsKey(dataKey)) { |
153 |
ajm |
1.8 |
// check if its a queue, if it is then we need to deal with it |
154 |
ajm |
1.3 |
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 |
ajm |
1.6 |
SwingSafeAdd task = new SwingSafeAdd((JPanel)_queuesDisplays.get(queueHashCode), queue); |
159 |
ajm |
1.3 |
SwingUtilities.invokeAndWait(task); |
160 |
|
|
} catch (Exception e) { |
161 |
ajm |
1.8 |
// if there was a problem |
162 |
|
|
System.err.println("ERROR Failed To Add Component - " + e); |
163 |
ajm |
1.3 |
} |
164 |
|
|
pack(); |
165 |
ajm |
1.1 |
} |
166 |
ajm |
1.3 |
// note we ignore all other attributes |
167 |
|
|
} |
168 |
|
|
if(components.containsKey(dataKey)) { |
169 |
ajm |
1.10 |
((DataComponent) components.get(dataKey)).setValue(packet); |
170 |
ajm |
1.1 |
} |
171 |
|
|
} |
172 |
|
|
} |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
176 |
|
|
|
177 |
|
|
//---ATTRIBUTES--- |
178 |
|
|
|
179 |
|
|
/** |
180 |
|
|
* The components that we already know about |
181 |
|
|
* connected with the attributes they care about |
182 |
|
|
* are stored here. |
183 |
|
|
*/ |
184 |
|
|
private HashMap _queues = new HashMap(); |
185 |
ajm |
1.13 |
|
186 |
|
|
/** |
187 |
|
|
* The Panels on the display hooked to the queue hashid |
188 |
|
|
*/ |
189 |
ajm |
1.1 |
private HashMap _queuesDisplays = new HashMap(); |
190 |
|
|
|
191 |
ajm |
1.13 |
/** |
192 |
|
|
* The box to lay queue panels into. |
193 |
|
|
*/ |
194 |
ajm |
1.1 |
private Box _content = Box.createVerticalBox(); |
195 |
|
|
|
196 |
|
|
//---STATIC ATTRIBUTES--- |
197 |
|
|
|
198 |
|
|
} |