1 23 package org.apache.slide.store.mem; 24 25 import java.util.ArrayList ; 26 import java.util.Enumeration ; 27 import java.util.List ; 28 29 import org.apache.slide.common.ServiceAccessException; 30 import org.apache.slide.common.Uri; 31 import org.apache.slide.lock.LockTokenNotFoundException; 32 import org.apache.slide.lock.NodeLock; 33 import org.apache.slide.store.LockStore; 34 35 36 38 public class TransientLockStore extends AbstractTransientStore 39 implements LockStore 40 { 41 43 public void putLock(Uri uri, NodeLock lock) throws ServiceAccessException { 44 debug("putLock {0} {1}", uri, lock.getLockId()); 45 List list = (List )get(uri.toString()); 46 if (list != null) { 47 list = new ArrayList (list); 48 } else { 49 list = new ArrayList (); 50 } 51 list.add(lock); 52 put(uri.toString(), list); 53 } 54 55 public void renewLock(Uri uri, NodeLock lock) 56 throws ServiceAccessException, LockTokenNotFoundException 57 { 58 debug("renewLock {0} {1}", uri, lock.getLockId()); 59 List list = (List )get(uri.toString()); 60 if (list == null || !list.contains(lock)) { 61 throw new LockTokenNotFoundException(lock); 62 } 63 list = new ArrayList (list); 64 list.remove(lock); 65 list.add(lock); 66 put(uri.toString(), list); 67 } 68 69 public void removeLock(Uri uri, NodeLock lock) 70 throws ServiceAccessException, LockTokenNotFoundException 71 { 72 debug("removeLock {0} {1}", uri, lock.getLockId()); 73 List list = (List )get(uri.toString()); 74 if (list == null) { 75 throw new LockTokenNotFoundException(lock); 76 } 77 if (!list.contains(lock)) { 78 throw new LockTokenNotFoundException(lock); 79 } else { 80 if (list.size() == 1) { 81 remove(uri.toString()); 82 } else { 83 list = new ArrayList (list); 84 list.remove(lock); 85 put(uri.toString(), list); 86 } 87 } 88 } 89 90 public void killLock(Uri uri, NodeLock lock) 91 throws ServiceAccessException, LockTokenNotFoundException 92 { 93 debug("killLock {0} {1}", uri, lock.getLockId()); 94 removeLock(uri, lock); 95 } 96 97 public Enumeration enumerateLocks(Uri uri) throws ServiceAccessException 98 { 99 debug("enumerateLocks {0}", uri); 100 101 List list = (List )get(uri.toString()); 102 if (list != null) { 103 return new IteratorEnum(list.iterator()); 104 } else { 105 return EMPTY_ENUM; 106 } 107 } 108 } 109 | Popular Tags |