1 package org.apache.ojb.otm.lock.map; 2 3 17 18 import java.util.Iterator ; 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import org.apache.ojb.broker.Identity; 23 import org.apache.ojb.otm.lock.ObjectLock; 24 25 32 public class InMemoryLockMap implements LockMap 33 { 34 35 private HashMap _locks; 36 37 public InMemoryLockMap () 38 { 39 _locks = new HashMap (); 40 } 41 42 43 48 public ObjectLock getLock(Identity oid) 49 { 50 ObjectLock lock; 51 52 synchronized (_locks) 53 { 54 lock = (ObjectLock) _locks.get(oid); 55 if (lock == null) 56 { 57 lock = new ObjectLock(oid); 58 _locks.put(oid, lock); 59 } 60 } 61 return lock; 62 } 63 64 public void gc() 65 { 66 synchronized (_locks) 67 { 68 for (Iterator it = _locks.entrySet().iterator(); it.hasNext(); ) 69 { 70 Map.Entry entry = (Map.Entry ) it.next(); 71 ObjectLock lock = (ObjectLock) entry.getValue(); 72 if (lock.isFree()) 73 { 74 it.remove(); 75 } 76 } 77 } 78 } 79 80 public String toString() 81 { 82 return _locks.toString(); 83 } 84 } 85 | Popular Tags |