1 23 24 28 package com.sun.jts.CosTransactions; 29 30 import java.util.*; 31 import org.omg.CosTransactions.*; 32 33 41 public class AdminUtil 42 { 43 45 58 public static void freezeAll() 59 { 60 TransactionState.freezeLock.acquireWriteLock(); 61 } 62 63 73 public static void unfreezeAll() 74 { 75 TransactionState.freezeLock.releaseWriteLock(); 76 } 77 78 79 89 public static boolean isFrozenAll() 90 { 91 return TransactionState.freezeLock.isWriteLocked(); 92 } 93 94 95 96 102 103 104 110 111 113 124 public static void startSampling() 125 { 126 if(!bSampling){ 127 try 128 { 129 statisticsLock.acquireWriteLock(); 130 lSampleEndTime = 0 ; 131 lSampleStartTime = System.currentTimeMillis(); 132 iCommits = 0; 133 iAborts = 0; 134 iPending = 0; 135 iRecCommits = 0; 136 iRecAborts = 0; 137 Iterator iter = getAllTransactions().iterator(); 140 141 while ( iter.hasNext() ) 142 { 143 CoordinatorImpl coord = (CoordinatorImpl)iter.next(); 144 if ( coord.get_status() == 145 org.omg.CosTransactions.Status.StatusPrepared ) 146 iPending++; 147 } 148 149 bSampling = true; 150 } 151 finally 152 { 153 statisticsLock.releaseWriteLock(); 154 } 155 } 156 } 157 158 159 168 public static void stopSampling() 169 { 170 try 171 { 172 statisticsLock.acquireWriteLock(); 173 lSampleEndTime = System.currentTimeMillis(); 174 bSampling = false; 175 } 176 finally 177 { 178 statisticsLock.releaseWriteLock(); 179 } 180 } 181 182 184 187 static void incrementCommitedTransactionCount() 188 { 189 try 190 { 191 statisticsLock.acquireReadLock(); 192 synchronized ( lkCommits ) 193 { 194 iCommits++; 195 } 196 } 197 finally 198 { 199 statisticsLock.releaseReadLock(); 200 } 201 } 202 203 207 static void incrementAbortedTransactionCount() 208 { 209 try 210 { 211 statisticsLock.acquireReadLock(); 212 synchronized ( lkAborts ) 213 { 214 iAborts++; 215 } 216 } 217 finally 218 { 219 statisticsLock.releaseReadLock(); 220 } 221 } 222 223 227 static void incrementUnpreparedAbortedTransactionCount() 228 { 229 try 230 { 231 statisticsLock.acquireReadLock(); 232 synchronized ( lkUAborts ) 233 { 234 iUAborts++; 235 } 236 } 237 finally 238 { 239 statisticsLock.releaseReadLock(); 240 } 241 } 242 243 244 249 static void incrementPendingTransactionCount() 250 { 251 try 252 { 253 statisticsLock.acquireReadLock(); 254 synchronized ( lkPending ) 255 { 256 iPending++; 257 } 258 } 259 finally 260 { 261 statisticsLock.releaseReadLock(); 262 } 263 } 264 265 269 public static void incrementRecoveryCommitedTransactionCount() 270 { 271 try 272 { 273 statisticsLock.acquireReadLock(); 274 synchronized ( lkRecCommits ) 275 { 276 iRecCommits++; 277 } 278 } 279 finally 280 { 281 statisticsLock.releaseReadLock(); 282 } 283 } 284 285 286 290 public static void incrementRecoveryAbortedTransactionCount() 291 { 292 try 293 { 294 statisticsLock.acquireReadLock(); 295 synchronized ( lkRecAborts ) 296 { 297 iRecAborts++; 298 } 299 } 300 finally 301 { 302 statisticsLock.releaseReadLock(); 303 } 304 } 305 306 307 325 326 344 345 346 348 352 public static long getCommitedTransactionCount() 353 { 354 return iCommits; 355 } 356 357 361 public static long getAbortedTransactionCount() 362 { 363 return iAborts; 364 } 365 366 370 public static long getActiveTransactionCount() 371 { 372 return RecoveryManager.getCoordsByGlobalTID().size() 373 - getPendingTransactionCount(); 374 } 375 376 383 public static long getPendingTransactionCount() 384 { 385 return iPending-iAborts-iCommits+iUAborts; 386 } 387 388 392 public static long getRecoveryCommitedTransactionCount() 393 { 394 return iRecCommits; 395 } 396 397 398 402 public static long getRecoveryAbortedTransactionCount() 403 { 404 return iRecAborts; 405 } 406 407 408 416 417 424 425 429 public static long getSamplingStartTime() 430 { 431 return lSampleStartTime; 432 } 433 434 435 439 public static long getSamplingEndTime() 440 { 441 return lSampleEndTime; 442 } 443 444 448 public static long getSamplingDuration() 449 { 450 return ( lSampleEndTime == 0 && lSampleStartTime != 0 ) 451 ? System.currentTimeMillis() - lSampleStartTime 452 : lSampleEndTime - lSampleStartTime; 453 } 454 455 456 458 462 public static Collection getAllTransactions() 463 { 464 return RecoveryManager.getCoordsByGlobalTID().values(); 465 } 466 467 471 public static Enumeration getAllTIDs() 472 { 473 return RecoveryManager.getCoordsByGlobalTID().keys(); 474 } 475 476 477 private static RWLock statisticsLock = new RWLock() ; 478 private static long lSampleStartTime = 0 ; 479 private static long lSampleEndTime = 0 ; 480 static boolean bSampling = false ; 481 private static int iCommits = 0; 482 private static int iAborts = 0; 483 private static int iUAborts=0; 484 private static int iPending = 0; 485 static int iRecCommits = 0; 486 static int iRecAborts = 0; 487 493 private static Object lkCommits = new Object (); 494 private static Object lkAborts = new Object (); 495 private static Object lkUAborts = new Object (); 496 private static Object lkPending = new Object (); 497 static Object lkRecCommits = new Object (); 498 static Object lkRecAborts = new Object (); 499 500 506 507 } 508 | Popular Tags |