KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#) JTAServerTransactionInterceptor
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: JTAServerTransactionInterceptor.java,v 1.9 2005/02/24 04:34:56 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.JServerRequestInfo;
45 import org.objectweb.carol.rmi.jrmp.interceptor.JServerRequestInterceptor;
46 import org.objectweb.jotm.Current;
47 import org.objectweb.jotm.TransactionContext;
48
49 /**
50  * Class <code>JTAServerTransactionInterceptor</code> is a JRMP Transaction server interceptor for
51  * Transaction Context propagation
52  *
53  * @author Guillaume Riviere (Guillaume.Riviere@inrialpes.fr)
54  *
55  */

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

65     /**
66      * transaction context id
67      */

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

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

78     private static String JavaDoc interceptorName = "JTAServerTransactionInterceptor";
79
80     /**
81      * constructor
82      */

83     public JTAServerTransactionInterceptor() {
84         // log.trace("default constructor");
85
}
86
87     /**
88      * Receive request
89      * @param jri JServerRequestInfo the jrmp server request information
90      * @exception IOException if an exception occur with the ObjectOutput
91      */

92     public void receive_request(JServerRequestInfo jri) throws IOException JavaDoc {
93         // log.trace("--> receive request");
94
if (current == null)
95             current = Current.getCurrent();
96         if (current != null) {
97             JTATransactionServiceContext jtasc =
98                 (JTATransactionServiceContext) jri.get_request_service_context(
99                     TX_CTX_ID);
100             if (jtasc != null) {
101                 // put into the the Current object (true for client side context
102
current.setPropagationContext(
103                     jtasc.getTransactionContext(),
104                     false);
105             }
106         }
107     }
108
109     /**
110      * send reply with context
111      * @param jri JServerRequestInfo the jrmp server request information
112      * @exception IOException if an exception occur with the ObjectOutput
113      */

114     public void send_reply(JServerRequestInfo jri) throws IOException JavaDoc {
115         if (current == null)
116             current = Current.getCurrent();
117         if (current != null) {
118             // get the Transaction Context (null if there is no transaction)
119
TransactionContext txCtx = current.getPropagationContext(false);
120             if (txCtx != null) {
121                 JTATransactionServiceContext jtasc =
122                     new JTATransactionServiceContext();
123                 jtasc.setContext(txCtx, true);
124                 jri.add_reply_service_context(jtasc);
125                 current.setPropagationContext(null, false);
126             }
127         }
128         // log.trace("<-- sent reply");
129
}
130
131     /**
132     * get the name of this interceptor
133     * @return name
134     */

135     public String JavaDoc name() {
136         return interceptorName;
137     }
138
139     public void send_exception(JServerRequestInfo jri) throws IOException JavaDoc {
140         if (current == null)
141             current = Current.getCurrent();
142         if (current != null) {
143             // get the Transaction Context (null if there is no transaction)
144
TransactionContext txCtx = current.getPropagationContext(false);
145             if (txCtx != null) {
146                 JTATransactionServiceContext jtasc =
147                     new JTATransactionServiceContext();
148                 jtasc.setContext(txCtx, true);
149                 jri.add_reply_service_context(jtasc);
150                 current.setPropagationContext(null, false);
151             }
152         }
153         // log.trace("<-- sent exception");
154
}
155
156     public void send_other(JServerRequestInfo jri) throws IOException JavaDoc {
157         if (current == null)
158             current = Current.getCurrent();
159         if (current != null) {
160             // get the Transaction Context (null if there is no transaction)
161
TransactionContext txCtx = current.getPropagationContext(false);
162             if (txCtx != null) {
163                 JTATransactionServiceContext jtasc =
164                     new JTATransactionServiceContext();
165                 jtasc.setContext(txCtx, true);
166                 jri.add_reply_service_context(jtasc);
167                 current.setPropagationContext(null, false);
168             }
169         }
170         // log.trace("<-- sent other");
171
}
172 }
173
Popular Tags