ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/HostDisplayPanel.java
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/HostDisplayPanel.java (file contents):
Revision 1.6 by tdb, Mon Jan 22 19:35:36 2001 UTC vs.
Revision 1.7 by ajm, Wed Jan 24 03:09:44 2001 UTC

# Line 1 | Line 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 java.util.HashMap;
8   import java.util.Set;
9   import java.util.Collections;
# Line 12 | Line 14 | import javax.swing.JPanel;
14   import javax.swing.JProgressBar;
15  
16   /**
17 < * At this time, this is simply a Panel which displays
18 < * all the host data and updates it when asked.
19 < * Has crude suport for heartbeats.
20 < * Now reads all other data as "Extra Data".
17 > * A HostDisplayPanel is simply a JPanel containing
18 > * DataComponents which relate to various host
19 > * attributes.  Once created, it can be asked to
20 > * update the data it displays by passing it an XML
21 > * packet for the host it displaying for.
22 > * This then updates all the DataComponents with the
23 > * values in the packet.
24   *
25   * @author  $Author$
26   * @version $Id$
# Line 34 | Line 39 | public class HostDisplayPanel extends JPanel {
39   //---CONSTRUCTORS---
40  
41      /**
42 <     * Creates a new Host Display Panel
42 >     * Creates a new Host Display Panel and adds
43 >     * all the appropriate DataComponents
44       */
45      public HostDisplayPanel() {
46 +        // set up the Panel
47          setLayout(new BorderLayout());
48          _east.add(_timeToHeartBeat);
49          add(_east, "East");
50          add(_center, "Center");
44        addDataComponent("packet.attributes.date", new DateDataComponent("Host Time"));
45        addDataComponent("packet.cpu.idle", new CPUDataComponent("CPU Idle"));
46        addDataComponent("packet.cpu.user", new CPUDataComponent("CPU User"));
47        addDataComponent("packet.cpu.kernel", new CPUDataComponent("CPU Kernel"));
48        addDataComponent("packet.cpu.iowait", new CPUDataComponent("CPU i/o wait"));
49        addDataComponent("packet.cpu.swap", new CPUDataComponent("CPU swapping"));
51          
52 <        MemoryTotalDataComponent totalMem = new MemoryTotalDataComponent("Total Memory");
52 >        // add all the DataComponents that we know about
53 >        addVisibleDataComponent("packet.attributes.date", new DateDataComponent("Host Time", "packet.attributes.date"));
54 >        addVisibleDataComponent("packet.cpu.idle", new CPUDataComponent("CPU Idle", "packet.cpu.idle"));
55 >        addVisibleDataComponent("packet.cpu.user", new CPUDataComponent("CPU User", "packet.cpu.user"));
56 >        addVisibleDataComponent("packet.cpu.kernel", new CPUDataComponent("CPU Kernel", "packet.cpu.kernel"));
57 >        addVisibleDataComponent("packet.cpu.iowait", new CPUDataComponent("CPU i/o wait", "packet.cpu.iowait"));
58 >        addVisibleDataComponent("packet.cpu.swap", new CPUDataComponent("CPU swapping", "packet.cpu.swap"));
59 >        
60 >        // theses next two are DataComponents, but not VisibleDataComponents
61 >        // this is because they hold the value but do NOT display it
62 >        MemoryTotalDataComponent totalMem = new MemoryTotalDataComponent("Total Memory", "packet.memory.total");
63          addDataComponent("packet.memory.total", totalMem);
64 <        MemoryTotalDataComponent totalSwap = new MemoryTotalDataComponent("Total Swap");
64 >        MemoryTotalDataComponent totalSwap = new MemoryTotalDataComponent("Total Swap", "packet.swap.total");
65          addDataComponent("packet.swap.total", totalSwap);
55        addDataComponent("packet.memory.free", new MemoryFreeDataComponent("Memory in use", totalMem));
56        addDataComponent("packet.swap.free", new MemoryFreeDataComponent("Swap in use", totalSwap));
66          
67 <        addDataComponent("packet.users.list", new UsersDataComponent("User List"));
68 <        
69 <        
67 >        // these next two are passed the non-visible datacomponents
68 >        addVisibleDataComponent("packet.memory.free", new MemoryFreeDataComponent("Memory in use", "packet.memory.free", totalMem));
69 >        addVisibleDataComponent("packet.swap.free", new MemoryFreeDataComponent("Swap in use", "packet.swap.free", totalSwap));
70 >
71 >        addVisibleDataComponent("packet.users.list", new UsersDataComponent("User List", "packet.users.list"));
72 >
73 >        // everything else we get is "extra", but we still want to display it        
74          _center.add(new javax.swing.JLabel("--- Extra Data ---"));
75      }
76  
77   //---PUBLIC METHODS---
78  
79 <    public void updateHost(XMLPacket packet) {
79 >    /**
80 >     * This method takes an XMLPacket containing
81 >     * information about the host this HostDisplayPanel
82 >     * is currently displaying.  It then updates all of the
83 >     * components with the new values.
84 >     *
85 >     * It also adds a standard StringDataComponent, should
86 >     * an attribute come up that there are no DataComponents
87 >     * associated with.
88 >     *
89 >     * @param packet the XML packet
90 >     * @return if the update was sucessful
91 >     */
92 >    public boolean updateHost(XMLPacket packet) {
93 >        // set that everything is ok so far
94 >        displaySucessful = true;
95 >        
96 >        // a simple way to handle heatbeats - this WILL change
97          if ((packet.getParam("packet.attributes.type")).equals("heartbeat")) {
98              _timeToHeartBeat.setValue(_max);
99 +        
100 +        // must be a normal data packet, update the display
101          } else {
102              _timeToHeartBeat.setValue(_timeToHeartBeat.getValue() - 1);
103 +            
104 +            // iterate over the packets data
105              Set packetSet = packet.getSet();
106              Iterator i = packetSet.iterator();
107              while (i.hasNext()) {
108                  String dataKey = (String) i.next();
109 +                
110 +                // if there are no components looking after this data
111 +                // create a new StringDataComponent for it
112                  if(!_components.containsKey(dataKey)) {
113 <                    addDataComponent(dataKey, new StringDataComponent(dataKey));
113 >                    addDataComponent(dataKey, new StringDataComponent(dataKey, dataKey));
114                  }
115 +                
116 +                // try and update the component, if it doesn't like what it gets
117 +                // warn the user and set that this was an unsucessful display
118                  try {
119                      ((DataComponent) _components.get(dataKey)).setValue(packet.getParam(dataKey));
120                  } catch (DataFormatException e) {
121 <                    SwingClient.addMessage("PACKET DATA ERROR: incorrect packet format - " + e);
121 >                    SwingClient.addMessage("WARNING: " + e.getMessage());
122 >                    displaySucessful = false;
123                  }
124              }
125          }
126 +        return displaySucessful;        
127      }
128  
129 +    /**
130 +     * Adds a DataComponent to the list of already
131 +     * known data components. The list is aware of
132 +     * what packet attributes that a DataComponent
133 +     * is looking after.
134 +     *
135 +     * @param ref the packet attribute that this Component looks after
136 +     * @param dataComponent the actual DataComponent
137 +     */
138      private void addDataComponent(String ref, DataComponent dataComponent) {
139          _components.put(ref, dataComponent);
140 +    }
141 +
142 +    /**
143 +     * Adds a DataComponent to the list of already
144 +     * known data components. The list is aware of
145 +     * what packet attributes that a DataComponent
146 +     * is looking after.
147 +     *
148 +     * Used for VISIBLE data components, as they are added to the display.
149 +     *
150 +     * @param ref the packet attribute that this Component looks after
151 +     * @param dataComponent the actual DataComponent
152 +     */
153 +    public void addVisibleDataComponent(String ref, VisibleDataComponent dataComponent) {
154 +        _components.put(ref, (DataComponent) dataComponent);
155          _center.add(dataComponent);
156      }
157  
158 + //---ATTRIBUTES---
159 +        
160 +    /**
161 +     * The components that we already know about
162 +     * connected with the attributes they care about
163 +     * are stored here.
164 +     */
165 +    private HashMap _components = new HashMap();
166  
167 +    /**
168 +     *
169 +     */
170 +    boolean displaySucessful = true;
171 +    /**
172 +     * The east panel, currently used for the heartbeat ticker.
173 +     */
174 +    JPanel _east = new JPanel();
175  
176 < //---ATTRIBUTES---
176 >    /**
177 >     * The centre panel, where all the data is displayed.
178 >     */
179 >    JPanel _center = new JPanel();
180 >    {
181 >        _center.setLayout(new BoxLayout(_center, BoxLayout.Y_AXIS));
182 >    }
183      
184 +    /**
185 +     * The minimum value of the heatbeat progress bar
186 +     */
187      int _min = 0;
188 +    
189 +    /**
190 +     * The maximum value of the heatbeat progress bar
191 +     */
192      int _max = 12;
193 +    
194 +    /**
195 +     * This progress bar indicates time till next heartbeat.
196 +     */
197      JProgressBar _timeToHeartBeat = new JProgressBar(JProgressBar.VERTICAL, _min, _max);
198      {
199          _timeToHeartBeat.setValue(_max);
200      }
201 <    
103 <    HashMap _components = new HashMap();
104 <    JPanel _east = new JPanel();
105 <    JPanel _center = new JPanel();
106 <    {
107 <        _center.setLayout(new BoxLayout(_center, BoxLayout.Y_AXIS));
108 <    }
201 >
202   //---STATIC ATTRIBUTES---
203      
204   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines