1 23 24 28 29 51 package com.sun.jts.CosTransactions; 52 53 import org.omg.CORBA.*; 54 import org.omg.PortableServer.*; 55 import org.omg.CosTransactions.*; 56 import com.sun.jts.trace.*; 57 import java.util.logging.Logger ; 58 import java.util.logging.Level ; 59 import com.sun.logging.LogDomains; 60 import com.sun.jts.utils.LogFormatter; 61 62 77 78 87 class RecoveryCoordinatorImpl extends RecoveryCoordinatorPOA { 88 89 private static boolean recoverable = false; 90 private static POA poa = null; 91 private RecoveryCoordinator thisRef = null; 92 private int internalSeq = 0; 93 96 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 97 GlobalTID globalTID = null; 98 99 RecoveryCoordinatorImpl() {} 100 101 118 RecoveryCoordinatorImpl(GlobalTID globalTID, int sequence) { 119 120 this.globalTID = globalTID; 121 internalSeq = sequence; 122 123 134 } 135 136 145 public void finalize() { 146 147 globalTID = null; 148 internalSeq = 0; 149 } 150 151 168 public Status replay_completion(Resource res) throws NotPrepared { 169 170 if(_logger.isLoggable(Level.FINE)) 171 { 172 _logger.logp(Level.FINE,"RecoveryCoordinatorImpl", 173 "replay_completion()","replay_completion on Resource:"+ 174 res); 175 } 176 177 178 Status result = Status.StatusRolledBack; 179 180 CoordinatorImpl coord = RecoveryManager.getCoordinator(globalTID); 181 if (coord != null) { 182 try { 183 result = coord.get_status(); 184 } catch (SystemException exc) {} 185 } 186 187 switch (result.value()) { 188 189 195 196 case Status._StatusActive : 197 case Status._StatusMarkedRollback : 198 try { 199 coord.rollback_only(); 200 } catch (Throwable exc) {} 201 202 throw new NotPrepared(); 203 204 210 211 case Status._StatusPrepared : 212 result = Status.StatusUnknown; 213 break; 214 215 223 224 case Status._StatusCommitting : 225 233 break; 234 235 case Status._StatusCommitted : 236 break; 237 238 case Status._StatusRolledBack : 239 240 246 if (coord == null) { 247 248 if (!Configuration.getProxyChecker().isProxy(res)) { 249 rollbackOrphan(res); 250 } else { 251 252 257 try { 258 OrphanRollbackThread rollbackThread = 259 new OrphanRollbackThread( 260 this, (Resource) res._duplicate()); 261 rollbackThread.start(); 262 } catch (SystemException exc) {} 263 } 264 } 265 266 break; 267 268 273 274 default : 275 result = Status.StatusRolledBack; 276 } 277 278 return result; 279 } 280 281 public Status replay_completion(Resource res, String logPath) throws NotPrepared { 283 284 if(_logger.isLoggable(Level.FINE)) 285 { 286 _logger.logp(Level.FINE,"RecoveryCoordinatorImpl", 287 "replay_completion()","replay_completion on Resource:"+ res); 288 } 289 290 Status result = Status.StatusRolledBack; 291 292 CoordinatorImpl coord = DelegatedRecoveryManager.getCoordinator(globalTID, logPath); 293 if (coord != null) { 294 try { 295 result = coord.get_status(); 296 } catch (SystemException exc) {} 297 } 298 299 switch (result.value()) { 300 301 307 308 case Status._StatusActive : 309 case Status._StatusMarkedRollback : 310 try { 311 coord.rollback_only(); 312 } catch (Throwable exc) {} 313 314 throw new NotPrepared(); 315 316 322 323 case Status._StatusPrepared : 324 result = Status.StatusUnknown; 325 break; 326 327 335 336 case Status._StatusCommitting : 337 345 break; 346 347 case Status._StatusCommitted : 348 break; 349 350 case Status._StatusRolledBack : 351 352 358 if (coord == null) { 359 360 if (!Configuration.getProxyChecker().isProxy(res)) { 361 rollbackOrphan(res); 362 } else { 363 364 369 try { 370 OrphanRollbackThread rollbackThread = 371 new OrphanRollbackThread( 372 this, (Resource) res._duplicate()); 373 rollbackThread.start(); 374 } catch (SystemException exc) {} 375 } 376 } 377 378 break; 379 380 385 386 default : 387 result = Status.StatusRolledBack; 388 } 389 390 return result; 391 } 392 393 410 void rollbackOrphan(Resource res) { 411 412 try { 413 res.rollback(); 414 } catch(Throwable exc) { 415 416 420 if (exc instanceof HeuristicCommit || 421 exc instanceof HeuristicMixed || 422 exc instanceof HeuristicHazard) { 423 _logger.log(Level.WARNING,"jts.heuristic_exception",exc.toString()); 424 } else {} 425 } 426 427 429 res._release(); 430 } 431 432 450 RecoveryCoordinatorImpl(byte[] key) { 451 452 454 byte[] tidBytes = new byte[key.length - 4]; 455 456 System.arraycopy(key, 4, tidBytes, 0, tidBytes.length); 460 461 globalTID = new GlobalTID(tidBytes); 462 463 466 RecoveryManager.waitForRecovery(); 467 468 } 470 471 480 synchronized final RecoveryCoordinator object() { 481 482 if (thisRef == null) { 483 if (poa == null) { 484 poa = Configuration.getPOA("RecoveryCoordinator"); 485 recoverable = Configuration.isRecoverable(); 486 } 487 488 try { 489 490 if (recoverable && globalTID != null) { 491 494 byte[] tidBytes = globalTID.toBytes(); 495 byte[] id = new byte[tidBytes.length + 4]; 496 System.arraycopy(tidBytes, 0, id, 4, tidBytes.length); 497 id[0] = (byte) internalSeq; 498 id[1] = (byte)(internalSeq >> 8); 499 id[2] = (byte)(internalSeq >> 16); 500 id[3] = (byte)(internalSeq >> 24); 501 502 504 poa.activate_object_with_id(id, this); 505 506 org.omg.CORBA.Object obj = 507 poa.create_reference_with_id( 508 id, RecoveryCoordinatorHelper.id()); 509 thisRef = RecoveryCoordinatorHelper.narrow(obj); 510 } else { 512 poa.activate_object(this); 513 org.omg.CORBA.Object obj = poa.servant_to_reference(this); 514 thisRef = RecoveryCoordinatorHelper.narrow(obj); 515 } 517 } catch(Exception exc) { 518 _logger.log(Level.SEVERE,"jts.create_recoverycoordinator_error"); 519 String msg = LogFormatter.getLocalizedMessage(_logger, 520 "jts.create_recoverycoordinator_error"); 521 throw new org.omg.CORBA.INTERNAL (msg); 522 } 523 } 524 525 return thisRef; 526 } 527 528 537 synchronized final void destroy() { 538 539 try { 540 if (poa != null && thisRef != null) { 541 poa.deactivate_object(poa.reference_to_id(thisRef)); 542 thisRef = null; 543 } else { 544 550 POA rcPoa = null; 551 if (poa == null) { 552 rcPoa = Configuration.getPOA("RecoveryCoordinator"); 553 } else { 554 rcPoa = poa; 555 } 556 557 if (thisRef == null) { 558 rcPoa.deactivate_object(rcPoa.servant_to_id(this)); 559 } else { 560 rcPoa.deactivate_object(rcPoa.reference_to_id(thisRef)); 561 thisRef = null; 562 } 563 } 564 } catch( Exception exc ) { 565 _logger.log(Level.WARNING,"jts.object_destroy_error","RecoveryCoordinator"); 566 } 567 568 finalize(); 569 } 570 } 571 572 585 class OrphanRollbackThread extends Thread { 586 Resource resource = null; 587 RecoveryCoordinatorImpl recovery = null; 588 589 599 OrphanRollbackThread(RecoveryCoordinatorImpl recovery, 600 Resource resource) { 601 this.resource = resource; 602 this.recovery = recovery; 603 setName("JTS Orphan Rollback Thread"); 604 } 605 606 615 public void run() { 616 recovery.rollbackOrphan(resource); 617 } 618 } 619 | Popular Tags |