1 21 22 package org.apache.derby.impl.services.locks; 23 24 import org.apache.derby.iapi.services.diag.Diagnosticable; 25 import org.apache.derby.iapi.services.diag.DiagnosticUtil; 26 import org.apache.derby.iapi.error.StandardException; 27 import org.apache.derby.iapi.services.sanity.SanityManager; 28 import org.apache.derby.iapi.services.locks.Lockable; 29 30 import java.util.Properties ; 31 import java.util.List ; 32 import java.util.Iterator ; 33 34 36 37 public class D_LockControl implements Diagnosticable 38 { 39 protected LockControl control; 40 41 public D_LockControl() 42 { 43 } 44 45 46 47 50 public void init(Object obj) 51 { 52 control = (LockControl) obj; 53 } 54 55 59 public String diag() 60 throws StandardException 61 { 62 StringBuffer sb = new StringBuffer (1024); 63 64 sb.append("LockControl:\n granted list: "); 65 66 int i = 0; 67 68 Object firstGrant = control.getFirstGrant(); 69 if (firstGrant != null) { 70 sb.append("\n g[" + i + "]:" + DiagnosticUtil.toDiagString(firstGrant)); 71 i++; 72 } 73 74 List granted = control.getGranted(); 75 76 if (granted != null) { 77 for (Iterator dli = granted.iterator(); dli.hasNext(); ) 78 { 79 sb.append("\n g[" + i + "]:" + DiagnosticUtil.toDiagString(dli.next())); 80 i++; 81 } 82 } 83 84 85 sb.append("\n waiting list:"); 86 87 List waiting = control.getWaiting(); 88 89 int num_waiting = 0; 90 91 if (waiting != null) 92 { 93 for (Iterator dli = waiting.iterator(); dli.hasNext(); ) 94 { 95 sb.append( 96 "\n w[" + num_waiting + "]:" + 97 DiagnosticUtil.toDiagString(dli.next())); 98 99 num_waiting++; 100 } 101 } 102 103 if (num_waiting == 0) 104 sb.append(" no waiting locks."); 105 106 return sb.toString(); 107 } 108 public void diag_detail(Properties prop) {} 109 110 113 114 115 118 119 static void debugLock(String type, Object compatabilitySpace, Object group, Lockable ref, Object qualifier, int timeout) { 120 121 if (SanityManager.DEBUG) { 122 123 SanityManager.DEBUG(Constants.LOCK_TRACE, type + 124 debugLockString( 125 compatabilitySpace, group, ref, qualifier, timeout)); 126 } 127 } 128 static void debugLock(String type, Object compatabilitySpace, Object group) { 129 130 if (SanityManager.DEBUG) { 131 132 SanityManager.DEBUG(Constants.LOCK_TRACE, type + 133 debugLockString(compatabilitySpace, group)); 134 } 135 } 136 static void debugLock(String type, Object compatabilitySpace, Object group, Lockable ref) { 137 138 if (SanityManager.DEBUG) { 139 140 SanityManager.DEBUG(Constants.LOCK_TRACE, type + 141 debugLockString(compatabilitySpace, group, ref)); 142 } 143 } 144 145 146 static String debugLockString(Object compatabilitySpace, Object group) { 147 148 if (SanityManager.DEBUG) { 149 150 StringBuffer sb = new StringBuffer (""); 151 152 debugAppendObject(sb, " CompatabilitySpace=", compatabilitySpace); 153 debugAppendObject(sb, " Group=", group); 154 155 debugAddThreadInfo(sb); 156 157 return sb.toString(); 158 159 } else { 160 return null; 161 } 162 } 163 164 static String debugLockString(Object compatabilitySpace, Object group, Lockable ref) { 165 166 if (SanityManager.DEBUG) { 167 168 StringBuffer sb = new StringBuffer (""); 169 170 debugAppendObject(sb, " Lockable ", ref); 171 debugAppendObject(sb, " CompatabilitySpace=", compatabilitySpace); 172 debugAppendObject(sb, " Group=", group); 173 174 debugAddThreadInfo(sb); 175 176 return sb.toString(); 177 178 } else { 179 return null; 180 } 181 } 182 183 184 static String debugLockString(Object compatabilitySpace, Object group, Lockable ref, Object qualifier, int timeout) { 185 186 if (SanityManager.DEBUG) { 187 188 StringBuffer sb = new StringBuffer (""); 189 190 debugAppendObject(sb, " Lockable ", ref); 191 debugAppendObject(sb, " Qualifier=", qualifier); 192 debugAppendObject(sb, " CompatabilitySpace=", compatabilitySpace); 193 debugAppendObject(sb, " Group=", group); 194 195 if (timeout >= 0) { 196 sb.append(" Timeout(ms)="); 197 sb.append(timeout); 198 } 199 200 debugAddThreadInfo(sb); 201 202 203 return sb.toString(); 204 205 } else { 206 return null; 207 } 208 } 209 210 static void debugAddThreadInfo(StringBuffer sb) { 211 212 if (SanityManager.DEBUG) { 213 if (SanityManager.DEBUG_ON(Constants.LOCK_TRACE_ADD_THREAD_INFO)) { 214 debugAppendObject(sb, " Thread=", Thread.currentThread()); 215 } 216 } 217 } 218 219 static void debugAppendObject(StringBuffer sb, String desc, Object item) { 220 if (SanityManager.DEBUG) { 221 222 sb.append(desc); 223 224 if (item != null) 225 sb.append(item.toString()); 226 else 227 sb.append("<null>"); 228 } 229 } 230 } 231 232 | Popular Tags |