KickJava   Java API By Example, From Geeks To Geeks.

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


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: SenderReceiver.java
32
//
33
// Description: Transaction context propagation class.
34
//
35
// Product: com.sun.jts.CosTransactions
36
//
37
// Author: Simon Holdsworth
38
//
39
// Date: June, 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.CORBA.TSIdentificationPackage.*;
55 import org.omg.CosTransactions.*;
56 import org.omg.CosTSPortability.*;
57
58 import java.util.logging.Logger JavaDoc;
59 import java.util.logging.Level JavaDoc;
60 import com.sun.logging.LogDomains;
61 /**
62  * The SenderRecevier class is our implemention of the OTS Sender and Receiver
63  * classes.
64  * <p>
65  * Their method are implemented here as passthroughs to avoid dependency on the
66  * CosTSPortability package in com.ibm.jts.implement. This is because
67  * CosTSPortability is a deprecated interface in the OMG specification.
68  *
69  * @version 0.1
70  *
71  * @author Simon Holdsworth, IBM Corporation
72  *
73  * @see
74  */

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

83 class SenderReceiver implements Sender, Receiver {
84
85     static private final boolean debug = false;
86     private static SenderReceiver sendRec = new SenderReceiver();
87     /*
88         Logger to log transaction messages
89     */

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

101     SenderReceiver() {}
102
103     /**
104      * Pass the operation through to the CurrentTransaction class.
105      *
106      * @param id The request identifier.
107      * @param holder The completed context object.
108      *
109      * @return
110      *
111      * @exception TRANSACTION_ROLLEDBACK The current transaction
112      * has been rolled back. The message should not be sent and
113      * TRANSACTION_ROLLEDBACK should be returned to the caller.
114      * @exception TRANSACTION_REQUIRED There is no current transaction.
115      *
116      * @see
117      */

118     public void sending_request(int id, PropagationContextHolder holder)
119             throws TRANSACTION_ROLLEDBACK, TRANSACTION_REQUIRED {
120
121         if (debug) {
122             _logger.log(Level.FINE,"In sending_request"+
123                     ":"+id+","+holder.value.current.otid.formatID);
124         }
125
126         CurrentTransaction.sendingRequest(id, holder);
127
128         if (debug) {
129             _logger.log(Level.FINE,"Out sending_request"+
130                     ":"+id+","+holder.value.current.otid.formatID);
131         }
132     }
133
134     /**
135      * Pass the operation through to the CurrentTransaction class.
136      *
137      * @param id The request identifier.
138      * @param context The PropagationContext from the message.
139      * @param ex The exception on the message.
140      *
141      * @return
142      *
143      * @exception WrongTransaction The context returned on the reply is for a
144      * different transaction from the current one on the thread.
145      *
146      * @see
147      */

148     public void received_reply(int id, PropagationContext context,
149             org.omg.CORBA.Environment JavaDoc ex)
150             throws org.omg.CORBA.WrongTransaction JavaDoc {
151
152         if (debug) {
153             _logger.log(Level.FINE,"In received_reply"+
154                     ":"+id+","+context.current.otid.formatID);
155         }
156
157         CurrentTransaction.receivedReply(id, context, ex);
158
159         if (debug) {
160             _logger.log(Level.FINE,"Out received_reply"+
161                     ":"+id+","+context.current.otid.formatID);
162         }
163     }
164
165     /**
166      * Pass the operation through to the CurrentTransaction class.
167      *
168      * @param id The request identifier.
169      * @param context The PropagationContext from the message.
170      *
171      * @return
172      *
173      * @see
174      */

175     public void received_request(int id, PropagationContext context) {
176
177         if (debug) {
178             _logger.log(Level.FINE,"In received_request"+
179                     ":"+id+","+context.current.otid.formatID);
180         }
181
182         CurrentTransaction.receivedRequest(id, context);
183
184         if (debug) {
185             _logger.log(Level.FINE,"Out received_request"+
186                     ":"+id+","+context.current.otid.formatID);
187         }
188     }
189
190     /**
191      * Pass the operation through to the CurrentTransaction class.
192      *
193      * @param id The request identifier.
194      * @param holder The context to be returned on the reply.
195      *
196      * @return
197      *
198      * @exception INVALID_TRANSACTION The current transaction has
199      * outstanding work on this reply, and has been marked rollback-only,
200      * or the reply is returning when a different transaction is active
201      * from the one active when the request was imported.
202      * @exception TRANSACTION_ROLLEDBACK The current transaction has
203      * already been rolled back.
204      *
205      * @see
206      */

207     public void sending_reply(int id, PropagationContextHolder holder)
208         throws INVALID_TRANSACTION, TRANSACTION_ROLLEDBACK {
209
210         if (debug) {
211             _logger.log(Level.FINE,"In sending_reply"+
212                     ":"+id+","+holder.value.current.otid.formatID);
213         }
214
215         CurrentTransaction.sendingReply(id, holder);
216
217         if (debug) {
218             _logger.log(Level.FINE,"Out sending_reply"+
219                     ":"+id+","+holder.value.current.otid.formatID);
220         }
221     }
222
223     /**
224      * Identifies an instance of this class to the TSIdentification object.
225      *
226      * @param ident The TSIdentification object.
227      *
228      * @return
229      *
230      * @see
231      */

232     static void identify(TSIdentification ident) {
233         try {
234             ident.identify_sender(sendRec);
235             ident.identify_receiver(sendRec);
236             if (debug) {
237                 _logger.log(Level.FINE,"Sender/Receiver "+ sendRec +
238                                    " successfully identified");
239             }
240         } catch(AlreadyIdentified exc) {
241             _logger.log(Level.WARNING,"jts.already_indetified_communication_manager");
242         } catch (NotAvailable exc) {
243             _logger.log(Level.WARNING,"jts.unable_to_indetify_communication_manager");
244         }
245     }
246
247     private void debugMessage(String JavaDoc msg, int id, PropagationContext ctx) {
248         //System.err.print is not removed as debug Message will no more be
249
//used.
250
_logger.log(Level.FINE,msg+";"+id);
251         if (ctx == null) {
252             _logger.log(Level.FINE,"");
253         } else {
254             _logger.log(Level.FINE,"," + ctx.current.otid.formatID);
255         }
256     }
257 }
258
Popular Tags