KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > shared > client > XACnxPrepare


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2006 ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - 2000 Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (INRIA)
22  * Contributor(s): ScalAgent Distributed Technologies
23  */

24 package org.objectweb.joram.shared.client;
25
26 import java.io.Externalizable JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.OutputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 import org.objectweb.joram.shared.stream.Streamable;
33 import org.objectweb.joram.shared.stream.StreamUtil;
34
35 /**
36  * An <code>XACnxPrepare</code> instance is used by an
37  * <code>XAConnection</code> for sending messages and acknowledgements to
38  * the proxy.
39  */

40 public final class XACnxPrepare extends AbstractJmsRequest {
41   /** Transaction branch qualifier. */
42   private byte[] bq;
43
44   /** Returns the transaction branch qualifier. */
45   public byte[] getBQ() {
46     return bq;
47   }
48
49   public void setBQ(byte[] bq) {
50     this.bq = bq;
51   }
52
53   /** Transaction identifier format. */
54   private int fi;
55
56   /** Returns the transaction identifier format. */
57   public int getFI() {
58     return fi;
59   }
60
61   public void setFI(int fi) {
62     this.fi = fi;
63   }
64
65   /** Global transaction identifier. */
66   private byte[] gti;
67
68   /** Returns the global transaction identifier. */
69   public byte[] getGTI() {
70     return gti;
71   }
72
73   public void setGTI(byte[] gti) {
74     this.gti = gti;
75   }
76
77   /** Vector of <code>ProducerMessages</code> instances. */
78   private Vector JavaDoc sendings;
79
80   /** Returns the vector of <code>ProducerMessages</code> instances. */
81   public Vector JavaDoc getSendings() {
82     if (sendings == null)
83       sendings = new Vector JavaDoc();
84     return sendings;
85   }
86
87   public void addProducerMessages(ProducerMessages pm) {
88     sendings.addElement(pm);
89   }
90
91   /** Vector of <code>SessAckRequest</code> instances. */
92   private Vector JavaDoc acks;
93
94   /** Returns the vector of <code>SessAckRequest</code> instances. */
95   public Vector JavaDoc getAcks() {
96     if (acks == null)
97       acks = new Vector JavaDoc();
98     return acks;
99   }
100
101   public void addSessAckRequest(SessAckRequest sar) {
102     acks.addElement(sar);
103   }
104
105   protected int getClassId() {
106     return XA_CNX_PREPARE;
107   }
108
109   /**
110    * Constructs an <code>XACnxPrepare</code> instance.
111    *
112    * @param bq Transaction branch qualifier.
113    * @param fi Transaction identifier format.
114    * @param gti Global transaction identifier.
115    * @param sendings Vector of <code>ProducerMessages</code> instances.
116    * @param acks Vector of <code>SessAckRequest</code> instances.
117    */

118   public XACnxPrepare(byte[] bq,
119                        int fi,
120                        byte[] gti,
121                        Vector JavaDoc sendings,
122                        Vector JavaDoc acks) {
123     super();
124     this.bq = bq;
125     this.fi = fi;
126     this.gti = gti;
127     this.sendings = sendings;
128     this.acks = acks;
129   }
130
131   public XACnxPrepare() {
132     super(null);
133     sendings = new Vector JavaDoc();
134     acks = new Vector JavaDoc();
135   }
136
137   /* ***** ***** ***** ***** *****
138    * Streamable interface
139    * ***** ***** ***** ***** ***** */

140
141   /**
142    * The object implements the writeTo method to write its contents to
143    * the output stream.
144    *
145    * @param os the stream to write the object to
146    */

147   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
148     super.writeTo(os);
149     StreamUtil.writeTo(bq, os);
150     StreamUtil.writeTo(fi, os);
151     StreamUtil.writeTo(gti, os);
152     if (sendings == null) {
153       StreamUtil.writeTo(-1, os);
154     } else {
155       int size = sendings.size();
156       StreamUtil.writeTo(size, os);
157       for (int i=0; i<size; i++) {
158         ((ProducerMessages) sendings.elementAt(i)).writeTo(os);
159       }
160     }
161     if (acks == null) {
162       StreamUtil.writeTo(-1, os);
163     } else {
164       int size = acks.size();
165       StreamUtil.writeTo(size, os);
166       for (int i=0; i<size; i++) {
167         ((SessAckRequest) acks.elementAt(i)).writeTo(os);
168       }
169     }
170   }
171
172   /**
173    * The object implements the readFrom method to restore its contents from
174    * the input stream.
175    *
176    * @param is the stream to read data from in order to restore the object
177    */

178   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
179     super.readFrom(is);
180     bq = StreamUtil.readByteArrayFrom(is);
181     fi = StreamUtil.readIntFrom(is);
182     gti = StreamUtil.readByteArrayFrom(is);
183     int size = StreamUtil.readIntFrom(is);
184     if (size == -1) {
185       sendings = null;
186     } else {
187       sendings = new Vector JavaDoc(size);
188       for (int i=0; i<size; i++) {
189         ProducerMessages pm = new ProducerMessages();
190         pm.readFrom(is);
191         sendings.addElement(pm);
192       }
193     }
194     size = StreamUtil.readIntFrom(is);
195     if (size == -1) {
196       acks = null;
197     } else {
198       acks = new Vector JavaDoc(size);
199       for (int i=0; i<size; i++) {
200         SessAckRequest ack = new SessAckRequest();
201         ack.readFrom(is);
202         acks.addElement(ack);
203       }
204     }
205   }
206 }
207
Popular Tags