ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/QueueFrame.java
Revision: 1.17
Committed: Sat May 18 18:15:56 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.16: +22 -3 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.17 /*
2     * i-scream central monitoring system
3     * Copyright (C) 2000-2002 i-scream
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19    
20 ajm 1.1 //---PACKAGE DECLARATION---
21 tdb 1.16 package uk.org.iscream.cms.conient;
22 ajm 1.1
23     //---IMPORTS---
24 tdb 1.16 import uk.org.iscream.cms.server.util.*;
25     import uk.org.iscream.cms.conient.datacomponents.*;
26 ajm 1.1 import javax.swing.*;
27     import javax.swing.border.*;
28     import java.util.*;
29     import java.awt.*;
30     import java.awt.event.*;
31    
32     /**
33 ajm 1.13 * This class allows a window to be shown which displays
34     * internel server queue information as sent by the i-scream
35     * server.
36     *
37     * This allows a check to be made on the current performance of
38     * the internal queues.
39 ajm 1.1 *
40 tdb 1.17 * @author $Author: tdb $
41     * @version $Id: QueueFrame.java,v 1.16 2001/05/29 17:41:32 tdb Exp $
42 ajm 1.1 */
43     public class QueueFrame extends JFrame {
44    
45     //---FINAL ATTRIBUTES---
46    
47     /**
48     * The current CVS revision of this class
49     */
50 tdb 1.17 public final String REVISION = "$Revision: 1.16 $";
51 ajm 1.1
52     //---STATIC METHODS---
53    
54     //---CONSTRUCTORS---
55    
56     /**
57 ajm 1.13 * Constructs a new frame
58 ajm 1.1 */
59     public QueueFrame() {
60     super("Server Queue Status");
61 ajm 1.12 JScrollPane scrollPane = new JScrollPane(_content,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED , JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
62 ajm 1.11 getContentPane().add(scrollPane, "Center");
63 ajm 1.1 JButton close = new JButton("Close Window");
64     close.addActionListener(new ActionListener() {
65     public void actionPerformed(ActionEvent e) {
66 ajm 1.5 setVisible(false);
67 ajm 1.1 }
68     });
69     getContentPane().add(close, "South");
70 ajm 1.4 setIconImage((new ImageIcon("./resources/server.gif")).getImage());
71 ajm 1.1 pack();
72     setVisible(true);
73     }
74    
75     //---PUBLIC METHODS---
76    
77     /**
78     * Process an incoming packet, updates the components.
79     *
80     * @param packet the packet to process
81     *
82     * @return if the proceesing was successful
83     */
84     public boolean update(XMLPacket packet) {
85     // iterate over the packets data
86     boolean displaySucessful = true;
87 ajm 1.6 String queueHashCode = packet.getParam("packet.attributes.hashCode");
88 ajm 1.1
89     // if there are no components looking after this data
90     // create a new StringDataComponent for it
91 ajm 1.6 if(!_queues.containsKey(queueHashCode)) {
92 ajm 1.1 addQueue(packet);
93     }
94    
95     // try and update the component, if it doesn't like what it gets
96     // warn the user and set that this was an unsucessful display
97     try {
98     updateQueueInformation(packet);
99     } catch (DataFormatException e) {
100     Conient.addMessage("WARNING{queue frame}: " + e.getMessage());
101     displaySucessful = false;
102     }
103     return displaySucessful;
104     }
105    
106     //---PRIVATE METHODS---
107    
108 ajm 1.13 /**
109     * Constructs and adds a new Queue panel to the
110     * current window. This happens when a new queue packet
111     * is detected
112     *
113     * @param packet the packet to obtain the queue data from
114     */
115 ajm 1.1 private void addQueue(XMLPacket packet) {
116     HashMap newQueue = new HashMap();
117     String queueName = packet.getParam("packet.attributes.name");
118 ajm 1.6 String queueHashCode = packet.getParam("packet.attributes.hashCode");
119 ajm 1.1 VisibleDataComponent date = new DateDataComponent("Last timestamp", "packet.attributes.date");
120     VisibleDataComponent total = new StringDataComponent("Total queued to date", "packet.queue.attributes.total");
121 ajm 1.14 VisibleDataComponent max = new StringDataComponent("Maximum queue size", "packet.queue.attributes.maxSize");
122 ajm 1.1 newQueue.put("packet.attributes.name", new StringDataComponent("Name", "packet.attributes.name"));
123     newQueue.put("packet.queue.attributes.total", total);
124 ajm 1.14 newQueue.put("packet.queue.attributes.maxSize", max);
125 ajm 1.1 newQueue.put("packet.attributes.date", date);
126 ajm 1.14
127 ajm 1.1 JPanel newQueueDisplay = new JPanel();
128     newQueueDisplay.setLayout(new BoxLayout(newQueueDisplay, BoxLayout.Y_AXIS));
129     newQueueDisplay.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), queueName));
130     newQueueDisplay.add(date);
131 ajm 1.15 newQueueDisplay.add(total);
132 ajm 1.14 newQueueDisplay.add(max);
133 ajm 1.8 _queuesDisplays.put(queueHashCode, newQueueDisplay);
134 ajm 1.1 try {
135     SwingSafeAdd task = new SwingSafeAdd(_content, newQueueDisplay);
136     SwingUtilities.invokeAndWait(task);
137     } catch (Exception e) {
138     // don't care
139     }
140     pack();
141 ajm 1.6 _queues.put(queueHashCode, newQueue);
142 ajm 1.1 }
143 ajm 1.13
144     /**
145     * Updates a queue panel with new data
146     *
147     * @param packet the packet to obtain the new data from
148     * @throws DataFormatException if the packet contains invalid data
149     */
150 ajm 1.1 private void updateQueueInformation(XMLPacket packet) throws DataFormatException {
151 ajm 1.6 String queueHashCode = packet.getParam("packet.attributes.hashCode");
152 ajm 1.3
153     // if it was a shutdown packet, remove the display
154     if (packet.getParam("packet.attributes.shutdown") != null) {
155     // *** !!! MAY NOT BE SWING SAFE !!! ***
156 ajm 1.6 JPanel temp = (JPanel)_queuesDisplays.get(queueHashCode);
157 ajm 1.3 temp.setVisible(false);
158     _content.remove(temp);
159     _queuesDisplays.remove(temp);
160     pack();
161    
162     // else update the display
163     } else {
164 ajm 1.6 HashMap components = (HashMap) _queues.get(queueHashCode);
165 ajm 1.3 Set packetSet = packet.getSet();
166     Iterator i = packetSet.iterator();
167     while (i.hasNext()) {
168     String dataKey = (String) i.next();
169     // if there are no components looking after this data
170     // create a new StringDataComponent for it
171     if(!components.containsKey(dataKey)) {
172 ajm 1.8 // check if its a queue, if it is then we need to deal with it
173 ajm 1.3 if(dataKey.startsWith("packet.queue.attributes.queue")) {
174     VisibleDataComponent queue = new StringDataComponent("Current length of " + dataKey.substring(dataKey.lastIndexOf('.') + 1), dataKey);
175     components.put(dataKey, queue);
176     try {
177 ajm 1.6 SwingSafeAdd task = new SwingSafeAdd((JPanel)_queuesDisplays.get(queueHashCode), queue);
178 ajm 1.3 SwingUtilities.invokeAndWait(task);
179     } catch (Exception e) {
180 ajm 1.8 // if there was a problem
181     System.err.println("ERROR Failed To Add Component - " + e);
182 ajm 1.3 }
183     pack();
184 ajm 1.1 }
185 ajm 1.3 // note we ignore all other attributes
186     }
187     if(components.containsKey(dataKey)) {
188 ajm 1.10 ((DataComponent) components.get(dataKey)).setValue(packet);
189 ajm 1.1 }
190     }
191     }
192     }
193    
194     //---ACCESSOR/MUTATOR METHODS---
195    
196     //---ATTRIBUTES---
197    
198     /**
199     * The components that we already know about
200     * connected with the attributes they care about
201     * are stored here.
202     */
203     private HashMap _queues = new HashMap();
204 ajm 1.13
205     /**
206     * The Panels on the display hooked to the queue hashid
207     */
208 ajm 1.1 private HashMap _queuesDisplays = new HashMap();
209    
210 ajm 1.13 /**
211     * The box to lay queue panels into.
212     */
213 ajm 1.1 private Box _content = Box.createVerticalBox();
214    
215     //---STATIC ATTRIBUTES---
216    
217     }