Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/tools/dash/DashBoard.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children | 28c84687bdb8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.tools.dash; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.HashMap; | |
5 import java.util.Map; | |
6 | |
7 import javax.swing.JFrame; | |
8 | |
9 import java.awt.Rectangle; | |
10 | |
11 import org.dancres.blitz.remote.StatsAdmin; | |
12 import org.dancres.blitz.stats.InstanceCount; | |
13 import org.dancres.blitz.stats.MemoryStat; | |
14 import org.dancres.blitz.stats.OpStat; | |
15 import org.dancres.blitz.stats.Stat; | |
16 import org.dancres.blitz.stats.TxnStat; | |
17 import org.dancres.blitz.stats.BlockingOpsStat; | |
18 | |
19 public class DashBoard extends javax.swing.JPanel { | |
20 | |
21 | |
22 /** Creates new form DashBoard */ | |
23 public DashBoard(JFrame frame) { | |
24 parent=frame; | |
25 initComponents(); | |
26 memoryBar.setMaximum(100); | |
27 | |
28 } | |
29 | |
30 /** This method is called from within the constructor to | |
31 * initialize the form. | |
32 * WARNING: Do NOT modify this code. The content of this method is | |
33 * always regenerated by the Form Editor. | |
34 */ | |
35 private void initComponents() {//GEN-BEGIN:initComponents | |
36 blockingTakeLb = new javax.swing.JLabel(); | |
37 blockingTakeCount = new javax.swing.JLabel(); | |
38 blockingReadLb = new javax.swing.JLabel(); | |
39 blockingReadCount = new javax.swing.JLabel(); | |
40 blockingOpButton = new javax.swing.JButton(); | |
41 takeCountLb = new javax.swing.JLabel(); | |
42 writeCountLb = new javax.swing.JLabel(); | |
43 readCountLb = new javax.swing.JLabel(); | |
44 instanceCount = new javax.swing.JLabel(); | |
45 txnCount = new javax.swing.JLabel(); | |
46 memoryCount = new javax.swing.JLabel(); | |
47 memoryBar = new javax.swing.JProgressBar(); | |
48 txnButton = new javax.swing.JButton(); | |
49 spaceOpButton = new javax.swing.JButton(); | |
50 instancesButton = new javax.swing.JButton(); | |
51 memoryButton = new javax.swing.JButton(); | |
52 takeCount = new javax.swing.JLabel(); | |
53 writeCount = new javax.swing.JLabel(); | |
54 readCount = new javax.swing.JLabel(); | |
55 | |
56 setLayout(null); | |
57 | |
58 takeCountLb.setText("Take:"); | |
59 add(takeCountLb); | |
60 takeCountLb.setBounds(160, 40, 40, 15); | |
61 | |
62 writeCountLb.setText("Write:"); | |
63 add(writeCountLb); | |
64 writeCountLb.setBounds(160, 60, 40, 15); | |
65 | |
66 readCountLb.setText("Read:"); | |
67 add(readCountLb); | |
68 readCountLb.setBounds(160, 80, 40, 15); | |
69 | |
70 blockingReadLb.setText("Read:"); | |
71 add(blockingReadLb); | |
72 blockingReadLb.setBounds(300, 40, 40, 15); | |
73 | |
74 blockingTakeLb.setText("Take:"); | |
75 add(blockingTakeLb); | |
76 blockingTakeLb.setBounds(300, 60, 40, 15); | |
77 | |
78 instanceCount.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); | |
79 instanceCount.setText("0"); | |
80 add(instanceCount); | |
81 instanceCount.setBounds(440, 40, 130, 15); | |
82 | |
83 txnCount.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); | |
84 txnCount.setText("0"); | |
85 add(txnCount); | |
86 txnCount.setBounds(20, 40, 130, 15); | |
87 | |
88 memoryCount.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); | |
89 memoryCount.setText("0"); | |
90 add(memoryCount); | |
91 memoryCount.setBounds(580, 40, 140, 15); | |
92 | |
93 add(memoryBar); | |
94 memoryBar.setBounds(580, 60, 140, 20); | |
95 | |
96 txnButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/txns.gif"))); | |
97 txnButton.setText("Active Txns"); | |
98 txnButton.addActionListener(new java.awt.event.ActionListener() { | |
99 public void actionPerformed(java.awt.event.ActionEvent evt) { | |
100 txnButtonActionPerformed(evt); | |
101 } | |
102 }); | |
103 | |
104 add(txnButton); | |
105 txnButton.setBounds(10, 10, 130, 26); | |
106 | |
107 spaceOpButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/ops.gif"))); | |
108 spaceOpButton.setText("Space Ops"); | |
109 spaceOpButton.addActionListener(new java.awt.event.ActionListener() { | |
110 public void actionPerformed(java.awt.event.ActionEvent evt) { | |
111 spaceOpButtonActionPerformed(evt); | |
112 } | |
113 }); | |
114 | |
115 add(spaceOpButton); | |
116 spaceOpButton.setBounds(150, 10, 130, 26); | |
117 | |
118 blockingOpButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/blocking.gif"))); | |
119 blockingOpButton.setText("Blocking"); | |
120 blockingOpButton.addActionListener(new java.awt.event.ActionListener() { | |
121 public void actionPerformed(java.awt.event.ActionEvent evt) { | |
122 blockingButtonActionPerformed(evt); | |
123 } | |
124 }); | |
125 | |
126 add(blockingOpButton); | |
127 blockingOpButton.setBounds(290, 10, 130, 26); | |
128 | |
129 instancesButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/instances.gif"))); | |
130 instancesButton.setText("Instances"); | |
131 instancesButton.addActionListener(new java.awt.event.ActionListener() { | |
132 public void actionPerformed(java.awt.event.ActionEvent evt) { | |
133 instancesButtonActionPerformed(evt); | |
134 } | |
135 }); | |
136 | |
137 add(instancesButton); | |
138 instancesButton.setBounds(430, 10, 140, 26); | |
139 | |
140 memoryButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/memory.gif"))); | |
141 memoryButton.setText("Memory"); | |
142 memoryButton.addActionListener(new java.awt.event.ActionListener() { | |
143 public void actionPerformed(java.awt.event.ActionEvent evt) { | |
144 memoryButtonActionPerformed(evt); | |
145 } | |
146 }); | |
147 | |
148 add(memoryButton); | |
149 memoryButton.setBounds(580, 10, 140, 26); | |
150 | |
151 takeCount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
152 takeCount.setText("0"); | |
153 add(takeCount); | |
154 takeCount.setBounds(200, 40, 80, 15); | |
155 | |
156 writeCount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
157 writeCount.setText("0"); | |
158 add(writeCount); | |
159 writeCount.setBounds(200, 60, 80, 15); | |
160 | |
161 readCount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
162 readCount.setText("0"); | |
163 add(readCount); | |
164 readCount.setBounds(200, 80, 80, 15); | |
165 | |
166 blockingReadCount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
167 blockingReadCount.setText("0"); | |
168 add(blockingReadCount); | |
169 blockingReadCount.setBounds(340, 40, 80, 15); | |
170 | |
171 blockingTakeCount.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
172 blockingTakeCount.setText("0"); | |
173 add(blockingTakeCount); | |
174 blockingTakeCount.setBounds(340, 60, 80, 15); | |
175 | |
176 }//GEN-END:initComponents | |
177 private Rectangle getNextWinBounds(){ | |
178 int windowCount=_openWindows.size()-1; | |
179 Rectangle dashBounds=parent.getBounds(); | |
180 return new Rectangle(dashBounds.x+(windowCount*25),dashBounds.y+dashBounds.height+(windowCount*25),400,300); | |
181 | |
182 } | |
183 private void blockingButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_blockingButtonActionPerformed | |
184 // Add your handling code here: | |
185 //JOptionPane.showMessageDialog(this,"Not implemented yet!"); | |
186 StatsFrame statsFrame=new StatsFrame(parent,"Blocking",StatsFrame.BLOCKERS); | |
187 _openWindows.add(statsFrame); | |
188 statsFrame.setBounds(getNextWinBounds()); | |
189 statsFrame.setVisible(true); | |
190 }//GEN-LAST:event_memoryButtonActionPerformed | |
191 | |
192 private void memoryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_memoryButtonActionPerformed | |
193 // Add your handling code here: | |
194 //JOptionPane.showMessageDialog(this,"Not implemented yet!"); | |
195 StatsFrame statsFrame=new StatsFrame(parent,"Memory usage",StatsFrame.MEMORY); | |
196 _openWindows.add(statsFrame); | |
197 statsFrame.setBounds(getNextWinBounds()); | |
198 statsFrame.setVisible(true); | |
199 }//GEN-LAST:event_memoryButtonActionPerformed | |
200 | |
201 private void instancesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_instancesButtonActionPerformed | |
202 // Add your handling code here: | |
203 //JOptionPane.showMessageDialog(this,"Not implemented yet!"); | |
204 StatsFrame statsFrame=new StatsFrame(parent,"Entry Instances",StatsFrame.INSTANCES,statsAdmin); | |
205 _openWindows.add(statsFrame); | |
206 statsFrame.setBounds(getNextWinBounds()); | |
207 statsFrame.setVisible(true); | |
208 }//GEN-LAST:event_instancesButtonActionPerformed | |
209 | |
210 private void spaceOpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spaceOpButtonActionPerformed | |
211 // Add your handling code here: | |
212 StatsFrame statsFrame=new StatsFrame(parent,"Read/write/takes",StatsFrame.OPSTATS); | |
213 _openWindows.add(statsFrame); | |
214 statsFrame.setBounds(getNextWinBounds()); | |
215 statsFrame.setVisible(true); | |
216 }//GEN-LAST:event_spaceOpButtonActionPerformed | |
217 | |
218 private void txnButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txnButtonActionPerformed | |
219 // Add your handling code here: | |
220 StatsFrame statsFrame=new StatsFrame(parent,"Active Txns",StatsFrame.TXNS); | |
221 _openWindows.add(statsFrame); | |
222 statsFrame.setBounds(getNextWinBounds()); | |
223 statsFrame.setVisible(true); | |
224 }//GEN-LAST:event_txnButtonActionPerformed | |
225 | |
226 | |
227 // Variables declaration - do not modify//GEN-BEGIN:variables | |
228 private javax.swing.JLabel blockingTakeLb; | |
229 private javax.swing.JLabel blockingTakeCount; | |
230 private javax.swing.JLabel blockingReadLb; | |
231 private javax.swing.JLabel blockingReadCount; | |
232 private javax.swing.JButton blockingOpButton; | |
233 private javax.swing.JLabel instanceCount; | |
234 private javax.swing.JButton instancesButton; | |
235 private javax.swing.JProgressBar memoryBar; | |
236 private javax.swing.JButton memoryButton; | |
237 private javax.swing.JLabel memoryCount; | |
238 private javax.swing.JLabel readCount; | |
239 private javax.swing.JLabel readCountLb; | |
240 private javax.swing.JButton spaceOpButton; | |
241 private javax.swing.JLabel takeCount; | |
242 private javax.swing.JLabel takeCountLb; | |
243 private javax.swing.JButton txnButton; | |
244 private javax.swing.JLabel txnCount; | |
245 private javax.swing.JLabel writeCount; | |
246 private javax.swing.JLabel writeCountLb; | |
247 // End of variables declaration//GEN-END:variables | |
248 | |
249 //blitz specific stuff | |
250 //private Object [] data; | |
251 private StatsAdmin statsAdmin; | |
252 private Map lookup; | |
253 private ArrayList _openWindows=new ArrayList(); | |
254 private JFrame parent; | |
255 | |
256 void init(StatsAdmin admin){ | |
257 statsAdmin=admin; | |
258 } | |
259 private void updateWindows(Stat [] stats){ | |
260 | |
261 ArrayList deathRow=new ArrayList(); | |
262 | |
263 int n=_openWindows.size(); | |
264 for(int i=0;i<n;i++){ | |
265 UpdateableView win=(UpdateableView)_openWindows.get(i); | |
266 boolean active=win.update(stats); | |
267 if(!active){ | |
268 deathRow.add(win); | |
269 } | |
270 } | |
271 //execute the prisoners | |
272 n=deathRow.size(); | |
273 for(int i=0;i<n;i++){ | |
274 _openWindows.remove(deathRow.get(i)); | |
275 } | |
276 } | |
277 void update(Stat[] stats){ | |
278 | |
279 updateWindows(stats); | |
280 | |
281 lookup=new HashMap(); | |
282 | |
283 long readCounter=0; | |
284 long writeCounter=0; | |
285 long takeCounter=0; | |
286 long instanceCounter=0; | |
287 | |
288 for(int i=0;i<stats.length;i++){ | |
289 | |
290 if(stats[i] instanceof MemoryStat){ | |
291 MemoryStat ms=(MemoryStat)stats[i]; | |
292 double max=ms.getMaxMemory(); | |
293 double used=ms.getCurrentMemory(); | |
294 | |
295 double pc=used/max*100; | |
296 double maxKB=max/(1024); | |
297 double usedKB=used/(1024); | |
298 | |
299 memoryCount.setText(""+(int)usedKB+"/"+(int)maxKB+" Kb"); | |
300 memoryBar.setValue((int)pc); | |
301 | |
302 | |
303 }else if(stats[i] instanceof OpStat){ | |
304 OpStat op=(OpStat)stats[i]; | |
305 String type=op.getType(); | |
306 int theOp=op.getOp(); | |
307 Long count=new Long(op.getCount()); | |
308 | |
309 Object [] data=getData(type); | |
310 | |
311 data[0]=type; | |
312 | |
313 switch(theOp){ | |
314 | |
315 case OpStat.READS : data[2]=count; | |
316 readCounter+=count.longValue(); | |
317 break; | |
318 case OpStat.WRITES :data[3]=count; | |
319 writeCounter+=count.longValue(); | |
320 break; | |
321 case OpStat.TAKES : data[4]=count; | |
322 takeCounter+=count.longValue(); | |
323 break; | |
324 } | |
325 //data[1]=new Long( ((Long)data[3]).longValue()-((Long)data[3]).longValue()); | |
326 }else if (stats[i] instanceof InstanceCount) { | |
327 InstanceCount myCount = (InstanceCount) stats[i]; | |
328 String type=myCount.getType(); | |
329 Object [] data=getData(type); | |
330 data[0]=type; | |
331 data[1]=new Integer(myCount.getCount()); | |
332 instanceCounter+=myCount.getCount(); | |
333 | |
334 }else if (stats[i] instanceof TxnStat) { | |
335 TxnStat myTxns = (TxnStat) stats[i]; | |
336 txnCount.setText(""+myTxns.getActiveTxnCount()); | |
337 | |
338 }else if (stats[i] instanceof BlockingOpsStat) { | |
339 BlockingOpsStat myBlockers = (BlockingOpsStat) stats[i]; | |
340 blockingReadCount.setText(""+myBlockers.getReaders()); | |
341 blockingTakeCount.setText(""+myBlockers.getTakers()); | |
342 | |
343 } | |
344 | |
345 } | |
346 readCount.setText(""+readCounter); | |
347 writeCount.setText(""+writeCounter); | |
348 takeCount.setText(""+takeCounter); | |
349 instanceCount.setText(""+instanceCounter); | |
350 } | |
351 private Object [] getData(String type){ | |
352 Object [] data=(Object[])lookup.get(type); | |
353 if(data==null){ | |
354 data=new Object[]{"",new Long(0),new Long(0),new Long(0),new Long(0)}; | |
355 lookup.put(type,data); | |
356 } | |
357 return data; | |
358 } | |
359 | |
360 } |