1 21 22 package org.apache.derby.impl.services.locks; 23 24 import org.apache.derby.iapi.services.locks.Latch; 25 26 import java.util.Hashtable ; 27 import java.util.Vector ; 28 import java.util.Enumeration ; 29 import java.util.NoSuchElementException ; 30 31 import java.util.ListIterator ; 32 import java.util.List ; 33 34 39 class LockTableVTI implements Enumeration 40 { 41 48 private final LockSet clonedLockTable; 49 private final Enumeration outerControl; 50 private Control control; 51 private ListIterator grantedList; 52 private ListIterator waitingList; 53 private Latch nextLock; 54 55 LockTableVTI(LockSet clonedLockTable) 56 { 57 this.clonedLockTable = clonedLockTable; 58 59 outerControl = clonedLockTable.elements(); 60 } 61 62 63 public boolean hasMoreElements() { 64 65 if (nextLock != null) 66 return true; 67 68 for (;;) { 69 70 if (control == null) { 71 if (!outerControl.hasMoreElements()) 72 return false; 73 75 control = (Control) outerControl.nextElement(); 76 77 List granted = control.getGranted(); 78 if (granted != null) 79 grantedList = granted.listIterator(); 80 81 82 List waiting = control.getWaiting(); 83 if (waiting != null) 84 waitingList = waiting.listIterator(); 85 86 nextLock = control.getFirstGrant(); 87 if (nextLock == null) { 88 89 nextLock = getNextLock(control); 90 } 91 92 } else { 93 nextLock = getNextLock(control); 94 } 95 96 97 if (nextLock != null) 98 return true; 99 100 control = null; 101 } 102 } 103 104 private Latch getNextLock(Control control) { 105 Latch lock = null; 106 if (grantedList != null) { 108 if (grantedList.hasNext()) { 109 lock = (Lock) grantedList.next(); 110 } 111 else 112 grantedList = null; 113 } 114 115 if (lock == null) { 116 if (waitingList != null) { 117 if (waitingList.hasNext()) { 118 lock = (Lock) waitingList.next(); 119 } 120 else 121 waitingList = null; 122 } 123 } 124 125 return lock; 126 } 127 128 public Object nextElement() { 129 130 if (!hasMoreElements()) 131 throw new NoSuchElementException (); 132 133 Latch ret = nextLock; 134 135 nextLock = null; 136 return ret; 137 } 138 } 139 140 141 142 | Popular Tags |