KickJava   Java API By Example, From Geeks To Geeks.

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


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.Enumeration JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import org.objectweb.joram.shared.messages.Message;
34 import org.objectweb.joram.shared.stream.Streamable;
35 import org.objectweb.joram.shared.stream.StreamUtil;
36
37 /**
38  * A <code>ProducerMessages</code> instance is sent by a
39  * <code>MessageProducer</code> when sending messages.
40  */

41 public final class ProducerMessages extends AbstractJmsRequest {
42   /** The wrapped messages. */
43   private Vector JavaDoc messages = null;
44
45   /**
46    * Indicates whether the produced messages
47    * are asynchronously send or not
48    * (without or with an acknowledgement).
49    */

50   private boolean asyncSend = false;
51   
52   public void setAsyncSend(boolean b) {
53     asyncSend = b;
54   }
55   
56   public final boolean getAsyncSend() {
57     return asyncSend;
58   }
59
60   /** Returns the produced messages. */
61   public Vector JavaDoc getMessages() {
62     if (messages == null)
63       messages = new Vector JavaDoc();
64     return messages;
65   }
66
67   /** Adds a message to deliver. */
68   public void addMessage(Message msg) {
69     if (messages == null)
70       messages = new Vector JavaDoc();
71     messages.addElement(msg);
72   }
73
74   /** Adds messages to deliver. */
75   public void addMessages(Vector JavaDoc msgs) {
76     if (messages == null)
77       messages = new Vector JavaDoc();
78     for (Enumeration JavaDoc e = msgs.elements(); e.hasMoreElements(); )
79       messages.addElement(e.nextElement());
80   }
81
82   protected int getClassId() {
83     return PRODUCER_MESSAGES;
84   }
85
86   /**
87    * Constructs a <code>ProducerMessages</code> instance.
88    *
89    * @param dest Name of the destination the messages are sent to.
90    */

91   public ProducerMessages(String JavaDoc dest) {
92     super(dest);
93   }
94
95   /**
96    * Constructs a <code>ProducerMessages</code> instance carrying a single
97    * message.
98    *
99    * @param dest Name of the destination the messages are sent to.
100    * @param msg Message to carry.
101    */

102   public ProducerMessages(String JavaDoc dest, Message msg) {
103     super(dest);
104     messages = new Vector JavaDoc();
105     messages.addElement(msg);
106   }
107
108   /**
109    * Constructs a <code>ProducerMessages</code> instance.
110    */

111   public ProducerMessages() {}
112
113   public void toString(StringBuffer JavaDoc strbuf) {
114     super.toString(strbuf);
115     strbuf.append(",messages=").append(messages);
116     strbuf.append(",asyncSend=").append(asyncSend);
117     strbuf.append(')');
118   }
119
120   /* ***** ***** ***** ***** *****
121    * Streamable interface
122    * ***** ***** ***** ***** ***** */

123
124   /**
125    * The object implements the writeTo method to write its contents to
126    * the output stream.
127    *
128    * @param os the stream to write the object to
129    */

130   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
131     super.writeTo(os);
132     Message.writeVectorTo(messages, os);
133     StreamUtil.writeTo(asyncSend, os);
134   }
135
136   /**
137    * The object implements the readFrom method to restore its contents from
138    * the input stream.
139    *
140    * @param is the stream to read data from in order to restore the object
141    */

142   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
143     super.readFrom(is);
144     messages = Message.readVectorFrom(is);
145     asyncSend = StreamUtil.readBooleanFrom(is);
146   }
147 }
148
Popular Tags