KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > monitor > TransactionCanvas


1 //$Id: TransactionCanvas.java,v 1.3 2002/08/27 08:32:26 per_nyfelt Exp $
2

3 package org.ozoneDB.core.monitor;
4
5 import org.ozoneDB.DxLib.*;
6 import org.ozoneDB.core.*;
7
8 import java.awt.*;
9 import java.awt.event.*;
10
11
12 public class TransactionCanvas extends Canvas {
13     static Color createColor = new Color( 255, 150, 80 );
14     static Color readColor = new Color( 176, 196, 222 );
15     static Color writeColor = new Color( 123, 104, 238 );
16
17     private Graphics dbg;
18     private Image dbImage;
19
20
21     /** */
22     public TransactionCanvas() {
23         setBackground( StorageCanvas.bg1Color );
24     }
25
26
27     /** */
28     public void update( Graphics g ) {
29         if (dbImage == null) {
30             /* BUG 0: deprecated function: size() */
31             dbImage = createImage( size().width, size().height );
32             dbg = dbImage.getGraphics();
33         }
34         paint( dbg );
35         g.drawImage( dbImage, 0, 0, this );
36     }
37
38
39     /** */
40     public void paint( Graphics g ) {
41         super.paint( g );
42         Rectangle rect = getBounds();
43
44         g.setColor( StorageCanvas.bg1Color );
45         g.fillRect( 1, 1, rect.width - 2, rect.height - 2 );
46         g.draw3DRect( 1, 1, rect.width - 2, rect.height - 2, true );
47         g.setColor( StorageCanvas.headColor );
48         g.fillRect( 3, 3, rect.width - 5, 13 );
49         g.setColor( Color.white );
50         g.drawString( "Transaction View", 6, 13 );
51
52         int viewHeight = (rect.height - 60) / 3;
53         Rectangle osRect = new Rectangle( 10, rect.height - viewHeight * 3 - 40, rect.width - 20, viewHeight );
54         updateCV( g, osRect );
55         Rectangle csRect = new Rectangle( 10, rect.height - viewHeight * 2 - 25, rect.width - 20, viewHeight );
56         updateBV( g, csRect );
57         Rectangle psRect = new Rectangle( 10, rect.height - viewHeight - 10, rect.width - 20, viewHeight );
58         updateTV( g, psRect );
59     }
60
61
62     /** */
63     public void updateTV( Graphics g, Rectangle r ) {
64         TransactionManager tam = Env.currentEnv().transactionManager;
65
66         g.setColor( StorageCanvas.bgColor );
67         g.fillRect( r.x, r.y + 14, r.width, r.height - 14 );
68         g.draw3DRect( r.x, r.y + 14, r.width, r.height - 14, false );
69
70         /*
71         int read = 0;
72         int write = 0;
73         int create = 0;
74         int viewW = r.width / 4;
75         DxIterator it = tam.taTable.iterator();
76         for (int i = 0; i < 4; i++) {
77             if (i > 0) {
78                 g.setColor( StorageCanvas.bgColor );
79                 g.draw3DRect( r.x + viewW * i - 1, r.y + 14, 1, r.height - 14, true );
80             }
81             Transaction ta = (Transaction)it.next();
82             if (ta != null && ta.createTable != null) {
83                 Rectangle taRect = new Rectangle( r.x + viewW * i + 1, r.y + 14 + 1, viewW, r.height - 14 - 1 );
84                 updateTA( g, taRect, ta );
85
86                 create += ta.createTable.count();
87                 read += ta.readTable.count();
88                 write += ta.writeTable.count();
89             }
90         }
91
92         g.setColor( StorageCanvas.fontColor );
93         String label =
94                 "Object access - " + new Integer( tam.taTable.count() ).toString() + " transactions [ " + new Integer(
95                 create ).toString() + " / " + new Integer( read ).toString() + " / " + new Integer( write ).toString()
96                 + " ]";
97         g.drawString( label, r.x, r.y + 12 );
98         */

99     }
100
101
102     /** */
103     public void updateTA( Graphics g, Rectangle r, Transaction ta ) {
104         /*
105         int max = ta.createTable.count();
106         max = Math.max( max, ta.readTable.count() );
107         max = Math.max( max, ta.writeTable.count() );
108
109         int scale = 1;
110         while (max / scale > r.height) {
111             scale++;
112         }
113
114         int bw = r.width / 3;
115         int bh = ta.createTable.count() / scale;
116         g.setColor( createColor );
117         g.fillRect( r.x, r.y + r.height - bh, bw, bh );
118         bh = ta.readTable.count() / scale;
119         g.setColor( readColor );
120         g.fillRect( r.x + bw, r.y + r.height - bh, bw, bh );
121         bh = ta.writeTable.count() / scale;
122         g.setColor( writeColor );
123         g.fillRect( r.x + bw * 2, r.y + r.height - bh, bw, bh );
124         */

125     }
126
127
128     /** */
129     public void updateBV( Graphics g, Rectangle r ) {
130         TransactionManager tam = Env.currentEnv().transactionManager;
131
132         g.setColor( StorageCanvas.bgColor );
133         g.fillRect( r.x, r.y + 14, r.width, r.height - 14 );
134         g.draw3DRect( r.x, r.y + 14, r.width, r.height - 14, false );
135         g.setColor( StorageCanvas.fontColor );
136         String JavaDoc label = "Blocking";
137         g.drawString( label, r.x, r.y + 12 );
138
139         int y = r.y + 14 + 14;
140         int x = r.x + 5;
141         g.setColor( StorageCanvas.fontColor );
142         /*
143         if (tam.taTable.isEmpty()) {
144             g.drawString( "No transactions.", x, y );
145         } else {
146             boolean somethingBlocked = false;
147             DxIterator it = tam.taTable.iterator();
148             Transaction ta;
149             while ((ta = (Transaction)it.next()) != null) {
150                 if (ta.blocker != null) {
151                     somethingBlocked = true;
152                     Transaction blocker = Env.currentEnv().objectSpace.objectForID( ta.blocker ).writeLocker;
153                     g.drawString( new Short( (short)ta.taID.hashCode() ).toString() + " blocked by " + new Short(
154                             (short)blocker.taID.hashCode() ).toString(), x, y );
155                     y += 14;
156                 }
157             }
158             if (!somethingBlocked) {
159                 g.drawString( "No transaction blocked.", x, y );
160             }
161         }
162         */

163     }
164
165
166     /** */
167     public void updateCV( Graphics g, Rectangle r ) {
168         TransactionManager tam = Env.currentEnv().transactionManager;
169
170         g.setColor( StorageCanvas.bgColor );
171         g.fillRect( r.x, r.y + 14, r.width, r.height - 14 );
172         g.draw3DRect( r.x, r.y + 14, r.width, r.height - 14, false );
173         g.setColor( StorageCanvas.fontColor );
174         String JavaDoc label = "Clients - ";
175         g.drawString( label, r.x, r.y + 12 );
176     }
177 }
178
Popular Tags