KickJava   Java API By Example, From Geeks To Geeks.

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


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
31 import java.util.Vector JavaDoc;
32 import java.util.Enumeration JavaDoc;
33 import java.util.Hashtable JavaDoc;
34
35 import org.objectweb.joram.shared.stream.Streamable;
36 import org.objectweb.joram.shared.stream.StreamUtil;
37
38 /**
39  * An <code>XACnxRollback</code> instance is used by an
40  * <code>XAConnection</code> for rolling back the operations performed
41  * during a transaction.
42  */

43 public final class XACnxRollback extends AbstractJmsRequest {
44   /** Transaction branch qualifier. */
45   private byte[] bq;
46
47   public void setBQ(byte[] bq) {
48     this.bq = bq;
49   }
50   
51   /** Returns the transaction branch qualifier. */
52   public byte[] getBQ() {
53     return bq;
54   }
55
56   /** Transaction identifier format. */
57   private int fi;
58
59   public void setFI(int fi) {
60     this.fi = fi;
61   }
62
63   /** Returns the transaction identifier format. */
64   public int getFI() {
65     return fi;
66   }
67
68   /** Global transaction identifier. */
69   private byte[] gti;
70
71   public void setGTI(byte[] gti) {
72     this.gti = gti;
73   }
74
75   /** Returns the global transaction identifier. */
76   public byte[] getGTI() {
77     return gti;
78   }
79
80   /** Table holding the identifiers of the messages to deny on queues. */
81   private Hashtable JavaDoc qDenyings = null;
82   /** Table holding the identifiers of the messages to deny on subs. */
83   private Hashtable JavaDoc subDenyings = null;
84
85   /**
86    * Adds a vector of denied messages' identifiers.
87    *
88    * @param target Name of the queue or of the subscription where denying the
89    * messages.
90    * @param ids Vector of message identifiers.
91    * @param queueMode <code>true</code> if the messages have to be denied on
92    * a queue.
93    */

94   public void add(String JavaDoc target, Vector JavaDoc ids, boolean queueMode) {
95     if (queueMode) {
96       if (qDenyings == null)
97         qDenyings = new Hashtable JavaDoc();
98       qDenyings.put(target, ids);
99     } else {
100       if (subDenyings == null)
101         subDenyings = new Hashtable JavaDoc();
102       subDenyings.put(target, ids);
103     }
104   }
105
106
107   /** Returns the queues enumeration. */
108   public Enumeration JavaDoc getQueues() {
109     if (qDenyings == null)
110       return (new Hashtable JavaDoc()).keys();
111     return qDenyings.keys();
112   }
113
114   /** Returns the vector of msg identifiers for a given queue. */
115   public Vector JavaDoc getQueueIds(String JavaDoc queue) {
116     if (qDenyings == null)
117       return null;
118     return (Vector JavaDoc) qDenyings.get(queue);
119   }
120
121   /** Returns the subscriptions enumeration. */
122   public Enumeration JavaDoc getSubs() {
123     if (subDenyings == null)
124       return (new Hashtable JavaDoc()).keys();
125     return subDenyings.keys();
126   }
127   
128   /** Sets the queue denyings table. */
129   public void setQDenyings(Hashtable JavaDoc qDenyings) {
130     this.qDenyings = qDenyings;
131   }
132
133   /** Sets the sub denyings table. */
134   public void setSubDenyings(Hashtable JavaDoc subDenyings) {
135     this.subDenyings = subDenyings;
136   }
137
138   /** Returns the vector of msg identifiers for a given subscription. */
139   public Vector JavaDoc getSubIds(String JavaDoc sub) {
140     if (subDenyings == null)
141       return null;
142     return (Vector JavaDoc) subDenyings.get(sub);
143   }
144
145   protected int getClassId() {
146     return XA_CNX_ROLLBACK;
147   }
148
149   /**
150    * Constructs an <code>XACnxRollback</code> instance.
151    *
152    * @param bq Transaction branch qualifier.
153    * @param fi Transaction identifier format.
154    * @param gti Global transaction identifier.
155    */

156   public XACnxRollback(byte[] bq, int fi, byte[] gti) {
157     super(null);
158     this.bq = bq;
159     this.fi = fi;
160     this.gti = gti;
161   }
162
163   /**
164    * Constructs an <code>XACnxRollback</code> instance.
165    */

166   public XACnxRollback() {}
167
168   /* ***** ***** ***** ***** *****
169    * Streamable interface
170    * ***** ***** ***** ***** ***** */

171
172   /**
173    * The object implements the writeTo method to write its contents to
174    * the output stream.
175    *
176    * @param os the stream to write the object to
177    */

178   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
179     super.writeTo(os);
180     StreamUtil.writeTo(bq, os);
181     StreamUtil.writeTo(fi, os);
182     StreamUtil.writeTo(gti, os);
183     if (qDenyings == null) {
184       StreamUtil.writeTo(-1, os);
185     } else {
186       int size = qDenyings.size();
187       for (Enumeration JavaDoc keys = qDenyings.keys(); keys.hasMoreElements(); ) {
188         String JavaDoc key = (String JavaDoc) keys.nextElement();
189         StreamUtil.writeTo(key, os);
190         Vector JavaDoc ids = (Vector JavaDoc) qDenyings.get(key);
191         StreamUtil.writeVectorOfStringTo(ids, os);
192       }
193     }
194     if (subDenyings == null) {
195       StreamUtil.writeTo(-1, os);
196     } else {
197       int size = subDenyings.size();
198       for (Enumeration JavaDoc keys = subDenyings.keys(); keys.hasMoreElements(); ) {
199         String JavaDoc key = (String JavaDoc) keys.nextElement();
200         StreamUtil.writeTo(key, os);
201         Vector JavaDoc ids = (Vector JavaDoc) subDenyings.get(key);
202         StreamUtil.writeVectorOfStringTo(ids, os);
203       }
204     }
205   }
206
207   /**
208    * The object implements the readFrom method to restore its contents from
209    * the input stream.
210    *
211    * @param is the stream to read data from in order to restore the object
212    */

213   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
214     super.readFrom(is);
215     bq = StreamUtil.readByteArrayFrom(is);
216     fi = StreamUtil.readIntFrom(is);
217     gti = StreamUtil.readByteArrayFrom(is);
218     int size = StreamUtil.readIntFrom(is);
219     if (size == -1) {
220       qDenyings = null;
221     } else {
222       qDenyings = new Hashtable JavaDoc(size*4/3);
223       for (int i=0; i<size; i++) {
224         String JavaDoc target = StreamUtil.readStringFrom(is);
225         Vector JavaDoc ids = StreamUtil.readVectorOfStringFrom(is);
226         qDenyings.put(target, ids);
227       }
228     }
229     size = StreamUtil.readIntFrom(is);
230     if (size == -1) {
231       subDenyings = null;
232     } else {
233       subDenyings = new Hashtable JavaDoc(size*4/3);
234       for (int i=0; i<size; i++) {
235         String JavaDoc target = StreamUtil.readStringFrom(is);
236         Vector JavaDoc ids = StreamUtil.readVectorOfStringFrom(is);
237         subDenyings.put(target, ids);
238       }
239     }
240   }
241 }
242
Popular Tags