KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#) JTATransactionServiceContext
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: JTATransactionServiceContext.java,v 1.8 2004/10/29 04:16:10 tonyortiz Exp $
37  * --------------------------------------------------------------------------
38  */

39 package org.objectweb.jotm.jta.rmi;
40
41 // java import
42
import java.io.Externalizable JavaDoc;
43 import java.io.IOException JavaDoc;
44 import java.io.ObjectInput JavaDoc;
45 import java.io.ObjectOutput JavaDoc;
46
47 // import javax.transaction.xa.Xid;
48
import org.objectweb.jotm.Xid;
49
50 import org.objectweb.carol.rmi.jrmp.interceptor.JServiceContext;
51 import org.objectweb.jotm.Coordinator;
52 import org.objectweb.jotm.InternalTransactionContext;
53 import org.objectweb.jotm.TransactionContext;
54 import org.objectweb.jotm.XidImpl;
55
56 /**
57  * Class <code>JTATransactionServiceContext</code> is a JRMP Class for Transaction
58  * Context Propagation
59  *
60  * @author Guillaume Riviere (Guillaume.Riviere@inrialpes.fr)
61  * @version 1.0, 13/09/2002
62  */

63 public class JTATransactionServiceContext
64     implements JServiceContext, Externalizable JavaDoc {
65
66     /**
67      * Transaction Context
68      */

69     transient TransactionContext txCtx = null;
70
71     /**
72      * true is this is a reply
73      */

74     transient boolean isReply;
75
76     /**
77      * context id
78      */

79     private transient int context_id;
80
81     /**
82      * empty constructor for extarenalizable
83      */

84     public JTATransactionServiceContext() {
85         this.context_id = JTAClientTransactionInterceptor.TX_CTX_ID;
86     }
87
88     /**
89      * the JServiceContext id
90      */

91     public int getContextId() {
92         return context_id;
93     }
94
95     /**
96      * constructor
97      * @param txCtx TransactionContext the RMI (Serializable) Transaction Context
98      * @param isReply boolean is reply indicator
99      */

100     public void setContext(TransactionContext txCtx, boolean isReply) {
101         this.txCtx = txCtx;
102         this.isReply = isReply;
103     }
104
105     /**
106      * get the transaction context
107      * @return TransactionContext the Transaction context
108      */

109     public TransactionContext getTransactionContext() {
110         return txCtx;
111     }
112
113     /**
114      * readExternal to initialise Transaction context
115      * @param in the object input
116      */

117     public void readExternal(ObjectInput JavaDoc in)
118         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
119         // read Xid
120
int fid = in.readInt();
121         byte[] gti = new byte[in.readInt()];
122         in.read(gti);
123         byte[] bq = new byte[in.readInt()];
124         in.read(bq);
125         Xid xid = new XidImpl(fid, gti, bq);
126         // read Coordinator
127
Coordinator coor = (Coordinator) in.readObject();
128         // read timeout
129
int timeout = in.readInt();
130         this.txCtx = new InternalTransactionContext(timeout, coor, (javax.transaction.xa.Xid JavaDoc) xid);
131     }
132
133     /**
134      * writeExternal to send Transaction context
135      * @param out the object output
136      */

137     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
138         // send Xid
139
Xid xid = txCtx.getXid();
140         out.writeInt(xid.getFormatId());
141         out.writeInt(xid.getGlobalTransactionId().length);
142         out.write(xid.getGlobalTransactionId());
143         out.writeInt(xid.getBranchQualifier().length);
144         out.write(xid.getBranchQualifier());
145         // send Coordinator
146
out.writeObject(txCtx.getCoordinator());
147         // send timeout
148
out.writeInt(txCtx.getTimeout());
149     }
150 }
151
Popular Tags