Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/txnlock/LockMgr.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.txnlock; | |
2 | |
3 import org.dancres.blitz.oid.OID; | |
4 | |
5 /** | |
6 A lock mgr instance is responsible for tracking all transaction locks | |
7 for a particular Entry type. | |
8 */ | |
9 public class LockMgr { | |
10 /** | |
11 For as long as any transaction has a reference to the lock, it will | |
12 be maintained by the LockMgr. Obviously, if there are no pending | |
13 transactions there's no need to hold the lock or it's state because | |
14 the lock should be clear. If it's not clear, we have a bug!!!! :) | |
15 */ | |
16 // private SoftHashMap theLocks = new SoftHashMap(); | |
17 private LockCache theLocks = new LockCache(); | |
18 | |
19 public TxnLock getLock(OID aOID) { | |
20 return theLocks.getOrInsert(aOID); | |
21 } | |
22 | |
23 public TxnLock newLock(OID aOID) { | |
24 TxnLock myLock = new TxnLock(); | |
25 | |
26 theLocks.put(aOID, myLock); | |
27 | |
28 return myLock; | |
29 } | |
30 | |
31 /** | |
32 Test to see if the specified OID has an active lock associated | |
33 with it. This is only truly useful in situations where the associated | |
34 Entry is in an unchanging state perhaps because it has been DELETED | |
35 or it's lease has expired. | |
36 */ | |
37 public boolean hasActiveLock(OID aOID) { | |
38 TxnLock myLock = (TxnLock) theLocks.get(aOID); | |
39 | |
40 if (myLock != null) { | |
41 synchronized(myLock) { | |
42 return myLock.isActive(); | |
43 } | |
44 } | |
45 | |
46 return false; | |
47 } | |
48 | |
49 } |