KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > utilint > EventTrace


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: EventTrace.java,v 1.11 2006/10/30 21:14:28 bostic Exp $
7  */

8
9 package com.sleepycat.je.utilint;
10
11
12 /**
13  * Internal class used for transient event tracing. Subclass this with
14  * specific events. Subclasses should have toString methods for display and
15  * events should be added by calling EventTrace.addEvent();
16  */

17 public class EventTrace {
18     static private int MAX_EVENTS = 100;
19
20     static public final boolean TRACE_EVENTS = false;
21
22     static int currentEvent = 0;
23
24     static final EventTrace[] events = new EventTrace[MAX_EVENTS];
25     static final int[] threadIdHashes = new int[MAX_EVENTS];
26     static boolean disableEvents = false;
27
28     protected String JavaDoc comment;
29
30     public EventTrace(String JavaDoc comment) {
31     this.comment = comment;
32     }
33
34     public EventTrace() {
35     comment = null;
36     }
37
38     public String JavaDoc toString() {
39     return comment;
40     }
41
42     static public void addEvent(EventTrace event) {
43     if (disableEvents) {
44         return;
45     }
46     int nextEventIdx = currentEvent++ % MAX_EVENTS;
47     events[nextEventIdx] = event;
48     threadIdHashes[nextEventIdx] =
49         System.identityHashCode(Thread.currentThread());
50     }
51
52     static public void addEvent(String JavaDoc comment) {
53     if (disableEvents) {
54         return;
55     }
56     addEvent(new EventTrace(comment));
57     }
58
59     static public void dumpEvents() {
60     if (disableEvents) {
61         return;
62     }
63     System.out.println("----- Event Dump -----");
64     EventTrace[] oldEvents = events;
65     int[] oldThreadIdHashes = threadIdHashes;
66     disableEvents = true;
67
68     int j = 0;
69     for (int i = currentEvent; j < MAX_EVENTS; i++) {
70         EventTrace ev = oldEvents[i % MAX_EVENTS];
71         if (ev != null) {
72         int thisEventIdx = i % MAX_EVENTS;
73         System.out.print(oldThreadIdHashes[thisEventIdx] + " ");
74         System.out.println(j + "(" + thisEventIdx + "): " + ev);
75         }
76         j++;
77     }
78     }
79
80     static public class ExceptionEventTrace extends EventTrace {
81     private Exception JavaDoc event;
82
83     public ExceptionEventTrace() {
84             event = new Exception JavaDoc();
85     }
86
87     public String JavaDoc toString() {
88             return Tracer.getStackTrace(event);
89     }
90     }
91 }
92
93     /*
94     static public class EvictEvent extends EventTrace {
95     long nodeId;
96     int addr;
97
98     public EvictEvent(String comment, long nodeId, int addr) {
99         super(comment);
100         this.nodeId = nodeId;
101         this.addr = addr;
102     }
103
104     static public void addEvent(String comment, IN node) {
105         long nodeId = node.getNodeId();
106         int addr = System.identityHashCode(node);
107         EventTrace.addEvent(new EvictEvent(comment, nodeId, addr));
108     }
109
110     public String toString() {
111         StringBuffer sb = new StringBuffer(comment);
112         sb.append(" IN: ").append(nodeId);
113         sb.append(" sIH ").append(addr);
114         return sb.toString();
115     }
116     }
117
118     static public class CursorTrace extends EventTrace {
119     long nodeId;
120     int index;
121
122     public CursorTrace(String comment, long nodeId, int index) {
123         super(comment);
124         this.nodeId = nodeId;
125         this.index = index;
126     }
127
128     static public void addEvent(String comment, CursorImpl cursor) {
129         long nodeId =
130         (cursor.getBIN() == null) ? -1 : cursor.getBIN().getNodeId();
131         EventTrace.addEvent
132         (new CursorTrace(comment, nodeId, cursor.getIndex()));
133     }
134
135     public String toString() {
136         StringBuffer sb = new StringBuffer(comment);
137         sb.append(" BIN: ").append(nodeId);
138         sb.append(" idx: ").append(index);
139         return sb.toString();
140     }
141     }
142     */

143
144
145 /*
146     class CursorEventTrace extends EventTrace {
147     private String comment;
148     private Node node1;
149     private Node node2;
150
151     CursorEventTrace(String comment, Node node1, Node node2) {
152         this.comment = comment;
153         this.node1 = node1;
154         this.node2 = node2;
155     }
156
157     public String toString() {
158         StringBuffer sb = new StringBuffer(comment);
159         if (node1 != null) {
160         sb.append(" ");
161         sb.append(node1.getNodeId());
162         }
163         if (node2 != null) {
164         sb.append(" ");
165         sb.append(node2.getNodeId());
166         }
167         return sb.toString();
168     }
169     }
170
171 */

172 /*
173
174     static class UndoEventTrace extends EventTrace {
175     private String comment;
176     private boolean success;
177     private Node node;
178     private DbLsn logLsn;
179     private Node parent;
180     private boolean found;
181     private boolean replaced;
182     private boolean inserted;
183     private DbLsn replacedLsn;
184     private DbLsn abortLsn;
185     private int index;
186
187     UndoEventTrace(String comment) {
188         this.comment = comment;
189     }
190
191     UndoEventTrace(boolean success,
192                Node node,
193                DbLsn logLsn,
194                Node parent,
195                boolean found,
196                boolean replaced,
197                boolean inserted,
198                DbLsn replacedLsn,
199                DbLsn abortLsn,
200                int index) {
201         this.comment = null;
202         this.success = success;
203         this.node = node;
204         this.logLsn = logLsn;
205         this.parent = parent;
206         this.found = found;
207         this.replaced = replaced;
208         this.inserted = inserted;
209         this.replacedLsn = replacedLsn;
210         this.abortLsn = abortLsn;
211         this.index = index;
212     }
213
214     public String toString() {
215         if (comment != null) {
216         return comment;
217         }
218         StringBuffer sb = new StringBuffer();
219             sb.append(" success=").append(success);
220             sb.append(" node=");
221             sb.append(node.getNodeId());
222             sb.append(" logLsn=");
223             sb.append(logLsn.getNoFormatString());
224             if (parent != null) {
225                 sb.append(" parent=").append(parent.getNodeId());
226             }
227             sb.append(" found=");
228             sb.append(found);
229             sb.append(" replaced=");
230             sb.append(replaced);
231             sb.append(" inserted=");
232             sb.append(inserted);
233             if (replacedLsn != null) {
234                 sb.append(" replacedLsn=");
235                 sb.append(replacedLsn.getNoFormatString());
236             }
237             if (abortLsn != null) {
238                 sb.append(" abortLsn=");
239                 sb.append(abortLsn.getNoFormatString());
240             }
241             sb.append(" index=").append(index);
242         return sb.toString();
243     }
244     }
245  */

246 /*
247     class CursorAdjustEventTrace extends EventTrace {
248     private int insertIndex;
249     private int cursorIndex;
250     private long nodeid;
251
252     CursorAdjustEventTrace(int insertIndex, int cursorIndex) {
253         this.insertIndex = insertIndex;
254         this.cursorIndex = cursorIndex;
255         this.nodeid = getNodeId();
256     }
257
258     public String toString() {
259         StringBuffer sb = new StringBuffer("cursor adjust ");
260         sb.append(insertIndex).append(" ");
261         sb.append(cursorIndex).append(" ");
262         sb.append(nodeid);
263         return sb.toString();
264     }
265     }
266
267 */

268 /*
269     class CompressEventTrace extends EventTrace {
270     private int entryIndex;
271     private long nodeid;
272
273     CompressEventTrace(int entryIndex) {
274         this.entryIndex = entryIndex;
275         this.nodeid = getNodeId();
276     }
277
278     public String toString() {
279         StringBuffer sb = new StringBuffer("bin compress ");
280         sb.append(entryIndex).append(" ");
281         sb.append(nodeid);
282         return sb.toString();
283     }
284     }
285
286 */

287 /*
288     class TreeEventTrace extends EventTrace {
289     private String comment;
290     private Node node1;
291     private Node node2;
292
293     TreeEventTrace(String comment, Node node1, Node node2) {
294         this.comment = comment;
295         this.node1 = node1;
296         this.node2 = node2;
297     }
298
299     public String toString() {
300         StringBuffer sb = new StringBuffer(comment);
301         if (node1 != null) {
302         sb.append(" ");
303         sb.append(node1.getNodeId());
304         }
305         if (node2 != null) {
306         sb.append(" ");
307         sb.append(node2.getNodeId());
308         }
309         return sb.toString();
310     }
311     }
312
313 */

314
315
316
Popular Tags