KickJava   Java API By Example, From Geeks To Geeks.

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


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.InputStream JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.util.Enumeration JavaDoc;
30 import java.util.Hashtable JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import org.objectweb.joram.shared.stream.Streamable;
34 import org.objectweb.joram.shared.stream.StreamUtil;
35
36 public final class CommitRequest extends AbstractJmsRequest {
37   /**
38    * List of ProducerMessages
39    */

40   private Vector JavaDoc producerMessages;
41   
42   /**
43    * List of SessAckRequest
44    */

45   private Vector JavaDoc ackRequests;
46   
47   /**
48    * Indicates whether the produced messages
49    * are asynchronously send or not
50    * (without or with an acknowledgement).
51    */

52   private boolean asyncSend = false;
53
54   protected int getClassId() {
55     return COMMIT_REQUEST;
56   }
57   
58   public CommitRequest() {}
59   
60   public void addProducerMessages(ProducerMessages pm) {
61     if (producerMessages == null) producerMessages = new Vector JavaDoc();
62     producerMessages.addElement(pm);
63   }
64   
65   public void addAckRequest(SessAckRequest sar) {
66     if (ackRequests == null) ackRequests = new Vector JavaDoc();
67     ackRequests.addElement(sar);
68   }
69   
70   public Enumeration JavaDoc getProducerMessages() {
71     if (producerMessages != null) {
72       return producerMessages.elements();
73     } else {
74       return null;
75     }
76   }
77   
78   public Enumeration JavaDoc getAckRequests() {
79     if (ackRequests != null) {
80       return ackRequests.elements();
81     } else {
82       return null;
83     }
84   }
85   
86   public void setAsyncSend(boolean b) {
87     asyncSend = b;
88   }
89   
90   public final boolean getAsyncSend() {
91     return asyncSend;
92   }
93   
94   public void toString(StringBuffer JavaDoc strbuf) {
95     super.toString(strbuf);
96     strbuf.append(",producerMessages=").append(producerMessages);
97     strbuf.append(",ackRequests=").append(ackRequests);
98     strbuf.append(",asyncSend=").append(asyncSend);
99     strbuf.append(')');
100   }
101
102   /**
103    * The object implements the writeTo method to write its contents to
104    * the output stream.
105    *
106    * @param os the stream to write the object to
107    */

108   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
109     super.writeTo(os);
110
111     // Serialize the producerMessages Vector
112
if (producerMessages == null) {
113       StreamUtil.writeTo(-1, os);
114     } else {
115       int size = producerMessages.size();
116       StreamUtil.writeTo(size, os);
117       for (int i=0; i<size; i++) {
118         ProducerMessages pm = (ProducerMessages) producerMessages.elementAt(i);
119         pm.writeTo(os);
120       }
121     }
122
123     // Serialize the ackRequests Vector
124
if (ackRequests == null) {
125       StreamUtil.writeTo(-1, os);
126     } else {
127       int size = ackRequests.size();
128       StreamUtil.writeTo(size, os);
129       for (int i=0; i<size; i++) {
130         SessAckRequest sar = (SessAckRequest) ackRequests.elementAt(i);
131         sar.writeTo(os);
132       }
133     }
134
135     StreamUtil.writeTo(asyncSend, os);
136   }
137
138   /**
139    * The object implements the readFrom method to restore its contents from
140    * the input stream.
141    *
142    * @param is the stream to read data from in order to restore the object
143    */

144   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
145     super.readFrom(is);
146
147     // Gets the producerMessages Vector
148
int size = StreamUtil.readIntFrom(is);
149     if (size == -1) {
150       producerMessages = null;
151     } else {
152       producerMessages = new Vector JavaDoc(size);
153       for (int i=0; i<size; i++) {
154         ProducerMessages pm = new ProducerMessages();
155         pm.readFrom(is);
156         producerMessages.addElement(pm);
157       }
158     }
159
160     // Gets the ackRequests Vector
161
size = StreamUtil.readIntFrom(is);
162     if (size == -1) {
163       ackRequests = null;
164     } else {
165       ackRequests = new Vector JavaDoc(size);
166       for (int i=0; i<size; i++) {
167         SessAckRequest sar = new SessAckRequest();
168         sar.readFrom(is);
169         ackRequests.addElement(sar);
170       }
171     }
172
173     asyncSend = StreamUtil.readBooleanFrom(is);
174   }
175 }
176
Popular Tags