001: //$Id: TransactionCanvas.java,v 1.2 2002/07/29 11:30:23 per_nyfelt Exp $
002:
003: package org.ozoneDB.core.monitor;
004:
005: import org.ozoneDB.DxLib.*;
006: import org.ozoneDB.core.*;
007:
008: import java.awt.*;
009: import java.awt.event.*;
010:
011: public class TransactionCanvas extends Canvas {
012: static Color createColor = new Color(255, 150, 80);
013: static Color readColor = new Color(176, 196, 222);
014: static Color writeColor = new Color(123, 104, 238);
015:
016: private Graphics dbg;
017: private Image dbImage;
018:
019: /** */
020: public TransactionCanvas() {
021: setBackground(StorageCanvas.bg1Color);
022: }
023:
024: /** */
025: public void update(Graphics g) {
026: if (dbImage == null) {
027: /* BUG 0: deprecated function: size() */
028: dbImage = createImage(size().width, size().height);
029: dbg = dbImage.getGraphics();
030: }
031: paint(dbg);
032: g.drawImage(dbImage, 0, 0, this );
033: }
034:
035: /** */
036: public void paint(Graphics g) {
037: super .paint(g);
038: Rectangle rect = getBounds();
039:
040: g.setColor(StorageCanvas.bg1Color);
041: g.fillRect(1, 1, rect.width - 2, rect.height - 2);
042: g.draw3DRect(1, 1, rect.width - 2, rect.height - 2, true);
043: g.setColor(StorageCanvas.headColor);
044: g.fillRect(3, 3, rect.width - 5, 13);
045: g.setColor(Color.white);
046: g.drawString("Transaction View", 6, 13);
047:
048: int viewHeight = (rect.height - 60) / 3;
049: Rectangle osRect = new Rectangle(10, rect.height - viewHeight
050: * 3 - 40, rect.width - 20, viewHeight);
051: updateCV(g, osRect);
052: Rectangle csRect = new Rectangle(10, rect.height - viewHeight
053: * 2 - 25, rect.width - 20, viewHeight);
054: updateBV(g, csRect);
055: Rectangle psRect = new Rectangle(10, rect.height - viewHeight
056: - 10, rect.width - 20, viewHeight);
057: updateTV(g, psRect);
058: }
059:
060: /** */
061: public void updateTV(Graphics g, Rectangle r) {
062: TransactionManager tam = Env.currentEnv().transactionManager;
063:
064: g.setColor(StorageCanvas.bgColor);
065: g.fillRect(r.x, r.y + 14, r.width, r.height - 14);
066: g.draw3DRect(r.x, r.y + 14, r.width, r.height - 14, false);
067:
068: /*
069: int read = 0;
070: int write = 0;
071: int create = 0;
072: int viewW = r.width / 4;
073: DxIterator it = tam.taTable.iterator();
074: for (int i = 0; i < 4; i++) {
075: if (i > 0) {
076: g.setColor( StorageCanvas.bgColor );
077: g.draw3DRect( r.x + viewW * i - 1, r.y + 14, 1, r.height - 14, true );
078: }
079: Transaction ta = (Transaction)it.next();
080: if (ta != null && ta.createTable != null) {
081: Rectangle taRect = new Rectangle( r.x + viewW * i + 1, r.y + 14 + 1, viewW, r.height - 14 - 1 );
082: updateTA( g, taRect, ta );
083:
084: create += ta.createTable.count();
085: read += ta.readTable.count();
086: write += ta.writeTable.count();
087: }
088: }
089:
090: g.setColor( StorageCanvas.fontColor );
091: String label =
092: "Object access - " + new Integer( tam.taTable.count() ).toString() + " transactions [ " + new Integer(
093: create ).toString() + " / " + new Integer( read ).toString() + " / " + new Integer( write ).toString()
094: + " ]";
095: g.drawString( label, r.x, r.y + 12 );
096: */
097: }
098:
099: /** */
100: public void updateTA(Graphics g, Rectangle r, Transaction ta) {
101: /*
102: int max = ta.createTable.count();
103: max = Math.max( max, ta.readTable.count() );
104: max = Math.max( max, ta.writeTable.count() );
105:
106: int scale = 1;
107: while (max / scale > r.height) {
108: scale++;
109: }
110:
111: int bw = r.width / 3;
112: int bh = ta.createTable.count() / scale;
113: g.setColor( createColor );
114: g.fillRect( r.x, r.y + r.height - bh, bw, bh );
115: bh = ta.readTable.count() / scale;
116: g.setColor( readColor );
117: g.fillRect( r.x + bw, r.y + r.height - bh, bw, bh );
118: bh = ta.writeTable.count() / scale;
119: g.setColor( writeColor );
120: g.fillRect( r.x + bw * 2, r.y + r.height - bh, bw, bh );
121: */
122: }
123:
124: /** */
125: public void updateBV(Graphics g, Rectangle r) {
126: TransactionManager tam = Env.currentEnv().transactionManager;
127:
128: g.setColor(StorageCanvas.bgColor);
129: g.fillRect(r.x, r.y + 14, r.width, r.height - 14);
130: g.draw3DRect(r.x, r.y + 14, r.width, r.height - 14, false);
131: g.setColor(StorageCanvas.fontColor);
132: String label = "Blocking";
133: g.drawString(label, r.x, r.y + 12);
134:
135: int y = r.y + 14 + 14;
136: int x = r.x + 5;
137: g.setColor(StorageCanvas.fontColor);
138: /*
139: if (tam.taTable.isEmpty()) {
140: g.drawString( "No transactions.", x, y );
141: } else {
142: boolean somethingBlocked = false;
143: DxIterator it = tam.taTable.iterator();
144: Transaction ta;
145: while ((ta = (Transaction)it.next()) != null) {
146: if (ta.blocker != null) {
147: somethingBlocked = true;
148: Transaction blocker = Env.currentEnv().objectSpace.objectForID( ta.blocker ).writeLocker;
149: g.drawString( new Short( (short)ta.taID.hashCode() ).toString() + " blocked by " + new Short(
150: (short)blocker.taID.hashCode() ).toString(), x, y );
151: y += 14;
152: }
153: }
154: if (!somethingBlocked) {
155: g.drawString( "No transaction blocked.", x, y );
156: }
157: }
158: */
159: }
160:
161: /** */
162: public void updateCV(Graphics g, Rectangle r) {
163: TransactionManager tam = Env.currentEnv().transactionManager;
164:
165: g.setColor(StorageCanvas.bgColor);
166: g.fillRect(r.x, r.y + 14, r.width, r.height - 14);
167: g.draw3DRect(r.x, r.y + 14, r.width, r.height - 14, false);
168: g.setColor(StorageCanvas.fontColor);
169: String label = "Clients - ";
170: g.drawString(label, r.x, r.y + 12);
171: }
172: }
|