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.7
Committed: Thu Mar 1 16:11:37 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.6: +5 -2 lines
Log Message:
now displays the internal hashcode for the queue

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2     package uk.ac.ukc.iscream.conient;
3    
4     //---IMPORTS---
5     import uk.ac.ukc.iscream.util.*;
6     import uk.ac.ukc.iscream.conient.datacomponents.*;
7     import javax.swing.*;
8     import javax.swing.border.*;
9     import java.util.*;
10     import java.awt.*;
11     import java.awt.event.*;
12    
13     /**
14     *
15     * @author $Author: ajm4 $
16 ajm 1.7 * @version $Id: QueueFrame.java,v 1.6 2001/03/01 15:48:22 ajm4 Exp $
17 ajm 1.1 */
18     public class QueueFrame extends JFrame {
19    
20     //---FINAL ATTRIBUTES---
21    
22     /**
23     * The current CVS revision of this class
24     */
25 ajm 1.7 public final String REVISION = "$Revision: 1.6 $";
26 ajm 1.1
27     //---STATIC METHODS---
28    
29     //---CONSTRUCTORS---
30    
31     /**
32     *
33     */
34     public QueueFrame() {
35     super("Server Queue Status");
36     //addVisibleDataComponent(_conent, new StringDataComponent("Host Name", "packet.attributes.machine_name"));
37    
38     getContentPane().add(_content, "Center");
39     JButton close = new JButton("Close Window");
40     close.addActionListener(new ActionListener() {
41     public void actionPerformed(ActionEvent e) {
42 ajm 1.5 setVisible(false);
43 ajm 1.1 }
44     });
45     getContentPane().add(close, "South");
46 ajm 1.4 setIconImage((new ImageIcon("./resources/server.gif")).getImage());
47 ajm 1.1 pack();
48     setVisible(true);
49     }
50    
51     //---PUBLIC METHODS---
52    
53     /**
54     * Process an incoming packet, updates the components.
55     *
56     * @param packet the packet to process
57     *
58     * @return if the proceesing was successful
59     */
60     public boolean update(XMLPacket packet) {
61     // iterate over the packets data
62     boolean displaySucessful = true;
63 ajm 1.6 String queueHashCode = packet.getParam("packet.attributes.hashCode");
64 ajm 1.1
65     // if there are no components looking after this data
66     // create a new StringDataComponent for it
67 ajm 1.6 if(!_queues.containsKey(queueHashCode)) {
68 ajm 1.1 addQueue(packet);
69     }
70    
71     // try and update the component, if it doesn't like what it gets
72     // warn the user and set that this was an unsucessful display
73     try {
74     updateQueueInformation(packet);
75     } catch (DataFormatException e) {
76     Conient.addMessage("WARNING{queue frame}: " + e.getMessage());
77     displaySucessful = false;
78     }
79     return displaySucessful;
80     }
81    
82     //---PRIVATE METHODS---
83    
84     private void addQueue(XMLPacket packet) {
85     HashMap newQueue = new HashMap();
86     String queueName = packet.getParam("packet.attributes.name");
87 ajm 1.6 String queueHashCode = packet.getParam("packet.attributes.hashCode");
88 ajm 1.1 VisibleDataComponent date = new DateDataComponent("Last timestamp", "packet.attributes.date");
89     VisibleDataComponent total = new StringDataComponent("Total queued to date", "packet.queue.attributes.total");
90 ajm 1.7 VisibleDataComponent hashCode = new StringDataComponent("Internal hash code", "packet.attributes.hashCode");
91 ajm 1.1 newQueue.put("packet.attributes.name", new StringDataComponent("Name", "packet.attributes.name"));
92     newQueue.put("packet.queue.attributes.total", total);
93     newQueue.put("packet.attributes.date", date);
94 ajm 1.7 newQueue.put("packet.attributes.hashCode", hashCode);
95 ajm 1.1 JPanel newQueueDisplay = new JPanel();
96     newQueueDisplay.setLayout(new BoxLayout(newQueueDisplay, BoxLayout.Y_AXIS));
97     newQueueDisplay.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), queueName));
98     newQueueDisplay.add(date);
99     newQueueDisplay.add(total);
100 ajm 1.7 newQueueDisplay.add(hashCode);
101 ajm 1.1 _queuesDisplays.put(queueName, newQueueDisplay);
102     try {
103     SwingSafeAdd task = new SwingSafeAdd(_content, newQueueDisplay);
104     SwingUtilities.invokeAndWait(task);
105     } catch (Exception e) {
106     // don't care
107     }
108     pack();
109 ajm 1.6 _queues.put(queueHashCode, newQueue);
110 ajm 1.1 }
111    
112     private void updateQueueInformation(XMLPacket packet) throws DataFormatException {
113 ajm 1.6 String queueHashCode = packet.getParam("packet.attributes.hashCode");
114 ajm 1.3
115     // if it was a shutdown packet, remove the display
116     if (packet.getParam("packet.attributes.shutdown") != null) {
117     // *** !!! MAY NOT BE SWING SAFE !!! ***
118 ajm 1.6 JPanel temp = (JPanel)_queuesDisplays.get(queueHashCode);
119 ajm 1.3 temp.setVisible(false);
120     _content.remove(temp);
121     _queuesDisplays.remove(temp);
122     pack();
123    
124     // else update the display
125     } else {
126 ajm 1.6 HashMap components = (HashMap) _queues.get(queueHashCode);
127 ajm 1.3 Set packetSet = packet.getSet();
128     Iterator i = packetSet.iterator();
129     while (i.hasNext()) {
130     String dataKey = (String) i.next();
131     // if there are no components looking after this data
132     // create a new StringDataComponent for it
133     if(!components.containsKey(dataKey)) {
134     // check if its a disk drive, if it is then we need to deal with it
135     if(dataKey.startsWith("packet.queue.attributes.queue")) {
136     VisibleDataComponent queue = new StringDataComponent("Current length of " + dataKey.substring(dataKey.lastIndexOf('.') + 1), dataKey);
137     components.put(dataKey, queue);
138     try {
139 ajm 1.6 SwingSafeAdd task = new SwingSafeAdd((JPanel)_queuesDisplays.get(queueHashCode), queue);
140 ajm 1.3 SwingUtilities.invokeAndWait(task);
141     } catch (Exception e) {
142     // don't care
143     }
144     pack();
145 ajm 1.1 }
146 ajm 1.3 // note we ignore all other attributes
147     }
148     if(components.containsKey(dataKey)) {
149     ((DataComponent) components.get(dataKey)).setValue(packet.getParam(dataKey));
150 ajm 1.1 }
151     }
152     }
153     }
154    
155     //---ACCESSOR/MUTATOR METHODS---
156    
157     //---ATTRIBUTES---
158    
159     /**
160     * The components that we already know about
161     * connected with the attributes they care about
162     * are stored here.
163     */
164     private HashMap _queues = new HashMap();
165     private HashMap _queuesDisplays = new HashMap();
166    
167     private Box _content = Box.createVerticalBox();
168    
169     //---STATIC ATTRIBUTES---
170    
171     }