KickJava   Java API By Example, From Geeks To Geeks.

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


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
//
31
// Module: Terminator.java
32
//
33
// Description: Transaction Terminator object implementation.
34
//
35
// Product: com.sun.jts.CosTransactions
36
//
37
// Author: Simon Holdsworth
38
//
39
// Date: March, 1997
40
//
41
// Copyright (c): 1995-1997 IBM Corp.
42
//
43
// The source code for this program is not published or otherwise divested
44
// of its trade secrets, irrespective of what has been deposited with the
45
// U.S. Copyright Office.
46
//
47
// This software contains confidential and proprietary information of
48
// IBM Corp.
49
//----------------------------------------------------------------------------
50

51 package com.sun.jts.CosTransactions;
52
53 import org.omg.CORBA.*;
54 import org.omg.PortableServer.*;
55 import org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc;
56 import org.omg.PortableServer.POAPackage.ServantNotActive JavaDoc;
57 import org.omg.CosTransactions.*;
58 import java.util.logging.Logger JavaDoc;
59 import java.util.logging.Level JavaDoc;
60 import com.sun.logging.LogDomains;
61 import com.sun.jts.utils.LogFormatter;
62 /**
63  * The TerminatorImpl interface is our implementation of the
64  * standard Terminator
65  * interface. It provides operations to complete a transaction, either
66  * requesting commitment, or demanding rollback. The TerminatorImpl in this
67  * design should be a pseudo-object, as we do not want its reference to be
68  * passed to other processes, and we always want it to be created locally.
69  *
70  * @version 0.01
71  *
72  * @author Simon Holdsworth, IBM Corporation
73  *
74  * @see
75 */

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

84 class TerminatorImpl extends TerminatorPOA implements Terminator JavaDoc {
85
86     private static POA poa = null;
87     private org.omg.CosTransactions.Terminator thisRef = null;
88
89     CoordinatorTerm coordTerm = null;
90
91     // this is needed to cleanup properly on completion and to avoid leaks.
92
ControlImpl control = null;
93     /*
94         Logger to log transaction messages
95     */

96     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER);
97     /**
98      * Default TerminatorImpl constructor.
99      *
100      * @param
101      *
102      * @return
103      *
104      * @see
105      */

106     TerminatorImpl() {}
107
108     /**
109      * Creates and initialises a new TerminatorImpl, given the Coordinator
110      * object for the transaction, and a flag to indicate whether the
111      * TerminatorImpl represents a subtransaction.
112      *
113      * @param coordinator The Coordinator for the transaction.
114      * @param subtran A flag indicating whether the transaction is a child.
115      *
116      * @return
117      *
118      * @see
119      */

120     TerminatorImpl (CoordinatorImpl coordinator, boolean subtran) {
121
122         // Initialise the instance variables.
123

124          coordTerm = new CoordinatorTerm(coordinator, subtran);
125     }
126
127     /**
128      * sets the control object that points to this terminator.
129      *
130      * @param control the control object this terminator belongs to.
131      */

132      void setControl(ControlImpl control) {
133         /* This method has been newly added (Ram J) */
134         this.control = control;
135      }
136
137     /**
138      * Cleans up the state of the object.
139      *
140      * @param
141      *
142      * @return
143      *
144      * @see
145      */

146     synchronized public void finalize() {
147
148         if (coordTerm != null) {
149             coordTerm.finalize();
150             coordTerm = null;
151         }
152     }
153
154     /**
155      * This implements the checked behaviour for threads calling
156      * the terminator object's completion methods directly.
157      */

158     private void PreCompletionCheck()
159         throws TRANSACTION_ROLLEDBACK, INVALID_TRANSACTION {
160
161         /* This method has been newly added (Ram J) */
162
163         StatusHolder status = new StatusHolder();
164         Long JavaDoc localTID = new Long JavaDoc(control.getLocalTID(status));
165
166         // check if the transaction is active, else throw exception
167

168         if (status.value != Status.StatusActive) {
169
170             if( status.value == Status.StatusRolledBack) {
171                 TRANSACTION_ROLLEDBACK exc =
172                     new TRANSACTION_ROLLEDBACK(0,
173                                                CompletionStatus.COMPLETED_NO);
174                 throw exc;
175             }
176
177             INVALID_TRANSACTION exc =
178                 new INVALID_TRANSACTION(MinorCode.Completed,
179                                         CompletionStatus.COMPLETED_NO);
180             throw exc;
181         }
182
183         // check if there is no outstanding requests, else throw exception
184
// CHECK(Ram J) should a check for active thread associations
185
// be done here as well ??
186
if (control.isOutgoing()) {
187
188             INVALID_TRANSACTION exc =
189                 new INVALID_TRANSACTION(MinorCode.DeferredActivities,
190                                         CompletionStatus.COMPLETED_NO);
191             throw exc;
192         }
193     }
194
195     /**
196      * Requests that the transaction controlled by the Terminator object be
197      * committed.
198      * The commit is passed on the the CoordinatorTerm object. If the heuristic
199      * report flag is set, any heuristic exception raised by the
200      * root Coordinator is returned to the caller,
201      * otherwise any heuristic exception is discarded.
202      *
203      * This operation is part of the OMG interface and must not return
204      * any exceptions other than those defined in the OMG interface.
205       *
206      * @param reportHeuristics Indicates whether heuristic exceptions
207      * should be passed to the caller.
208      *
209      * @return
210      *
211      * @exception HeuristicHazard Heuristic action may have been taken by a
212      * participant in the transaction.
213      * @exception HeuristicMixed Heuristic action has been
214      * taken by a participant in the transaction so part
215      * of the transaction has been rolled back.
216      * @exception SystemException The operation failed.
217      *
218      * @see
219      */

220     synchronized public void commit(boolean reportHeuristics)
221         throws HeuristicMixed, HeuristicHazard, TRANSACTION_ROLLEDBACK {
222
223         // for checked transaction behaviour (Ram J)
224
PreCompletionCheck();
225
226         // Try to commit the transaction. If the client does not want a
227
// heuristic report, then the transaction can be completed promptly.
228

229         // If the client does not want heuristic reporting, and an
230
// exception was raised, and it is a Heuristic exception, forget it.
231
// Any other exception that is raised is returned to the client.
232

233         try {
234             coordTerm.commit(!reportHeuristics);
235         } catch (HeuristicMixed exc) {
236             if (reportHeuristics) {
237                 control.destroy(); // added (Ram J) for memory Leak fix
238
throw exc;
239             }
240         } catch (HeuristicHazard exc) {
241             if (reportHeuristics) {
242                 control.destroy(); // added (Ram J) for memory Leak fix
243
throw exc;
244             }
245         } catch (TRANSACTION_ROLLEDBACK exc) {
246             control.destroy(); // added (Ram J) for memory Leak fix
247
throw exc;
248         } catch(LogicErrorException exc) {
249             control.destroy(); // added (Ram J) for memory Leak fix
250
INTERNAL ex2 = new INTERNAL(MinorCode.LogicError,
251                                         CompletionStatus.COMPLETED_NO);
252             throw ex2;
253         } catch (INTERNAL exc) { // added (Ram J) percolate up system excs
254
control.destroy();
255             throw (INTERNAL) exc;
256         }
257
258         control.destroy(); // added (Ram J) for memory Leak fix
259
}
260
261     /**
262      * Demands that the transaction represented by the Terminator object
263      * be rolled back.
264      * No heuristics are reported by this operation so if the root Coordinator
265      * raises a heuristic exception, it is cleared before the operation
266      * returns to the caller.
267      *
268      * This operation is part of the OMG interface and must not return
269      * any exceptions other than those defined in the OMG interface.
270      *
271      * @param
272      *
273      * @return
274      *
275      * @exception SystemException The operation failed.
276      *
277      * @see
278      */

279     public void rollback() throws SystemException {
280
281         // for checked transaction behaviour (Ram J)
282
PreCompletionCheck();
283
284         // Roll the transaction back.
285
// If a Heuristic exception was raised, forget it.
286
// Any other exception that is raised is returned to the client.
287

288         try {
289             coordTerm.rollback();
290         } catch (HeuristicMixed exc) {
291             control.destroy(); // added (Ram J) for memory Leak fix
292
} catch (HeuristicHazard exc) {
293             control.destroy(); // added (Ram J) for memory Leak fix
294
} catch (TRANSACTION_ROLLEDBACK exc) {
295             control.destroy(); // added (Ram J) for memory Leak fix
296
throw exc;
297         } catch (LogicErrorException exc) {
298             control.destroy(); // added (Ram J) for memory Leak fix
299
INTERNAL ex2 = new INTERNAL(MinorCode.LogicError,
300                                         CompletionStatus.COMPLETED_NO);
301             throw ex2;
302         } catch (INTERNAL exc) { // added (Ram J) percolate up system excs
303
control.destroy();
304             throw (INTERNAL) exc;
305         }
306
307         control.destroy(); // added (Ram J) for memory Leak fix
308

309     }
310
311     /**
312      * Returns the CORBA Object which represents this object.
313      *
314      * @param
315      *
316      * @return The CORBA object.
317      *
318      * @see
319      */

320     synchronized final Terminator JavaDoc object() {
321         if (thisRef == null) {
322             if (poa == null) {
323                 poa = Configuration.getPOA("transient"/*#Frozen*/);
324             }
325
326             try {
327                 poa.activate_object(this);
328                 thisRef =
329                     TerminatorHelper.narrow(poa.servant_to_reference(this));
330                 //thisRef = (Terminator) this;
331
} catch(ServantAlreadyActive JavaDoc saexc) {
332                 _logger.log(Level.SEVERE,"jts.create_terminator_object_error",saexc);
333                 String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
334                                          "jts.create_terminator_object_error");
335                 throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
336             } catch(ServantNotActive JavaDoc snexc) {
337                 _logger.log(Level.SEVERE,"jts.create_terminator_object_error",snexc);
338                 String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
339                                          "jts.create_terminator_object_error");
340                 throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
341             } catch(Exception JavaDoc exc) {
342                 _logger.log(Level.SEVERE,"jts.create_terminator_object_error",exc);
343                 String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
344                                          "jts.create_terminator_object_error");
345                 throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
346             }
347         }
348
349         return thisRef;
350     }
351
352     /**
353      * Destroys the TerminatorImpl object.
354      *
355      * @param
356      *
357      * @return
358      *
359      * @see
360      */

361     synchronized final void destroy() {
362         if (poa != null && thisRef != null) {
363             try {
364                 poa.deactivate_object(poa.reference_to_id(thisRef));
365                 thisRef = null;
366             } catch (Exception JavaDoc exc) {
367                 _logger.log(Level.WARNING,"jts.object_destroy_error","Terminator");
368             }
369         }
370
371         finalize();
372     }
373
374     /*
375      * These methods are there to satisy the compiler. At some point
376      * when we move towards a tie based model, the org.omg.Corba.Object
377      * interface method implementation below shall be discarded.
378      */

379
380     public org.omg.CORBA.Object JavaDoc _duplicate() {
381         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
382     }
383
384     public void _release() {
385         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
386     }
387
388     public boolean _is_a(String JavaDoc repository_id) {
389         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
390     }
391
392     public boolean _is_equivalent(org.omg.CORBA.Object JavaDoc that) {
393         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
394     }
395
396     public boolean _non_existent() {
397         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
398     }
399
400     public int _hash(int maximum) {
401         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
402     }
403
404     public Request _request(String JavaDoc operation) {
405         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
406     }
407
408     public Request _create_request(Context ctx,
409                    String JavaDoc operation,
410                    NVList arg_list,
411                    NamedValue result) {
412         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
413     }
414
415     public Request _create_request(Context ctx,
416                    String JavaDoc operation,
417                    NVList arg_list,
418                    NamedValue result,
419                    ExceptionList exceptions,
420                    ContextList contexts) {
421         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
422     }
423
424     public org.omg.CORBA.Object JavaDoc _get_interface_def() {
425         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
426     }
427
428     public org.omg.CORBA.Policy JavaDoc _get_policy(int policy_type) {
429         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
430     }
431
432     public org.omg.CORBA.DomainManager JavaDoc[] _get_domain_managers() {
433         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
434     }
435
436     public org.omg.CORBA.Object JavaDoc _set_policy_override(
437             org.omg.CORBA.Policy JavaDoc[] policies,
438             org.omg.CORBA.SetOverrideType JavaDoc set_add) {
439         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc("This is a locally constrained object.");
440     }
441 }
442
Popular Tags