KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > txn > LockInfo


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

8
9 package com.sleepycat.je.txn;
10
11 import java.util.Collections JavaDoc;
12 import java.util.Map JavaDoc;
13 import java.util.WeakHashMap JavaDoc;
14
15 import com.sleepycat.je.utilint.Tracer;
16
17 /**
18  * LockInfo is a class that embodies information about a lock instance. The
19  * holding thread and the locktype are all contained in the object.
20  */

21 public class LockInfo implements Cloneable JavaDoc {
22     private Locker locker;
23     private LockType lockType;
24
25     private static boolean deadlockStackTrace = false;
26     private static Map JavaDoc traceExceptionMap =
27         Collections.synchronizedMap(new WeakHashMap JavaDoc());
28     private static class StackTraceAtLockTime extends Exception JavaDoc {}
29
30     /**
31      * Called when the je.txn.deadlockStackTrace property is changed.
32      */

33     static void setDeadlockStackTrace(boolean enable) {
34         deadlockStackTrace = enable;
35     }
36
37     /**
38      * For unit testing only.
39      */

40     public static boolean getDeadlockStackTrace() {
41         return deadlockStackTrace;
42     }
43
44     /**
45      * Construct a new LockInfo. public for Sizeof program.
46      */

47     public LockInfo(Locker locker, LockType lockType) {
48     this.locker = locker;
49     this.lockType = lockType;
50
51         if (deadlockStackTrace) {
52             traceExceptionMap.put(this, new StackTraceAtLockTime());
53         }
54     }
55
56     /**
57      * Change this lockInfo over to the prescribed locker.
58      */

59     void setLocker(Locker locker) {
60     this.locker = locker;
61     }
62
63     /**
64      * @return The transaction associated with this Lock.
65      */

66     Locker getLocker() {
67     return locker;
68     }
69
70     /**
71      * @return The LockType associated with this Lock.
72      */

73     void setLockType(LockType lockType) {
74     this.lockType = lockType;
75     }
76
77     /**
78      * @return The LockType associated with this Lock.
79      */

80     LockType getLockType() {
81     return lockType;
82     }
83
84     public Object JavaDoc clone()
85         throws CloneNotSupportedException JavaDoc {
86
87         return super.clone();
88     }
89
90     /**
91      * Debugging
92      */

93     public void dump() {
94     System.out.println(this);
95     }
96
97     public String JavaDoc toString() {
98         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(500);
99
100         buf.append("<LockInfo locker=\"");
101         buf.append(locker);
102         buf.append("\" type=\"");
103         buf.append(lockType);
104         buf.append("\"/>");
105
106         if (deadlockStackTrace) {
107             Exception JavaDoc traceException = (Exception JavaDoc) traceExceptionMap.get(this);
108             if (traceException != null) {
109                 buf.append(" lock taken at: ");
110                 buf.append(Tracer.getStackTrace(traceException));
111             }
112         }
113
114         return buf.toString();
115     }
116 }
117
Popular Tags