KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > mom > notifications > ClientMessages


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.mom.notifications;
25
26 import fr.dyade.aaa.agent.AgentId;
27 import org.objectweb.joram.shared.messages.Message;
28
29 import java.util.Vector JavaDoc;
30
31 /**
32  * A <code>ClientMessages</code> instance is used by a client agent for
33  * sending one or many messages to a destination.
34  */

35 public class ClientMessages extends AbstractRequest {
36   /** Message sent by the client. */
37   private Message message = null;
38   /** Messages sent by the client. */
39   private Vector JavaDoc messages = null;
40   /** Identifier of the producer's dead message queue, if any. */
41   private AgentId producerDMQId = null;
42   
43   private boolean asyncSend;
44
45   /**
46    * Constructs a <code>ClientMessages</code> instance.
47    *
48    * @param clientContext Identifies a client context.
49    * @param requestId Request identifier.
50    */

51   public ClientMessages(int clientContext, int requestId) {
52     super(clientContext, requestId);
53   }
54
55   /**
56    * Constructs a <code>ClientMessages</code> instance.
57    *
58    * @param clientContext Identifies a client context.
59    * @param requestId Request identifier.
60    * @param messages The message.
61    */

62   public ClientMessages(int clientContext, int requestId, Message message) {
63     super(clientContext, requestId);
64     this.message = message;
65   }
66
67   /**
68    * Constructs a <code>ClientMessages</code> instance.
69    *
70    * @param clientContext Identifies a client context.
71    * @param requestId Request identifier.
72    * @param messages Vector of messages.
73    */

74   public ClientMessages(int clientContext, int requestId, Vector JavaDoc messages) {
75     super(clientContext, requestId);
76     if (messages.size() == 1)
77       message = (Message) messages.get(0);
78     else
79       this.messages = messages;
80   }
81
82   /**
83    * Constructs a <code>ClientMessages</code> instance.
84    */

85   public ClientMessages() {}
86
87
88   /** Adds a message to deliver. */
89   public void addMessage(Message msg) {
90     if (message == null && messages == null)
91       message = msg;
92     else {
93       if (messages == null) {
94         messages = new Vector JavaDoc();
95         messages.add(message);
96         message = null;
97       }
98       messages.add(msg);
99     }
100   }
101
102   /** Sets the identifier of the producer's dead message queue, if any. */
103   public void setDMQId(AgentId dmqId) {
104     producerDMQId = dmqId;
105   }
106
107   
108   /** Returns the messages. */
109   public Vector JavaDoc getMessages() {
110     if (messages == null) {
111       messages = new Vector JavaDoc();
112       if (message != null)
113         messages.add(message);
114     }
115     return messages;
116   }
117   
118   public void setAsyncSend(boolean b) {
119     asyncSend = b;
120   }
121   
122   public final boolean getAsyncSend() {
123     return asyncSend;
124   }
125
126   /** Returns the identifier of the producer's dead message queue, if any. */
127   public AgentId getDMQId() {
128     return producerDMQId;
129   }
130
131   /**
132    * Appends a string image for this object to the StringBuffer parameter.
133    *
134    * @param output
135    * buffer to fill in
136    * @return
137     <code>output</code> buffer is returned
138    */

139   public StringBuffer JavaDoc toString(StringBuffer JavaDoc output) {
140     output.append('(');
141     super.toString(output);
142     output.append(",message=").append(message);
143     output.append(",messages=").append(messages);
144     output.append(",producerDMQId=").append(producerDMQId);
145     output.append(",asyncSend=").append(asyncSend);
146     output.append(')');
147
148     return output;
149   }
150 }
151
Popular Tags