1 24 package org.objectweb.jalisto.se.impl.lock; 25 26 import org.objectweb.jalisto.se.api.internal.DataWrapper; 27 import org.objectweb.jalisto.se.api.internal.multi.LockTable; 28 import org.objectweb.jalisto.se.exception.multi.LockException; 29 30 import java.util.*; 31 32 public class LockTableImpl implements LockTable { 33 34 public LockTableImpl() { 35 locks = new Hashtable(); 36 } 37 38 public synchronized Iterator getKeys() { 39 ArrayList keys = new ArrayList(); 40 keys.addAll(locks.keySet()); 41 return keys.iterator(); 42 } 43 44 public synchronized Lock getLockOrCreate(Object floid) { 45 Lock lock; 46 if (!locks.containsKey(floid)) { 47 lock = Lock.newInstance(); 48 locks.put(floid, lock); 49 } else { 50 lock = (Lock) locks.get(floid); 51 } 52 return lock; 53 } 54 55 public synchronized Lock getLock(Object floid) { 56 if (!locks.containsKey(floid)) { 57 throw new LockException(); 58 } 59 return (Lock) locks.get(floid); 60 } 61 62 public synchronized DataWrapper getLockedValue(Object floid, Object sessionId) { 63 Lock lock = (Lock) locks.get(floid); 64 if (lock != null) { 65 return lock.getModifiedValue(sessionId); 66 } 67 throw new LockException("no lock find with this floid " + floid); 68 } 69 70 public synchronized void checkLocksForSession(Collection classeFloids, Object sessionId) { 72 Iterator floids = locks.keySet().iterator(); 73 while (floids.hasNext()) { 74 Object floid = floids.next(); 75 Lock lock = (Lock) locks.get(floid); 76 if (lock.hasToBeRemoveForExtentWith(sessionId)) { 77 classeFloids.remove(floid); 78 } 79 } 80 } 81 82 public synchronized boolean containsDeletedValue(Object floid, Object sessionId) { 83 Lock lock = (Lock) locks.get(floid); 84 if (lock != null) { 85 return (lock.getCurrentAction(sessionId) == ObjectTransactionnalState.DELETE_ACTION); 86 } 87 return false; 88 } 89 90 public synchronized boolean containsLockedValue(Object floid, Object sessionId) { 91 Lock lock = (Lock) locks.get(floid); 92 if (lock != null) { 93 return (lock.getModifiedValue(sessionId) != null); 94 } 95 return false; 96 } 97 98 public boolean hasLock(Object floid) { 99 return locks.containsKey(floid); 100 } 101 102 public void publishLocks() { 103 System.out.println(locks.toString()); 104 } 105 106 public synchronized void removeLockByFloid(Object floid) { 108 Lock lock = (Lock) locks.get(floid); 109 if (lock != null) { 110 if (lock.canBeDeleted()) { 111 locks.remove(floid); 112 lock.release(); 113 } 114 } 115 } 116 117 public boolean isEmpty() { 118 return locks.isEmpty(); 119 } 120 121 122 private Map locks; } 124 | Popular Tags |