KickJava   Java API By Example, From Geeks To Geeks.

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


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: CoordinatorSynchronizationImpl.java
31
//
32
// Description: Subordinate Coordinator synchronization 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 java.util.logging.Logger JavaDoc;
61 import java.util.logging.Level JavaDoc;
62 import com.sun.logging.LogDomains;
63 import com.sun.jts.utils.LogFormatter;
64
65 /**The CoordinatorSynchronizationImpl interface allows a subordinate Coordinator
66  * to be informed of the completion of a transaction, both before the transaction
67  * is prepared, and after it is committed or rolled back. Every
68  * Synchronization object registered with the subordinate should be called
69  * before the operation returns to the superior. An instance of this class
70  * should be accessed from only one thread within a process.
71  *
72  * @version 0.01
73  *
74  * @author Simon Holdsworth, IBM Corporation
75  *
76  * @see
77 */

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

85 class CoordinatorSynchronizationImpl extends SynchronizationPOA {
86
87     private static POA poa = null;
88     private Synchronization thisRef = null;
89
90     private Long JavaDoc localTID = null;
91     private TopCoordinator coordinator = null;
92     /*
93         Logger to log transaction messages
94     */

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

105     CoordinatorSynchronizationImpl() {
106     }
107
108     /**Sets up a new CoordinatorSynchronizationImpl object with the Coordinator reference so
109      * that it can pass on synchronization requests.
110      *
111      * @param coord The Coordinator for the transaction.
112      *
113      * @return
114      *
115      * @see
116      */

117     CoordinatorSynchronizationImpl( TopCoordinator coord ) {
118
119         // Set the instance variables to the values passed in.
120

121         coordinator = coord;
122         try {
123             localTID = new Long JavaDoc(coord.getLocalTID());
124         } catch( SystemException exc ) {}
125
126     }
127
128     /**Cleans up the objects state.
129      *
130      * @param
131      *
132      * @return
133      *
134      * @see
135      */

136     public void finalize() {
137
138         coordinator = null;
139
140     }
141
142     /**Passes on the before completion operation to the Coordinator.
143      *
144      * @param
145      *
146      * @return
147      *
148      * @exception SystemException The operation failed. The minor code provides
149      * a reason for the failure.
150      *
151      * @see
152      */

153     public void before_completion()
154         throws SystemException {
155
156         // If there is no Coordinator reference, raise an exception.
157

158         if( coordinator == null ) {
159             INTERNAL exc = new INTERNAL(MinorCode.NoCoordinator,
160                                         CompletionStatus.COMPLETED_NO);
161             throw exc;
162         }
163
164         // Pass the before completion operation on to the coordinator.
165

166         coordinator.beforeCompletion();
167
168     }
169
170     /**Passes on the after completion operation to the Coordinator.
171      *
172      * @param status The state of the transaction.
173      *
174      * @return
175      *
176      * @exception SystemException The operation failed. The minor code provides
177      * a reason for the failure.
178      *
179      * @see
180      */

181     public void after_completion( Status status )
182         throws SystemException {
183
184         // If there is no Coordinator reference, raise an exception.
185

186         if( coordinator == null ) {
187             INTERNAL exc = new INTERNAL(MinorCode.NoCoordinator,
188                                         CompletionStatus.COMPLETED_NO);
189             throw exc;
190         }
191
192         // Pass the after completion operation on to the coordinator.
193
// Destroy myself.
194

195         coordinator.afterCompletion(status);
196         destroy();
197
198     }
199
200     /**Returns the CORBA Object which represents this object.
201      *
202      * @param
203      *
204      * @return The CORBA object.
205      *
206      * @see
207      */

208     Synchronization object() {
209         if( poa == null ) poa = Configuration.getPOA("transient"/*#Frozen*/);
210         if( thisRef == null ) {
211             if( poa == null )
212                 poa = Configuration.getPOA("transient"/*#Frozen*/);
213
214             try {
215                 poa.activate_object(this);
216                 thisRef = SynchronizationHelper.
217                             narrow(poa.servant_to_reference(this));
218                 //thisRef = (Synchronization)this;
219
} catch( ServantAlreadyActive JavaDoc saexc ) {
220                 _logger.log(Level.SEVERE,
221                         "jts.create_CoordinatorSynchronization_object_error");
222                  String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
223                               "jts.create_CoordinatorSynchronization_object_error");
224                   throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
225             } catch( ServantNotActive JavaDoc snexc ) {
226                 _logger.log(Level.SEVERE,
227                         "jts.create_CoordinatorSynchronization_object_error");
228                  String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
229                               "jts.create_CoordinatorSynchronization_object_error");
230                   throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
231             } catch( Exception JavaDoc exc ) {
232                 _logger.log(Level.SEVERE,
233                         "jts.create_CoordinatorSynchronization_object_error");
234                  String JavaDoc msg = LogFormatter.getLocalizedMessage(_logger,
235                               "jts.create_CoordinatorSynchronization_object_error");
236                   throw new org.omg.CORBA.INTERNAL JavaDoc(msg);
237             }
238         }
239
240         return thisRef;
241     }
242
243     /**Destroys the CoordinatorSynchronizationImpl object.
244      *
245      * @param
246      *
247      * @return
248      *
249      * @see
250      */

251     void destroy() {
252         if( poa != null &&
253             thisRef != null )
254             try {
255                 poa.deactivate_object(poa.reference_to_id(thisRef));
256                 thisRef = null;
257             } catch( Exception JavaDoc exc ) {
258                  _logger.log(Level.WARNING,"jts.object_destroy_error",
259                         "CoordinatorResource");
260             }
261
262         finalize();
263     }
264
265     /**
266      * Returns the CoordinatorSynchronizationImpl which serves the given object.
267      *
268      * @param The CORBA Object.
269      *
270      * @return The CoordinatorSynchronizationImpl object which serves it.
271      *
272      * @see
273      */

274     synchronized static final CoordinatorSynchronizationImpl servant(Synchronization sync) {
275         CoordinatorSynchronizationImpl result = null;
276
277         // we will not be able to obtain the
278
// servant from our local POA for a proxy sync object.
279
// so return null
280
if (sync != null && Configuration.getProxyChecker().isProxy(sync)) {
281             return result;
282         }
283
284         if (sync instanceof CoordinatorSynchronizationImpl ) {
285             result = (CoordinatorSynchronizationImpl) sync;
286         } else if (poa != null) {
287             try {
288                 result = (CoordinatorSynchronizationImpl) poa.reference_to_servant(sync);
289                 if( result.thisRef == null )
290                     result.thisRef = sync;
291             } catch( Exception JavaDoc exc ) {
292                 _logger.log(Level.WARNING,"jts.cannot_locate_servant",
293                             "CoordinatorSynchronization");
294             }
295         }
296
297         return result;
298     }
299 }
300
Popular Tags