KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jotm > jta > rmi > JTAClientTransactionInterceptor


1 /*
2  * @(#) JTAClientTransactionInterceptor
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: JTAClientTransactionInterceptor.java,v 1.9 2005/02/24 04:32:40 tonyortiz Exp $
37  * --------------------------------------------------------------------------
38  */

39 package org.objectweb.jotm.jta.rmi;
40
41 // java import
42
import java.io.IOException JavaDoc;
43
44 import org.objectweb.carol.rmi.jrmp.interceptor.JClientRequestInfo;
45 import org.objectweb.carol.rmi.jrmp.interceptor.JClientRequestInterceptor;
46 import org.objectweb.jotm.Current;
47 import org.objectweb.jotm.TransactionContext;
48
49 /**
50  * Class <code>JTAClientTransactionInterceptor</code> is a JRMP Transaction client interceptor for
51  * Transaction Context propagation
52  *
53  * @author Guillaume Riviere (Guillaume.Riviere@inrialpes.fr)
54  */

55 public class JTAClientTransactionInterceptor
56     implements JClientRequestInterceptor {
57
58     // Commented out all the tracing in this module, generated
59
// warnings when integrated with JONAS at JONAS START.
60
// Need to resolve whenever JONAS uses log4j.
61
// private static Log log =
62
// LogFactory.getLog("org.objectweb.jotm.jta.rmi.client");
63

64     /**
65      * transaction context id
66      */

67     public static int TX_CTX_ID = 0;
68
69     /**
70      * current object
71      */

72     private static Current current = null;
73
74     /**
75      * interceptor name
76      */

77     private static String JavaDoc interceptorName = "JTAClientTransactionInterceptor";
78
79     /**
80      * constructor
81      */

82     public JTAClientTransactionInterceptor() {
83         // log.trace("default constructor");
84
}
85
86     /**
87      * get the name of this interceptor
88      * @return name
89      */

90     public String JavaDoc name() {
91         return interceptorName;
92     }
93
94     /**
95      * send client context with the request. The sendingRequest method of the JPortableInterceptors
96      * is called prior to marshalling arguments and contexts
97      * @param jri JClientRequestInfo the jrmp client info
98      * @exception IOException if an exception occur with the ObjectOutput
99      */

100     public void send_request(JClientRequestInfo jri) throws IOException JavaDoc {
101         // log.trace("--> send request");
102
try {
103             if (current == null)
104                 current = Current.getCurrent();
105             if (current != null) {
106                 // get the Transaction Context (null if there is no transaction)
107
TransactionContext txCtx = current.getPropagationContext(true);
108                 if (txCtx != null) {
109                     JTATransactionServiceContext jtasc =
110                         new JTATransactionServiceContext();
111                     jtasc.setContext(txCtx, false);
112                     jri.add_request_service_context(jtasc);
113                 }
114             }
115         } catch (Exception JavaDoc e) {
116             e.printStackTrace();
117         }
118     }
119
120     /**
121      * Receive reply interception
122      * @param jri JClientRequestInfo the jrmp client info
123      * @exception IOException if an exception occur with the ObjectOutput
124      */

125     public void receive_reply(JClientRequestInfo jri) throws IOException JavaDoc {
126         if (current == null)
127             current = Current.getCurrent();
128         if (current != null) {
129             JTATransactionServiceContext jtasc =
130                 (JTATransactionServiceContext) jri.get_reply_service_context(
131                     TX_CTX_ID);
132             if (jtasc != null) {
133                 // put into the the Current object (true for client side context
134
current.setPropagationContext(
135                     jtasc.getTransactionContext(),
136                     true);
137             }
138         }
139         // log.trace("<-- received reply");
140
}
141
142     // empty method
143
public void send_poll(JClientRequestInfo jri) throws IOException JavaDoc {
144         // log.trace("--> send poll");
145
}
146
147     public void receive_exception(JClientRequestInfo jri) throws IOException JavaDoc {
148         // log.trace("<-- received exception");
149
if (current == null)
150             current = Current.getCurrent();
151         if (current != null) {
152             JTATransactionServiceContext jtasc =
153                 (JTATransactionServiceContext) jri.get_reply_service_context(
154                     TX_CTX_ID);
155             if (jtasc != null) {
156                 // put into the the Current object (true for client side context
157
current.setPropagationContext(
158                     jtasc.getTransactionContext(),
159                     true);
160             }
161         }
162     }
163
164     public void receive_other(JClientRequestInfo jri) throws IOException JavaDoc {
165         if (current == null)
166             current = Current.getCurrent();
167         if (current != null) {
168             JTATransactionServiceContext jtasc =
169                 (JTATransactionServiceContext) jri.get_reply_service_context(
170                     TX_CTX_ID);
171             if (jtasc != null) {
172                 // put into the the Current object (true for client side context
173
current.setPropagationContext(
174                     jtasc.getTransactionContext(),
175                     true);
176             }
177         }
178         // log.trace("<-- received other");
179
}
180 }
181
Popular Tags