KickJava   Java API By Example, From Geeks To Geeks.

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


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

8
9 package com.sleepycat.je.txn;
10
11 import java.util.Set JavaDoc;
12
13 import com.sleepycat.je.DatabaseException;
14 import com.sleepycat.je.LockStats;
15 import com.sleepycat.je.dbi.DatabaseImpl;
16 import com.sleepycat.je.dbi.EnvironmentImpl;
17 import com.sleepycat.je.dbi.MemoryBudget;
18
19 /**
20  * SyncedLockManager uses the synchronized keyword to implement its critical
21  * sections.
22  */

23 public class SyncedLockManager extends LockManager {
24
25     public SyncedLockManager(EnvironmentImpl envImpl)
26         throws DatabaseException {
27
28         super(envImpl);
29     }
30
31     /**
32      * @see LockManager#attemptLock
33      */

34     protected LockAttemptResult attemptLock(Long JavaDoc nodeId,
35                                             Locker locker,
36                                             LockType type,
37                                             boolean nonBlockingRequest)
38         throws DatabaseException {
39         
40     int lockTableIndex = getLockTableIndex(nodeId);
41         synchronized(lockTableLatches[lockTableIndex]) {
42             return attemptLockInternal(nodeId, locker, type,
43                        nonBlockingRequest, lockTableIndex);
44         }
45     }
46         
47     /**
48      * @see LockManager#makeTimeoutMsg
49      */

50     protected String JavaDoc makeTimeoutMsg(String JavaDoc lockOrTxn,
51                                     Locker locker,
52                                     long nodeId,
53                                     LockType type,
54                                     LockGrantType grantType,
55                                     Lock useLock,
56                                     long timeout,
57                                     long start,
58                                     long now,
59                     DatabaseImpl database) {
60
61     int lockTableIndex = getLockTableIndex(nodeId);
62         synchronized(lockTableLatches[lockTableIndex]) {
63             return makeTimeoutMsgInternal(lockOrTxn, locker, nodeId, type,
64                                           grantType, useLock, timeout,
65                                           start, now, database);
66         }
67     }
68
69     /**
70      * @see LockManager#releaseAndNotifyTargets
71      */

72     protected Set JavaDoc releaseAndFindNotifyTargets(long nodeId,
73                                               Lock lock,
74                                               Locker locker,
75                                               boolean removeFromLocker)
76         throws DatabaseException {
77
78     long nid = nodeId;
79     if (nid == -1) {
80         nid = lock.getNodeId().longValue();
81     }
82     int lockTableIndex = getLockTableIndex(nid);
83         synchronized(lockTableLatches[lockTableIndex]) {
84             return releaseAndFindNotifyTargetsInternal
85         (nodeId, lock, locker, removeFromLocker, lockTableIndex);
86         }
87     }
88
89     /**
90      * @see LockManager#transfer
91      */

92     void transfer(long nodeId,
93                   Locker owningLocker,
94                   Locker destLocker,
95                   boolean demoteToRead)
96         throws DatabaseException {
97
98     int lockTableIndex = getLockTableIndex(nodeId);
99         synchronized(lockTableLatches[lockTableIndex]) {
100             transferInternal(nodeId, owningLocker, destLocker,
101                  demoteToRead, lockTableIndex);
102         }
103     }
104
105     /**
106      * @see LockManager#transferMultiple
107      */

108     void transferMultiple(long nodeId,
109                           Locker owningLocker,
110                           Locker[] destLockers)
111         throws DatabaseException {
112
113     int lockTableIndex = getLockTableIndex(nodeId);
114         synchronized(lockTableLatches[lockTableIndex]) {
115             transferMultipleInternal(nodeId, owningLocker,
116                      destLockers, lockTableIndex);
117         }
118     }
119
120     /**
121      * @see LockManager#demote
122      */

123     void demote(long nodeId, Locker locker)
124         throws DatabaseException {
125         
126     int lockTableIndex = getLockTableIndex(nodeId);
127         synchronized(lockTableLatches[lockTableIndex]) {
128             demoteInternal(nodeId, locker, lockTableIndex);
129         }
130     }
131
132     /**
133      * @see LockManager#isLocked
134      */

135     boolean isLocked(Long JavaDoc nodeId) {
136
137     int lockTableIndex = getLockTableIndex(nodeId);
138         synchronized(lockTableLatches[lockTableIndex]) {
139             return isLockedInternal(nodeId, lockTableIndex);
140         }
141     }
142
143     /**
144      * @see LockManager#isOwner
145      */

146     boolean isOwner(Long JavaDoc nodeId, Locker locker, LockType type) {
147
148     int lockTableIndex = getLockTableIndex(nodeId);
149         synchronized(lockTableLatches[lockTableIndex]) {
150             return isOwnerInternal(nodeId, locker, type, lockTableIndex);
151         }
152     }
153
154     /**
155      * @see LockManager#isWaiter
156      */

157     boolean isWaiter(Long JavaDoc nodeId, Locker locker) {
158         
159     int lockTableIndex = getLockTableIndex(nodeId);
160         synchronized(lockTableLatches[lockTableIndex]) {
161             return isWaiterInternal(nodeId, locker, lockTableIndex);
162         }
163     }
164
165     /**
166      * @see LockManager#nWaiters
167      */

168     int nWaiters(Long JavaDoc nodeId) {
169
170     int lockTableIndex = getLockTableIndex(nodeId);
171         synchronized(lockTableLatches[lockTableIndex]) {
172             return nWaitersInternal(nodeId, lockTableIndex);
173         }
174     }
175
176     /**
177      * @see LockManager#nOwners
178      */

179     int nOwners(Long JavaDoc nodeId) {
180
181     int lockTableIndex = getLockTableIndex(nodeId);
182         synchronized(lockTableLatches[lockTableIndex]) {
183             return nOwnersInternal(nodeId, lockTableIndex);
184         }
185     }
186
187     /**
188      * @see LockManager#getWriterOwnerLocker
189      */

190     Locker getWriteOwnerLocker(Long JavaDoc nodeId)
191         throws DatabaseException {
192
193     int lockTableIndex = getLockTableIndex(nodeId);
194         synchronized(lockTableLatches[lockTableIndex]) {
195             return getWriteOwnerLockerInternal(nodeId, lockTableIndex);
196         }
197     }
198
199     /**
200      * @see LockManager#validateOwnership
201      */

202     protected boolean validateOwnership(Long JavaDoc nodeId,
203                                         Locker locker,
204                                         LockType type,
205                                         boolean flushFromWaiters,
206                     MemoryBudget mb)
207         throws DatabaseException {
208
209     int lockTableIndex = getLockTableIndex(nodeId);
210         synchronized(lockTableLatches[lockTableIndex]) {
211             return validateOwnershipInternal
212         (nodeId, locker, type, flushFromWaiters, mb, lockTableIndex);
213         }
214     }
215
216     /**
217      * @see LockManager#dumpLockTable
218      */

219     protected void dumpLockTable(LockStats stats)
220         throws DatabaseException {
221         
222     for (int i = 0; i < nLockTables; i++) {
223         synchronized(lockTableLatches[i]) {
224         dumpLockTableInternal(stats, i);
225         }
226     }
227     }
228 }
229
Popular Tags