KickJava   Java API By Example, From Geeks To Geeks.

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


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: RegisteredSyncs.java
31
//
32
// Description: Synchronization participant management.
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 java.util.*;
53
54 import org.omg.CORBA.*;
55 import org.omg.CosTransactions.*;
56
57 import com.sun.jts.trace.*;
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 /**
64  * The RegisteredSyncs class provides operations that manage a set of
65  * Synchronization objects involved in a transaction. In order to avoid
66  * sending multiple synchronization requests to the same resource we require
67  * some way to perform Synchronization reference comparisons.
68  *
69  * @version 0.01
70  *
71  * @author Simon Holdsworth, IBM Corporation
72  *
73  * @see
74  */

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

83 class RegisteredSyncs {
84
85     private Vector registered = new Vector();
86
87     /*
88         Logger to log transaction messages
89     */

90     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER);
91
92     /**
93      * Default RegisteredSyncs constructor.
94      *
95      * @param
96      *
97      * @return
98      *
99      * @see
100      */

101     RegisteredSyncs() {}
102
103     /**Cleans up the objects state.
104      *
105      * @param
106      *
107      * @return
108      *
109      * @see
110      */

111     public void finalize() {
112         if (registered != null) {
113             registered.removeAllElements();
114         }
115         registered = null;
116     }
117
118     /**
119      * Distributes before completion operations to all registered
120      * Synchronization objects.
121      * <p>
122      * Returns a boolean to indicate success/failure.
123      *
124      * @param
125      *
126      * @return Indicates success of the operation.
127      *
128      * @see
129      */

130     boolean distributeBefore() {
131
132         boolean result = true;
133
134         for (int i = 0; i < registered.size() && result == true; i++) {
135             Synchronization sync = (Synchronization) registered.elementAt(i);
136             try {
137                 if(_logger.isLoggable(Level.FINEST))
138                 {
139                     _logger.logp(Level.FINEST,"RegisterdSyncs","distributeBefore()",
140                             "Before invoking before_completion() on synchronization object " + sync);
141                 }
142
143                 sync.before_completion();
144
145                 if(_logger.isLoggable(Level.FINEST))
146                 {
147                     _logger.logp(Level.FINEST,"RegisterdSyncs","distributeBefore()",
148                              "After invoking before_completion() on synchronization object " + sync);
149                 }
150             } catch (Throwable JavaDoc exc) {
151
152                 // Discard any exceptions at this point and return false.
153
if (!(exc instanceof INVALID_TRANSACTION)) {
154                     _logger.log(Level.WARNING,
155                             "jts.exception_in_synchronization_operation",
156                             new java.lang.Object JavaDoc[] { exc.toString(),"before_completion"});
157                 }
158                 result = false;
159             }
160         }
161
162         return result;
163     }
164
165     /**
166      * Distributes after completion operations to all registered
167      * Synchronization objects.
168      *
169      * @param status Indicates whether the transaction committed.
170      *
171      * @return
172      *
173      * @see
174      */

175     void distributeAfter(Status status) {
176
177         for (int i = 0; i < registered.size(); i++) {
178             boolean isProxy = false;
179             Synchronization sync = (Synchronization) registered.elementAt(i);
180
181             // COMMENT(Ram J) the instanceof operation should be replaced
182
// by a is_local() call, once the local object contract is
183
// implemented.
184
if (!(sync instanceof com.sun.jts.jta.SynchronizationImpl)) {
185                 isProxy = Configuration.getProxyChecker().isProxy(sync);
186             }
187
188             try {
189                 if(_logger.isLoggable(Level.FINEST))
190                 {
191                     _logger.logp(Level.FINEST,"RegisterdSyncs","distributeAfter()",
192                             "Before invoking after_completion() on synchronization object " + sync);
193                 }
194
195                 sync.after_completion(status);
196
197                 if(_logger.isLoggable(Level.FINEST))
198                 {
199                     _logger.logp(Level.FINEST,"RegisterdSyncs","distributeAfter()",
200                             "After invoking after_completion() on"+
201                             "synchronization object"+ sync);
202                 }
203             } catch (Throwable JavaDoc exc) {
204                 // Discard any exceptions at this point.
205
if (exc instanceof OBJECT_NOT_EXIST ||
206                         exc instanceof COMM_FAILURE) {
207                     // ignore i.e., no need to log this error (Ram J)
208
// this can happen normally during after_completion flow,
209
// since remote sync objects would go away when the
210
// subordinate cleans up (i.e, the subordinate would have
211
// called afterCompletions locally before going away).
212
} else {
213                     _logger.log(Level.WARNING,
214                             "jts.exception_in_synchronization_operation",
215                             new java.lang.Object JavaDoc[] { exc.toString(),
216                             "after_completion"});
217                 }
218             }
219
220             // Release the object if it is a proxy.
221
if (isProxy) {
222                 sync._release();
223             }
224         }
225     }
226
227     /**
228      * Adds a reference to a Synchronization object to the set.
229      * <p>
230      * If there is no such set then a new one is created with the single
231      * Synchronization reference.
232      *
233      * @param obj The Synchronization object to be added.
234      *
235      * @return
236      *
237      * @see
238      */

239     void addSync(Synchronization obj) {
240         registered.addElement(obj);
241     }
242
243     /**
244      * Empties the set of registered Synchronization objects.
245      *
246      * @param
247      *
248      * @return
249      *
250      * @see
251      */

252     void empty() {
253         registered.removeAllElements();
254     }
255
256     /**
257      * Checks whether there are any Synchronization objects registered.
258      * <p>
259      * If there are, the operation returns true, otherwise false.
260      *
261      * @param
262      *
263      * @return Indicates whether any objects are registered.
264      *
265      * @see
266      */

267     boolean involved() {
268
269         boolean result = (registered.size() != 0);
270         return result;
271     }
272 }
273
Popular Tags