KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jts > CosTransactions > CoordinatorResourceImpl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28 //----------------------------------------------------------------------------
29
//
30
// Module: CoordinatorResourceImpl.java
31
//
32
// Description: Subordinate Coordinator participation interface.
33
//
34
// Product: com.sun.jts.CosTransactions
35
//
36
// Author: Simon Holdsworth
37
//
38
// Date: March, 1997
39
//
40
// Copyright (c): 1995-1997 IBM Corp.
41
//
42
// The source code for this program is not published or otherwise divested
43
// of its trade secrets, irrespective of what has been deposited with the
44
// U.S. Copyright Office.
45
//
46
// This software contains confidential and proprietary information of
47
// IBM Corp.
48
//----------------------------------------------------------------------------
49

50 package com.sun.jts.CosTransactions;
51
52 // Import required classes.
53

54 import org.omg.CORBA.*;
55 import org.omg.PortableServer.*;
56 import org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc;
57 import org.omg.PortableServer.POAPackage.ServantNotActive JavaDoc;
58 import org.omg.CosTransactions.*;
59
60 import com.sun.jts.otsidl.*;
61
62 import com.sun.jts.trace.*;
63 import java.util.logging.Logger JavaDoc;
64 import java.util.logging.Level JavaDoc;
65 import com.sun.logging.LogDomains;
66 import com.sun.jts.utils.LogFormatter;
67
68 /**The CoordinatorResourceImpl interface provides operations that allow a
69  * Coordinator to be represented among the registered Resources of a
70  * superior Coordinator, without requiring that the Coordinator support the
71  * Resource interface.
72  *
73  * @version 0.02
74  *
75  * @author Simon Holdsworth, IBM Corporation
76  *
77  * @see
78 */

79 //----------------------------------------------------------------------------
80
// CHANGE HISTORY
81
//
82
// Version By Change Description
83
// 0.01 SAJH Initial implementation.
84
// 0.02 GDH Gordon Hutchison April 1998
85
// Improved behaviour post recovery occurring
86
//-----------------------------------------------------------------------------
87

88 class CoordinatorResourceImpl extends CoordinatorResourcePOA
89         implements CompletionHandler {
90     private static POA poa = null;
91     private static boolean recoverable = false;
92     private CoordinatorResource thisRef = null;
93
94     /**This flag may be set to indicate that the transaction is being forced.
95      */

96     boolean beingForced = false;
97
98     private GlobalTID globalTID = null;
99     private boolean subtransaction = false;
100     private boolean aborted = false;
101     private boolean heuristicDamage = false;
102     private boolean completed = false;
103     private boolean setAsTerminator = false;
104
105     /*
106         Logger to log transaction messages
107     */

108     
109     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER);
110     /**Normal constructor.
111      * <p>
112      * Sets up the CoordinatorResourceImpl with the Coordinator reference and the
113      * local transaction identifier so that the Resource can always find the
114      * Coordinator to pass on the two-phase commit messages.
115      * <p>
116      * A flag is passed to indicate whether the CoordinatorResourceImpl represents
117      * a subtransaction.
118      *
119      * @param globalTID The global transaction identifier.
120      * @param coord The Coordinator for the transaction.
121      * @param subtran Subtransaction indicator.
122      *
123      * @return
124      *
125      * @see
126      */

127     CoordinatorResourceImpl( GlobalTID globalTID,
128                              CoordinatorImpl coord,
129                              boolean subtran ) {
130
131
132         // Set up the instance variables to those values passed in.
133

134         subtransaction = subtran;
135         this.globalTID = globalTID;
136
137         // Inform the Coordinator that this is the object that normally terminates
138
// the transaction.
139

140         if( coord != null )
141             coord.setTerminator(this);
142
143     }
144
145     /**Cleans up the state of the object.
146      *
147      * @param
148      *
149      * @return
150      *
151      * @see
152      */

153     public void finalize() {
154
155         globalTID = null;
156
157     }
158
159     /**Informs the CoordinatorResourceImpl object that the transaction it
160      * represents has completed.
161      * <p>
162      * Flags indicate whether the transaction aborted, and whether there was
163      * heuristic damage.
164      *
165      * @param aborted Indicates the transaction aborted.
166      * @param heuristicDamage Indicates heuristic damage occurred.
167      *
168      * @return
169      *
170      * @see CompletionHandler
171      */

172     public void setCompleted( boolean aborted,
173                               boolean heuristicDamage ) {
174
175         // Record the information.
176

177         completed = true;
178         this.aborted = aborted;
179         this.heuristicDamage = heuristicDamage;
180
181     }
182
183     /**Requests the prepare phase vote from the object.
184      * <p>
185      * This uses a private interface to pass the superior Coordinator's prepare request.
186      * on to the Coordinator that registered the CoordinatorResourceImpl.
187      * <p>
188      * The result from the Coordinator is returned to the caller.
189      *
190      * @param
191      *
192      * @return The Coordinators vote.
193      *
194      * @exception SystemException The operation failed.
195      * @exception HeuristicMixed Indicates that a participant voted to roll the
196      * transaction back, but one or more others have already heuristically committed.
197      * @exception HeuristicHazard Indicates that a participant voted to roll the
198      * transaction back, but one or more others may have already heuristically
199      * committed.
200      *
201      * @see Resource
202      */

203     public Vote prepare()
204         throws SystemException, HeuristicMixed, HeuristicHazard {
205
206
207         Vote result = Vote.VoteRollback;
208
209         // If no global identifier has been set up, we can do nothing but vote for
210
// the transaction to be rolled back.
211

212         if( globalTID == null ) {
213             INTERNAL exc = new INTERNAL(MinorCode.NoGlobalTID,
214                                         CompletionStatus.COMPLETED_NO);
215             throw exc;
216         }
217
218         // Prepare operations should only come in for top-level transactions.
219

220         if( subtransaction ) {
221
222             INTERNAL exc = new INTERNAL(MinorCode.TopForSub,
223                                         CompletionStatus.COMPLETED_NO);
224             throw exc;
225         }
226
227         // If the transaction that this object represents has already been rolled
228
// back, return a rollback vote.
229

230         if (completed) {
231             if (aborted) {
232                 result = Vote.VoteRollback;
233             } else {
234                 result = Vote.VoteCommit;
235             }
236         } else {
237
238             // Look up the Coordinator for the transaction.
239

240             TopCoordinator coord = (TopCoordinator)RecoveryManager.getCoordinator(globalTID);
241
242             // If there is a Coordinator, lock it for the duration of this operation.
243
// If there is no Coordinator, return a rollback vote.
244

245             if( coord != null )
246                 synchronized( coord ) {
247
248                     // Get the Coordinator's vote.
249
// If the Coordinator throws HeuristicMixed or HeuristicHazard,
250
// allow them to percolate to the caller.
251

252                     result = coord.prepare();
253
254                     // If the Coordinator has voted to roll the transaction back, then this
255
// CoordinatorResourceImpl will not be called again. Ensure that the
256
// Coordinator has rolled back.
257
// If the Coordinator throws HeuristicMixed or HeuristicHazard,
258
// allow them to percolate to the caller.
259

260                     if( result == Vote.VoteRollback )
261                         coord.rollback(false);
262                 }
263         }
264
265         // If the Coordinator has voted to roll the transaction back, then this
266
// CoordinatorResourceImpl will not be called again.
267
// If a heuristic exception was thrown, this will be done in forget.
268

269         if (result == Vote.VoteRollback) {
270             destroy();
271         }
272
273         return result;
274     }
275
276     /**Informs the object that the transaction is to be committed.
277      * <p>
278      * Passes the superior Coordinator's commit request on to the Coordinator that
279      * registered the CoordinatorResourceImpl, using a private interface.
280      * <p>
281      * If the Coordinator does not raise any heuristic exception, the
282      * CoordinatorResourceImpl destroys itself.
283      *
284      * @param
285      *
286      * @return
287      *
288      * @exception HeuristicRollback The transaction has already been rolled back.
289      * @exception HeuristicMixed At least one participant in the transaction has
290      * rolled back its changes.
291      * @exception HeuristicHazard At least one participant in the transaction may
292      * have rolled back its changes.
293      * @exception NotPrepared The transaction has not yet been prepared.
294      * @exception SystemException An error occurred. The minor code indicates
295      * the reason for the exception.
296      *
297      * @see Resource
298      */

299     public void commit()
300         throws HeuristicRollback, HeuristicMixed, HeuristicHazard, NotPrepared,
301         SystemException {
302
303         // If no global identifier has been set up, we can do nothing.
304

305         if( globalTID == null ) {
306             INTERNAL exc = new INTERNAL(MinorCode.NoGlobalTID,
307                                         CompletionStatus.COMPLETED_NO);
308             throw exc;
309         }
310
311         // Commit operations should only come in for top-level transactions.
312

313         if( subtransaction ) {
314             INTERNAL exc = new INTERNAL(MinorCode.TopForSub,
315                                         CompletionStatus.COMPLETED_NO);
316             throw exc;
317         }
318
319         // If the transaction that this object represents has already been completed,
320
// raise a heuristic exception if necessary. This object must wait for a
321
// forget before destroying itself if it returns a heuristic exception.
322

323         if( completed ) {
324             if( aborted ) {
325                 heuristicDamage = true;
326                 HeuristicRollback exc = new HeuristicRollback();
327                 throw exc;
328             } else if( heuristicDamage ) {
329                 HeuristicMixed exc = new HeuristicMixed();
330                 throw exc;
331             }
332         } else {
333
334             // Look up the Coordinator for the transaction.
335

336             // GDH: First of all make sure it has been recovered if necessary
337
if(_logger.isLoggable(Level.FINE))
338         {
339             _logger.logp(Level.FINE,"CoordinatorResourceImpl","commit()",
340                     "Before invoking RecoveryManager.waitForRecovery():"+
341                     "GTID is: "+ globalTID.toString());
342
343         }
344             RecoveryManager.waitForRecovery();
345
346             TopCoordinator coord = (TopCoordinator)RecoveryManager.getCoordinator(globalTID);
347
348             // If there is a Coordinator, lock it for the duration of this operation.
349
// Tell the Coordinator to commit.
350
// If the Coordinator throws HeuristicMixed or HeuristicHazard,
351
// allow them to percolate to the caller.
352

353             if( coord != null )
354                 synchronized( coord ) {
355                     // GDH:
356
// Make sure the coordinator knows we are it's terminator
357
// (this is done here in case we are in a recovery situation)
358
// (the operation has been moved from the constructor of the
359
// this object to here as the constructor is now called
360
// to early to ensure the coordinator is present in all
361
// cases
362

363                     // GDH:
364
// If the transaction has completed at this point the
365
// makeSureSetAsTerminator method will be unable to
366
// set the coordinators terminator and will throw
367
// an object not exist exception: This is what we want in this case.
368

369                     makeSureSetAsTerminator();
370                     coord.commit();
371                 }
372         }
373
374         // If and we are not being forced, we can destroy ourselves before returning.
375
// Otherwise, the TopCoordinator will have called setCompleted to set up
376
// the information we need should a subsequent commit or rollback request
377
// arrive.
378

379         if( !beingForced )
380             destroy();
381
382     }
383
384     /**Informs the object that the transaction is to be committed in one phase.
385      * <p>
386      * Passes the superior Coordinator's single-phase commit request on to the
387      * Coordinator that registered the CoordinatorResourceImpl, using a private
388      * interface.
389      * <p>
390      * The result from the Coordinator is returned to the caller. If the
391      * Coordinator did not raise any heuristic exception, the CoordinatorResourceImpl
392      * destroys itself.
393      *
394      * @param
395      *
396      * @return
397      *
398      * @exception TRANSACTION_ROLLEDBACK The transaction could not be committed and
399      * has been rolled back.
400      * @exception HeuristicHazard One or more resources in the transaction may have
401      * rolled back.
402      * @exception SystemException An error occurred. The minor code indicates
403      * the reason for the exception.
404      *
405      * @see Resource
406      */

407     public void commit_one_phase()
408         throws TRANSACTION_ROLLEDBACK, HeuristicHazard, SystemException {
409
410         boolean rolledBack;
411
412
413         // If no global_identifier has been set up, we can do nothing.
414

415         if( globalTID == null ) {
416             INTERNAL exc = new INTERNAL(MinorCode.NoGlobalTID,
417                                         CompletionStatus.COMPLETED_NO);
418             throw exc;
419         }
420
421         // Commit operations should only come in for top-level transactions.
422

423         if( subtransaction ) {
424             INTERNAL exc = new INTERNAL(MinorCode.TopForSub,
425                                         CompletionStatus.COMPLETED_NO);
426             throw exc;
427         }
428
429         // If the transaction that this object represents has already been completed,
430
// raise an exception if necessary.
431

432         if( completed ) {
433             if( aborted ) {
434                 TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_NO);
435                 throw exc;
436             }
437         } else {
438
439             // Look up the Coordinator for the transaction.
440

441             // GDH: First of all make sure it has been recovered if necessary
442
if(_logger.isLoggable(Level.FINE))
443         {
444             _logger.logp(Level.FINE,"CoordinatorResourceImpl","commit_one_phase()",
445                     "Before invoking RecoveryManager.waitForRecovery(): "+
446                     "GTID is: " + globalTID.toString());
447         }
448             RecoveryManager.waitForRecovery();
449
450             TopCoordinator coord = (TopCoordinator)RecoveryManager.getCoordinator(globalTID);
451
452             // If there is a Coordinator, lock it for the duration of this operation.
453
// Tell the Coordinator to commit, by first doing a prepare.
454
// If the Coordinator throws HeuristicMixed or HeuristicHazard,
455
// allow them to percolate to the caller.
456

457             if( coord != null ) {
458                 rolledBack = false;
459
460                 synchronized( coord ) {
461
462                     // GDH:
463
// Make sure the coordinator knows we are it's terminator
464
// (this is done here in case we are in a recovery situation)
465
// (the operation has been moved from the constructor of the
466
// this object to here as the constructor is now called
467
// to early to ensure the coordinator is present in all
468
// cases
469
makeSureSetAsTerminator();
470
471                     // The prepare operation may throw the HeuristicHazard exception. In this case
472
// allow it to go back to the caller.
473

474                     Vote vote = Vote.VoteRollback;
475                     try {
476                         vote = coord.prepare();
477                     } catch( HeuristicMixed exc ) {
478                         throw new HeuristicHazard();
479                     }
480                     try {
481                         if( vote == Vote.VoteCommit )
482                             coord.commit();
483                         else if (vote == Vote.VoteRollback) {
484                             // COMMENT (Ram J) 12/11/2000 The above if check
485
// for rollback was added to avoid throwing a
486
// rollback exception for readonly votes.
487
coord.rollback(true);
488                             rolledBack = true;
489                         }
490                     } catch (Throwable JavaDoc exc) {
491                         // ADDED(Ram J) percolate any system exception
492
// back to the caller.
493
if (exc instanceof INTERNAL) {
494                             destroy();
495                             throw (INTERNAL) exc;
496                         }
497                     }
498                 }
499
500             } else {
501                 // coord is null
502
// We could still find no coord that matched even after recovery
503
// If there is still no coord then the process failed between
504
// deleting the subordinate coordinator and the result being received
505
// in the superior. As all of the recoverable work occurred in this
506
// server or in its subordinate servers (we are in cop), from a data integrity point of
507
// view, it does not matter what result the CoordinatorResource returns
508
// to the superior. However, the superior may still have a client attached
509
// and it would look strange if the transaction actually rolled back and
510
// the TRANSACTION_ROLLEDBACK exception was not reported to the client.
511
// Therefore we jump through hoops to give the best answer as possible.
512
// By delaying the call to forget_superior until CoordinatorResource's
513
// destructor we ensure the Coordinator and the CoordinatorResource are
514
// deleted together (as much as is possible in the JAVA/CORBA environment) and
515
// this occurs after the response has been sent to the superior (because
516
// the ORB is holding a reference count to the CoordinatorResource).
517
// Therefore, the most likely reason for this to occur is that the
518
// Coordinator was timed out (and removed) just before the server
519
// terminated. In this case, the transaction rolled back, which is the
520
// response that will be returned.
521

522                 rolledBack = true;
523
524             }
525
526             if( rolledBack ) {
527                 destroy();
528                 TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_YES);
529                 throw exc;
530             }
531         }
532
533         // Self-destruct before returning.
534

535         destroy();
536
537     }
538
539     /**Informs the object that the transaction is to be rolled back.
540      * <p>
541      * Passes the superior Coordinator's rollback request on to the Coordinator
542      * that registered the CoordinatorResourceImpl, using a private interface.
543      * <p>
544      * If the Coordinator does not raise any heuristic exception, the
545      * CoordinatorResourceImpl destroys itself.
546      *
547      * @param
548      *
549      * @return
550      *
551      * @exception HeuristicCommit The transaction has already been committed.
552      * @exception HeuristicMixed At least one participant in the transaction has
553      * committed its changes.
554      * @exception HeuristicHazard At least one participant in the transaction may
555      * have rolled back its changes.
556      * @exception SystemException An error occurred. The minor code indicates
557      * the reason for the exception.
558      *
559      * @see Resource
560      */
//----------------------------------------------------------------------------
561
public void rollback()
562              throws HeuristicCommit, HeuristicMixed,
563              HeuristicHazard, SystemException {
564
565              // If no global identifier has been set up, we can do nothing.
566

567              if( globalTID == null ) {
568                  INTERNAL exc = new INTERNAL(MinorCode.NoGlobalTID,
569                                              CompletionStatus.COMPLETED_NO);
570                  throw exc;
571              }
572
573              // Rollback operations should only come in for top-level transactions.
574

575              if( subtransaction ) {
576                  INTERNAL exc = new INTERNAL(MinorCode.TopForSub,
577                                              CompletionStatus.COMPLETED_NO);
578                  throw exc;
579              }
580
581              // If the transaction that this object represents has already been completed,
582
// raise a heuristic exception if necessary. This object must wait for a
583
// forget before destroying itself if it returns a heuristic exception.
584

585              if( completed ) {
586                  if( !aborted ) {
587                      heuristicDamage = true;
588                      HeuristicCommit exc = new HeuristicCommit();
589                      throw exc;
590                  }
591                  else if( heuristicDamage ) {
592                      HeuristicMixed exc = new HeuristicMixed();
593                      throw exc;
594                  }
595              } else {
596
597                  // Look up the Coordinator for the transaction.
598

599                  // GDH: First of all make sure it has been recovered if necessary
600
if(_logger.isLoggable(Level.FINE))
601             {
602                 _logger.logp(Level.FINE,"CoordinatorResourceImpl","rollback()",
603                         "Before invoking RecoveryManager.waitForRecovery(): "+
604                         "GTID is : "+ globalTID.toString());
605             
606             }
607                  RecoveryManager.waitForRecovery();
608
609                  TopCoordinator coord = (TopCoordinator)RecoveryManager.getCoordinator(globalTID);
610
611                  // If there is a Coordinator, lock it for the duration of this operation.
612
// Tell the Coordinator to rollback.
613
// If the Coordinator throws HeuristicMixed or HeuristicHazard,
614
// allow them to percolate to the caller.
615

616                  if( coord != null )
617                      synchronized( coord ) {
618
619                          // GDH:
620
// Make sure the coordinator knows we are it's terminator
621
// (this is done here in case we are in a recovery situation)
622
// (the operation has been moved from the constructor of the
623
// this object to here as the constructor is now called
624
// to early to ensure the coordinator is present in all
625
// cases
626
makeSureSetAsTerminator();
627                          coord.rollback(true);
628                      }
629              }
630
631              // If we are not being forced, we can destroy ourselves before returning.
632
// Otherwise, the TopCoordinator will have called set_completed to set up
633
// the information we need should a subsequent commit or rollback request
634
// arrive.
635

636              if( !beingForced )
637                  destroy();
638
639          }
640
641     /**Informs the object that the transaction is to be forgotten.
642      * <p>
643      * Informs the CoordinatorResourceImpl that it does not need to retain heuristic
644      * information any longer.
645      *
646      * @param
647      *
648      * @return
649      *
650      * @exception SystemException An error occurred. The minor code indicates
651      * the reason for the exception.
652      *
653      * @see
654      */

655     public void forget() throws SystemException {
656
657         // Forget operations should only come in for top-level transactions.
658

659         if( subtransaction ) {
660             INTERNAL exc = new INTERNAL(MinorCode.TopForSub,
661                                         CompletionStatus.COMPLETED_NO);
662             throw exc;
663         }
664
665         // If no exception is raised, we can destroy ourselves before returning.
666

667         destroy();
668     }
669
670     /**Informs the object that the subtransaction is to be committed.
671      * <p>
672      * Passes the superior Coordinator's commit request on to the SubCoordinator
673      * that registered the CoordinatorResourceImpl, using a private interface.
674      * <p>
675      * The result from the SubCoordinator is returned to the caller. The
676      * CoordinatorResourceImpl destroys itself.
677      *
678      * @param parent The parent Coordinator reference.
679      *
680      * @return
681      *
682      * @exception TRANSACTION_ROLLEDBACK The transaction could not be committed
683      * and some parts may have rolled back.
684      * @exception SystemException An error occurred. The minor code indicates
685      * the reason for the exception.
686      *
687      * @see
688      */

689     public void commit_subtransaction( Coordinator parent )
690         throws TRANSACTION_ROLLEDBACK, SystemException {
691
692         // If no global identifier has been set up, we can do nothing.
693

694         if( globalTID == null ) {
695             INTERNAL exc = new INTERNAL(MinorCode.NoGlobalTID,
696                                         CompletionStatus.COMPLETED_NO);
697             throw exc;
698         }
699
700         // Commit_subtransaction operations should only come in for subtransactions.
701

702         if( !subtransaction ) {
703             INTERNAL exc = new INTERNAL(MinorCode.SubForTop,
704                                         CompletionStatus.COMPLETED_NO);
705             throw exc;
706         }
707
708         // If the transaction that this object represents has already been rolled
709
// back, raise the TRANSACTION_ROLLEDBACK exception.
710

711         if( completed ) {
712             if( aborted ) {
713                 destroy();
714                 TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_YES);
715                 throw exc;
716             }
717         } else {
718
719             // Look up the Coordinator for the subtransaction.
720

721             SubCoordinator coord = (SubCoordinator)RecoveryManager.getCoordinator(globalTID);
722
723             // If there is a Coordinator, lock it for the duration of this operation.
724
// Tell the Coordinator to prepare then commit.
725
// Record then ignore any exceptions - we do not expect heuristics during
726
// subtransaction completion.
727

728             if( coord != null ) {
729                 boolean rolledBack = false;
730
731                 synchronized( coord ) {
732                     try {
733                         if( coord.prepare() == Vote.VoteCommit )
734                             coord.commit();
735                         else {
736                             coord.rollback(true);
737                             rolledBack = true;
738                         }
739                     }
740                     catch( Throwable JavaDoc ex ) {
741                     }
742                 }
743
744                 if( rolledBack ) {
745                     destroy();
746                     TRANSACTION_ROLLEDBACK exc = new TRANSACTION_ROLLEDBACK(0,CompletionStatus.COMPLETED_YES);
747                     throw exc;
748                 }
749             }
750         }
751
752         // Destroy ourselves before returning (there is no heuristic information for
753
// subtransactions).
754

755         destroy();
756
757     }
758
759     /**Informs the object that the subtransaction is to be rolled back.
760      * <p>
761      * Passes the superior Coordinator's rollback request on to the SubCoordinator
762      * that registered the CoordinatorResourceImpl, using a private interface.
763      * <p>
764      * The result from the SubCoordinator is returned to the caller. The
765      * CoordinatorResourceImpl destroys itself.
766      *
767      * @param
768      *
769      * @return
770      *
771      * @exception SystemException An error occurred. The minor code indicates
772      * the reason for the exception.
773      *
774      * @see
775      */

776
777     public void rollback_subtransaction() throws SystemException {
778
779         // If no global identifier has been set up, we can do nothing.
780

781         if( globalTID == null ) {
782             INTERNAL exc = new INTERNAL(MinorCode.NoGlobalTID,
783                                         CompletionStatus.COMPLETED_NO);
784             throw exc;
785         }
786
787         // Commit_subtransaction operations should only come in for subtransactions.
788

789         if( !subtransaction ) {
790             INTERNAL exc = new INTERNAL(MinorCode.SubForTop,
791                                         CompletionStatus.COMPLETED_NO);
792             throw exc;
793         }
794
795         // If the transaction that this object represents has already been completed,
796
// do nothing.
797

798         if( !completed ) {
799
800             // Look up the Coordinator for the transaction.
801

802             SubCoordinator coord = (SubCoordinator)RecoveryManager.getCoordinator(globalTID);
803
804             // If there is a Coordinator, lock it for the duration of this operation.
805
// Tell the Coordinator to rollback.
806

807             if( coord != null )
808                 synchronized( coord ) {
809                     coord.rollback(true);
810                 }
811         }
812
813         // Destroy ourselves before returning (there is no heuristic information for
814
// subtransactions).
815

816         destroy();
817
818     }
819
820     /**Creates the CoordinatorResourceImpl with the given key. This is done when
821      * the CoordinatorResource object is recreated after the server has been
822      * restarted.
823      *
824      * @param key The key for the object.
825      *
826      * @return
827      *
828      * @see
829      */

830     CoordinatorResourceImpl( byte[] key ) {
831
832         // Get the global transaction identifier from the key.
833

834         globalTID = new GlobalTID(key);
835
836         // GDH
837
// Ensure that recovery has completed so that we can get the Coordinator.
838
// This is now delayed until the 2PC methods for normal resync and is
839
// done as part of the superinfo.reconst
840

841         // RecoveryManager.waitForRecovery();
842

843         // Check that the global transaction identifier represents a known transaction.
844
// If it does not, then throw the OBJECT_NOT_EXIST exception.
845

846         // CoordinatorImpl coord = RecoveryManager.getCoordinator(globalTID);
847
// if( coord == null )
848
// {
849
// OBJECT_NOT_EXIST exc = new OBJECT_NOT_EXIST();
850
// if( trc != null ) trc.event(EVT_THROW).data(exc).write();
851
// throw exc;
852
// }
853

854         // If the transaction is known, then inform the Coordinator that this is the
855
// terminator for it.
856

857         // else
858
// coord.setTerminator(this);
859

860         // Leave other members at the default values.
861

862     }
863
864     /**Returns the CORBA Object which represents this object.
865      *
866      * @param
867      *
868      * @return The CORBA object.
869      *
870      * @see
871      */

872     CoordinatorResource object() {
873         if( thisRef == null ) {
874             if( poa == null ) {
875                 poa = Configuration.getPOA("CoordinatorResource"/*#Frozen*/);
876                 recoverable = Configuration.isRecoverable();
877             }
878
879             try {
880                 byte[] id = null;
881                 if (recoverable && globalTID != null) {
882                     id = globalTID.toBytes();
883                     poa.activate_object_with_id(id, this);
884                     org.omg.CORBA.Object JavaDoc obj = poa.create_reference_with_id(id, CoordinatorResourceHelper.id());
885                     thisRef = CoordinatorResourceHelper.narrow(obj);
886                     //thisRef = (CoordinatorResource) this;
887
} else {
888                     poa.activate_object(this);
889                     org.omg.CORBA.Object JavaDoc obj = poa.servant_to_reference(this);
890                     thisRef = CoordinatorResourceHelper.narrow(obj);
891                     //thisRef = (CoordinatorResource) this;
892
}
893             } catch( ServantAlreadyActive JavaDoc saexc ) {
894                 _logger.log(Level.SEVERE,
895                         "jts.create_CoordinatorResource_object_error",saexc);
896                 String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
897                                          "jts.create_CoordinatorResource_object_error");
898                 throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
899                         
900             } catch( ServantNotActive JavaDoc snexc ) {
901                 _logger.log(Level.SEVERE,
902                         "jts.create_CoordinatorResource_object_error",snexc);
903                 String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
904                                          "jts.create_CoordinatorResource_object_error");
905                 throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
906                         
907             } catch( Exception JavaDoc exc ) {
908                 _logger.log(Level.SEVERE,
909                         "jts.create_CoordinatorResource_object_error",exc);
910                 String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
911                                          "jts.create_CoordinatorResource_object_error");
912                 throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
913                         
914             }
915         }
916
917         return thisRef;
918     }
919
920     /**Destroys the CoordinatorResourceImpl object.
921      *
922      * @param
923      *
924      * @return
925      *
926      * @see
927      */

928     void destroy() {
929
930         try {
931             if (poa != null && thisRef != null) {
932                 poa.deactivate_object(poa.reference_to_id(thisRef));
933                 thisRef = null;
934             } else {
935                 // BUGFIX(Ram J) It is possible that the
936
// CoordinatorResource object was activated via the activation
937
// daemon. In that case, there is no guarantee
938
// that poa and thisRef are set to a meaningful value.
939
// So, try to deactivate the CoordinatorResource object anyway.
940

941                 POA crPoa = null;
942                 if (poa == null) {
943                     crPoa = Configuration.getPOA("CoordinatorResource"/*#Frozen*/);
944                 } else {
945                     crPoa = poa;
946                 }
947                 if (thisRef == null) {
948                     crPoa.deactivate_object(crPoa.servant_to_id(this));
949                 } else {
950                     crPoa.deactivate_object(crPoa.reference_to_id(thisRef));
951                     thisRef = null;
952                 }
953             }
954         } catch( Exception JavaDoc exc ) {
955              _logger.log(Level.WARNING,"jts.object_destroy_error","CoordinatorResource");
956                 
957         }
958
959         finalize();
960     }
961
962     /**Dumps the state of the object.
963      *
964      * @param
965      *
966      * @return
967      *
968      * @see
969      */

970     void dump() {
971     }
972
973     /**Makes sure this object is set as the Coordinator Terminator
974      *
975      * @param
976      *
977      * @return
978      *
979      * @see
980      */

981     void makeSureSetAsTerminator() {
982
983         if( !setAsTerminator ) {
984
985             CoordinatorImpl coord = RecoveryManager.getCoordinator(globalTID);
986
987             // If the transaction is not known then throw an exception,
988
// otherwise inform the Coordinator that this is the
989
// terminator for it.
990

991             if( coord == null ) {
992                 OBJECT_NOT_EXIST exc = new OBJECT_NOT_EXIST();
993                 throw exc;
994             } else {
995                 coord.setTerminator(this);
996                 setAsTerminator = true;
997             }
998         }
999
1000    } // MakeSureSetAsTerminator method
1001

1002    } // class
1003

1004
Popular Tags