KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jotm > ots > OTSClientTransactionInterceptor


1 /*
2  * @(#) OTSClientTransactionInterceptor.java 1.0 02/07/15
3  *
4  * JOTM: Java Open Transaction Manager
5  *
6  * This module was originally developed by
7  * - INRIA inside the ObjectWeb Consortium(http://www.objectweb.org)
8  *
9  * The original code and portions created by INRIA are
10  * Copyright (C) 2002 - INRIA (www.inria.fr)
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions are met:
15  *
16  * -Redistributions of source code must retain the above copyright notice, this
17  * list of conditions and the following disclaimer.
18  *
19  * -Redistributions in binary form must reproduce the above copyright notice,
20  * this list of conditions and the following disclaimer in the documentation
21  * and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * --------------------------------------------------------------------------
36  * $Id: OTSClientTransactionInterceptor.java,v 1.12 2004/12/13 19:49:29 tonyortiz Exp $
37  * --------------------------------------------------------------------------
38  */

39 package org.objectweb.jotm.ots;
40
41 // java import
42
import org.objectweb.jotm.Current;
43 import org.objectweb.jotm.TransactionContext;
44 import org.omg.IOP.ServiceContext JavaDoc;
45 import org.omg.PortableInterceptor.ClientRequestInfo JavaDoc;
46 import org.omg.PortableInterceptor.ClientRequestInterceptor JavaDoc;
47 import org.omg.PortableInterceptor.ForwardRequest JavaDoc;
48 import org.omg.PortableInterceptor.ORBInitInfo JavaDoc;
49
50 /**
51  * Class <code>OTSClientTransactionInterceptor</code> is a Client Interceptor for OTS Java Client
52  * of JOTM. This Interceptor translate the Standart OTS Propagation Context to a Internal JOTM
53  * Transaction context
54  *
55  * @author Guillaume Riviere (Guillaume.Riviere@inrialpes.fr)
56  */

57 public class OTSClientTransactionInterceptor
58     extends OTSInterceptor
59     implements ClientRequestInterceptor JavaDoc {
60
61     /**
62      * current object
63      */

64     private static Current current = null;
65
66     /**
67      * interceptor name
68      */

69     private String JavaDoc interceptorName = "OTSClientTransactionInteceptor";
70
71     /**
72      * constructor
73      */

74     public OTSClientTransactionInterceptor(ORBInitInfo JavaDoc info) {
75         super(info);
76     }
77
78     /**
79      * get the name of this interceptor
80      * @return name
81      */

82     public String JavaDoc name() {
83         return interceptorName;
84     }
85
86     public void destroy() {
87     }
88
89     /**
90      * send client transaction context with the request, if existed.
91      *
92      * @param jri ClientRequestInfo iiop client info
93      * @exception IOException if an exception occured with the ObjectOutput
94      */

95     public void send_request(ClientRequestInfo JavaDoc jri) throws ForwardRequest JavaDoc {
96         
97         if (current == null)
98             current = Current.getCurrent();
99         if (current != null) {
100             try {
101                 // get the Transaction Context (null if there is no transaction)
102
TransactionContext txCtx = current.getPropagationContext(true);
103                 ServiceContext JavaDoc pContext = null ;
104
105                 if (txCtx != null) {
106                     
107                     // get the TransactionContext and build the Corba PropagtionContext
108
pContext = buildCorbaPropagationContext(txCtx);
109                     jri.add_request_service_context(pContext, true);
110                 } else {
111                 
112                 // if no active global transaction, the container does not include a tx context
113
// in the request message
114
}
115                 
116             } catch (Exception JavaDoc e) {
117                 throw new ForwardRequest JavaDoc();
118             }
119         }
120     }
121     
122    
123     /**
124      * Receive reply interception
125      * @param jri JClientRequestInfo jri client info
126      * @exception IOException if an exception occur with the ObjectOutput
127      */

128     public void receive_reply(ClientRequestInfo JavaDoc jri) {
129         
130         if (current == null)
131             current = Current.getCurrent();
132         
133         if (current != null) {
134
135             try {
136                 TransactionContext txCtx = decodeCorbaPropagationContext(jri.get_reply_service_context(TX_CTX_ID)) ;
137
138                 if ( txCtx != null ) {
139
140                     // put into the the Current object (true for client side context)
141
current.setPropagationContext(txCtx, true);
142             
143                     // associate Thread whith Tx
144
current.associateThreadTx(txCtx.getXid());
145                 }
146                 
147             } catch (org.omg.CORBA.BAD_PARAM JavaDoc b) {
148                 // else we do nothing -> no transaction context for this call
149

150             } catch (Exception JavaDoc e) {
151                
152             }
153         }
154     }
155
156     // empty method
157
public void send_poll(ClientRequestInfo JavaDoc jri) {
158     }
159
160     public void receive_exception(ClientRequestInfo JavaDoc jri) throws ForwardRequest JavaDoc {
161         if (current == null)
162             current = Current.getCurrent();
163         
164         if (current != null) {
165             try {
166                 TransactionContext txCtx = decodeCorbaPropagationContext(jri.get_reply_service_context(TX_CTX_ID)) ;
167
168                 if ( txCtx != null ) {
169
170                     // put into the the Current object (true for client side context)
171
current.setPropagationContext(txCtx, true);
172             
173                     // associate Thread whith Tx
174
current.associateThreadTx(txCtx.getXid());
175                 }
176     
177             } catch (org.omg.CORBA.BAD_PARAM JavaDoc b) {
178                 // else we do nothing -> no transaction context for this call
179

180             } catch (Exception JavaDoc e) {
181             }
182         }
183     }
184
185     public void receive_other(ClientRequestInfo JavaDoc jri) throws ForwardRequest JavaDoc {
186     }
187
188 }
189
Popular Tags