1 21 22 package org.apache.derbyTesting.unitTests.services; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 import java.util.Hashtable ; 26 import org.apache.derby.iapi.services.locks.*; 27 28 31 class T_L2 implements Lockable { 32 33 private int allowed; 34 private Object [] lockers; 35 private int[] counts; 36 37 T_L2(int allowed) { 38 this.allowed = allowed; 39 lockers = new Object [allowed]; 40 counts = new int[allowed]; 41 } 42 43 47 48 public void lockEvent(Latch lockInfo) { 49 50 int empty = -1; 51 for (int i = 0; i < allowed; i++) { 52 if (lockers[i] == lockInfo.getCompatabilitySpace()) { 53 counts[i]++; 54 return; 55 } 56 57 if (lockers[i] == null) 58 empty = i; 59 } 60 61 if (SanityManager.DEBUG) 62 SanityManager.ASSERT(empty != -1); 63 lockers[empty] = lockInfo.getCompatabilitySpace(); 64 counts[empty] = 1; 65 66 } 67 68 public boolean requestCompatible(Object requestedQualifier, Object grantedQualifier) { 69 return false; 70 } 71 72 public boolean lockerAlwaysCompatible() { 73 return true; 74 } 75 76 public void unlockEvent(Latch lockInfo) { 77 78 for (int i = 0; i < allowed; i++) { 79 80 if (lockers[i] == lockInfo.getCompatabilitySpace()) { 81 counts[i]--; 82 if (SanityManager.DEBUG) 83 SanityManager.ASSERT(counts[i] >= 0); 84 if (counts[i] == 0) { 85 lockers[i] = null; 86 return; 87 } 88 89 return; 90 } 91 } 92 93 if (SanityManager.DEBUG) 94 SanityManager.THROWASSERT("unlocked by a compatability space that does not exist"); 95 } 96 97 public boolean lockAttributes(int flag, Hashtable t) 98 { 99 return false; 100 } 101 102 } 103 | Popular Tags |