KickJava   Java API By Example, From Geeks To Geeks.

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


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: CoordinatorImpl.java
31
//
32
// Description: Transaction Coordinator base object implementation.
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 java.util.*;
55
56 import org.omg.CORBA.*;
57 import org.omg.PortableServer.*;
58 import org.omg.CosTransactions.*;
59
60 import com.sun.jts.otsidl.*;
61 import java.util.logging.Logger JavaDoc;
62 import java.util.logging.Level JavaDoc;
63 import com.sun.logging.LogDomains;
64 import com.sun.jts.utils.LogFormatter;
65
66 /**The CoordinatorImpl interface is an extension to the standard Coordinator
67  * interface that provides the common operations for top-level transactions and
68  * subtransactions. It is used as a common superclass for the TopCoordinator and
69  * SubCoordinator classes, and has no implementation.
70  *
71  * @version 0.01
72  *
73  * @author Simon Holdsworth, IBM Corporation
74  *
75  * @see
76 */

77 //----------------------------------------------------------------------------
78
// CHANGE HISTORY
79
//
80
// Version By Change Description
81
// 0.01 SAJH Initial implementation.
82
//-----------------------------------------------------------------------------
83

84 abstract class CoordinatorImpl extends JCoordinatorPOA implements JCoordinator {
85
86     /**Reply action value indicating nothing should be done to the transaction.
87      */

88     static final int doNothing = 1;
89
90     /**Reply action value indicating that the transaction should be forgotten.
91      */

92     static final int forgetMe = 2;
93
94     /**Reply action value indicating that the transaction has active children.
95      */

96     static final int activeChildren = 3;
97
98     /**OMG Coordinator operation required of all subclasses.
99      */

100     public abstract Status get_status();
101
102     /**OMG Coordinator operation required of all subclasses.
103      */

104     public abstract Status get_parent_status();
105
106     /**OMG Coordinator operation required of all subclasses.
107      */

108     public abstract Status get_top_level_status();
109
110     /**OMG Coordinator operation required of all subclasses.
111      */

112     public abstract boolean is_same_transaction( Coordinator other );
113
114     /**OMG Coordinator operation required of all subclasses.
115      */

116     public abstract boolean is_related_transaction( Coordinator other );
117
118     /**OMG Coordinator operation required of all subclasses.
119      */

120     public abstract boolean is_ancestor_transaction( Coordinator other );
121
122     /**OMG Coordinator operation required of all subclasses.
123      */

124     public abstract boolean is_descendant_transaction( Coordinator other );
125
126     /**OMG Coordinator operation required of all subclasses.
127      */

128     public abstract boolean is_top_level_transaction();
129
130     /**OMG Coordinator operation required of all subclasses.
131      */

132     public abstract int hash_transaction();
133
134     /**OMG Coordinator operation required of all subclasses.
135      */

136     public abstract int hash_top_level_tran();
137     /*
138         Logger to log transaction messages
139     */

140     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER);
141
142     /**OMG Coordinator operation required of all subclasses.
143      *
144      * @exception Inactive The Coordinator is completing the transaction and
145      * cannot accept this registration.
146      */

147     public abstract RecoveryCoordinator register_resource( Resource res )
148         throws Inactive;
149
150     /**OMG Coordinator operation required of all subclasses.
151      *
152      * @exception NotSubtransaction The Coordinator represents a top-level
153      * transaction and cannot accept the registration.
154      * @exception Inactive The Coordinator is completing the transaction and
155      * cannot accept this registration.
156      */

157     public abstract
158         void register_subtran_aware( SubtransactionAwareResource sares )
159         throws Inactive, NotSubtransaction;
160
161     /**OMG Coordinator operation required of all subclasses.
162      *
163      * @exception Inactive The Coordinator is already completing the transaction.
164      */

165     public abstract void rollback_only()
166         throws Inactive;
167
168     /**OMG Coordinator operation required of all subclasses.
169      */

170     public abstract String JavaDoc get_transaction_name();
171
172     /**OMG Coordinator operation required of all subclasses.
173      *
174      * @exception Inactive The Coordinator is completing the transaction and
175      * cannot create a new child.
176      * @exception SubtransactionsUnavailable Subtransactions are not available.
177      */

178     public abstract Control create_subtransaction()
179         throws Inactive, SubtransactionsUnavailable;
180
181     /**OMG Coordinator operation required of all subclasses.
182      *
183      * @exception Inactive The Coordinator is completing the transaction and
184      * cannot accept the registration.
185      * @exception SynchronizationUnavailable Synchronization is not supported.
186      */

187     public abstract void register_synchronization( Synchronization sync )
188         throws Inactive, SynchronizationUnavailable;
189
190     /**OMG Coordinator operation required of all subclasses.
191      *
192      * @exception Inactive The Coordinator is completing the transaction.
193      */

194     public abstract PropagationContext get_txcontext()
195         throws Unavailable;
196
197     /**IDL JCoordinator operation required of all subclasses.
198      *
199      * @exception Unavailable The global transaction identifier is not available.
200      */

201     public abstract otid_t getGlobalTID();
202
203     /**IDL JCoordinator operation required of all subclasses.
204      */

205     public abstract long getLocalTID();
206
207     /**IDL JCoordinator operation required of all subclasses.
208      */

209     public abstract TransIdentity[] getAncestors();
210
211     /**IDL JCoordinator operation required of all subclasses.
212      */

213     public abstract boolean isRollbackOnly();
214
215     /**Add the given Coordinator reference to the set of children of the target
216      * object.
217      */

218     abstract boolean addChild( CoordinatorImpl child );
219
220     /**Remove the given Coordinator reference from the set of children. If the
221      * target object is temporary, and no longer has any children or registered
222      * resources, it destroys itself before returning.
223      */

224     abstract boolean removeChild( CoordinatorImpl child );
225
226     /**Direct the CoordinatorImpl to prepare to commit. If there are active
227      * subtransactions, the operation raises the INVALID_TRANSACTION standard
228      * exception. Otherwise the CoordinatorImpl directs all registered Resources to
229      * prepare, and returns the consolidated result to the caller. The
230      * CoordinatorImpl must guarantee that each Resource object registered with it
231      * receives at most one prepare request (This includes the case where the
232      * Recoverable Server registers the same Resource twice).
233      *
234      * @exception INVALID_TRANSACTION Indicates that the transaction may not be
235      * committed due to outstanding work.
236      * @exception HeuristicMixed Indicates that a participant voted to roll the
237      * transaction back, but one or more others have already heuristically committed.
238      * @exception HeuristicHazard Indicates that a participant voted to roll the
239      * transaction back, but one or more others may have already heuristically
240      * committed.
241      */

242     abstract Vote prepare()
243         throws INVALID_TRANSACTION, HeuristicMixed, HeuristicHazard;
244
245     /**Direct the CoordinatorImpl to commit. The CoordinatorImpl directs all
246      * registered Resources to commit. Those Resources that raised heuristic
247      * exceptions are subsequently told to forget the transaction. If there are
248      * no registered Synchronization objects, and the CoordinatorImpl is not the
249      * root, it removes itself from the TransactionManager associations and
250      * destroys itself before returning.
251      *
252      * @exception HeuristicMixed Indicates that heuristic decisions have been
253      * taken which have resulted in part of the transaction being rolled back.
254      * @exception HeuristicHazard Indicates that heuristic decisions may have been
255      * taken which have resulted in part of the transaction being rolled back.
256      * @exception NotPrepared Indicates that the transaction has not been prepared.
257      */

258     abstract void commit()
259         throws HeuristicMixed, HeuristicHazard, NotPrepared;
260
261     /**Direct the CoordinatorImpl to commit in one phase if possible. If the
262      * coordinator has a single resource registered it will flow the
263      * commit_one_phase mehtod to it, if it has >1 resource the method will
264      * return false indicating two phase commit is required.
265      * Other than that the method behaves as commit.
266      *
267      * @exception HeuristicMixed Indicates that heuristic decisions have been
268      * taken which have resulted in part of the transaction being rolled back.
269      * @exception HeuristicHazard Indicates that heuristic decisions may have been
270      * taken which have resulted in part of the transaction being rolled back.
271      */

272     abstract boolean commitOnePhase()
273         throws HeuristicMixed, HeuristicHazard;
274
275     /**Direct the CoordinatorImpl to rollback the transaction. It directs every
276      * registered Resource to rollback. Those Resources that raised heuristic
277      * exceptions are subsequently told to forget the transaction. If there are
278      * no registered Synchronization objects, the CoordinatorImpl removes itself
279      * from the TransactionManager associations and destroys itself before
280      * returning.
281      * If force is TRUE, the coordinator is rolled back even if this could compromise
282      * data integrity (i.e. even if the coordinator is prepared). If force is FALSE,
283      * no attempt is made to roll back the coordinator if it is prepared and FALSE
284      * is returned from the method.
285      *
286      * @exception HeuristicMixed Indicates that heuristic decisions have been
287      * taken which have resulted in part of the transaction being rolled back.
288      * @exception HeuristicHazard Indicates that heuristic decisions may have been
289      * taken which have resulted in part of the transaction being rolled back.
290      */

291     abstract void rollback( boolean force )
292         throws HeuristicMixed, HeuristicHazard;
293
294     /**Inform the CoordinatorImpl of an imminent reply. If the CoordinatorImpl has
295      * active children, it returns activeChildren. If the CoordinatorImpl has
296      * already been registered, the operation returns doNothing. Otherwise the
297      * CoordinatorImpl returns forgetMe, and the output parameter is set to the
298      * parent CoordinatorImpl, if any.
299      */

300     abstract CoordinatorImpl replyAction( int[/*1*/] action )
301         throws SystemException;
302
303     /**Inform the CoordinatorImpl that it is no longer a temporary construct.
304      * This is used when a request is received for an CoordinatorImpl that was
305      * created as a temporary ancestor of a subtransaction.
306      */

307     abstract Long JavaDoc setPermanent();
308
309     /**Return a boolean value indicating whether the CoordinatorImpl is in an
310      * active state (i.e. not preparing or later states).
311      */

312     abstract boolean isActive();
313
314     /**Return a boolean value indicating whether the CoordinatorImpl has registered
315      * with its superior (if any).
316      */

317     abstract boolean hasRegistered();
318
319     /**Record the object that is normally responsible for directing the
320      * CoordinatorImpl through termination. For a root CoordinatorImpl, this is a
321      * CoordinatorTerm object; for a subordinate it is a CoordinatorResource.
322      */

323     abstract void setTerminator( CompletionHandler terminator );
324
325     /**Return the parent coordinator.
326      */

327     abstract Coordinator getParent();
328
329     /**Return the superior coordinator.
330      */

331     abstract Coordinator getSuperior();
332
333     /**Returns the object normally responsible for terminating the transaction.
334      */

335     abstract CompletionHandler getTerminator();
336
337     /**Cleans up an empty Coordinator object which was created temporarily for a
338      * read-only transactional request.
339      */

340     abstract void cleanUpEmpty( CoordinatorImpl forgetParent );
341
342     /**Clean up the state of the object.
343      */

344     public abstract void finalize();
345
346     private static POA poa = null;
347     private Coordinator thisRef = null;
348
349     /**Returns a CORBA object which represents the transaction.
350      */

351     synchronized final Coordinator object() {
352         if( thisRef == null ) {
353             if( poa == null )
354                 poa = Configuration.getPOA("Coordinator"/*#Frozen*/);
355
356             try {
357                 poa.activate_object(this);
358                 thisRef = CoordinatorHelper.narrow(poa.servant_to_reference(this));
359             } catch( Exception JavaDoc exc ) {
360                 _logger.log(Level.SEVERE,"jts.create_coordinator_object_error",exc);
361                 String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
362                                         "jts.create_coordinator_object_error");
363                 throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
364             }
365         }
366
367         return thisRef;
368     }
369
370     /**Returns the CoordinatorImpl which serves the given object.
371      */

372     synchronized static final CoordinatorImpl servant( Coordinator coord ) {
373         CoordinatorImpl result = null;
374
375         if( coord instanceof CoordinatorImpl )
376             result = (CoordinatorImpl)coord;
377         else if( poa != null ) {
378             JCoordinator jcoord = JCoordinatorHelper.narrow(coord);
379             if( jcoord != null )
380                 try {
381                     result = (CoordinatorImpl)poa.reference_to_servant(jcoord);
382                     if( result.thisRef == null )
383                         result.thisRef = jcoord;
384                 } catch( Exception JavaDoc exc ) {
385                     _logger.log(Level.WARNING,"jts.cannot_locate_servant","Coordinator");
386                 }
387         }
388
389         return result;
390     }
391
392     /**Destroys the CoordinatorImpl object reference.
393      */

394     synchronized final void destroy() {
395         if( poa != null && thisRef != null )
396             try {
397                 poa.deactivate_object(poa.reference_to_id(thisRef));
398                 thisRef = null;
399             } catch( Exception JavaDoc exc ) {
400                 _logger.log(Level.WARNING,"jts.object_destroy_error","Coordinator");
401             }
402     }
403
404     /*
405      * These methods are there to satisy the compiler. At some point
406      * when we move towards a tie based model, the org.omg.Corba.Object
407      * interface method implementation below shall be discarded.
408      */

409
410     private static org.omg.CORBA.NO_IMPLEMENT JavaDoc no_implement =
411         new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
412
413
414     public org.omg.CORBA.Object JavaDoc _duplicate() {
415         throw no_implement;
416     }
417
418     public void _release() {
419         throw no_implement;
420     }
421
422     public boolean _is_a(String JavaDoc repository_id) {
423         throw no_implement;
424     }
425
426     public boolean _is_equivalent(org.omg.CORBA.Object JavaDoc that) {
427         throw no_implement;
428     }
429
430     public boolean _non_existent() {
431         throw no_implement;
432     }
433
434     public int _hash(int maximum) {
435         throw no_implement;
436     }
437
438     public Request _request(String JavaDoc operation) {
439         throw no_implement;
440     }
441
442     public Request _create_request(Context ctx,
443                    String JavaDoc operation,
444                    NVList arg_list,
445                    NamedValue result) {
446         throw no_implement;
447     }
448
449     public Request _create_request(Context ctx,
450                    String JavaDoc operation,
451                    NVList arg_list,
452                    NamedValue result,
453                    ExceptionList exceptions,
454                    ContextList contexts) {
455         throw no_implement;
456     }
457
458     public org.omg.CORBA.Object JavaDoc _get_interface_def() {
459         throw no_implement;
460     }
461
462     public org.omg.CORBA.Policy JavaDoc _get_policy(int policy_type) {
463         throw no_implement;
464     }
465
466     public org.omg.CORBA.DomainManager JavaDoc[] _get_domain_managers() {
467         throw no_implement;
468     }
469
470     public org.omg.CORBA.Object JavaDoc _set_policy_override(
471             org.omg.CORBA.Policy JavaDoc[] policies,
472             org.omg.CORBA.SetOverrideType JavaDoc set_add) {
473         throw no_implement;
474     }
475 }
476
Popular Tags