KickJava   Java API By Example, From Geeks To Geeks.

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


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
30 import org.objectweb.joram.shared.stream.Streamable;
31 import org.objectweb.joram.shared.stream.StreamUtil;
32
33 import fr.dyade.aaa.util.Strings;
34
35 /**
36  * A <code>ConsumerSetListRequest</code> is sent by a
37  * <code>MessageConsumer</code> on which a message listener is set.
38  */

39 public final class ConsumerSetListRequest extends AbstractJmsRequest {
40   /** Selector for filtering messages on a queue. */
41   private String JavaDoc selector;
42
43   /** Sets the selector. */
44   public void setSelector(String JavaDoc selector) {
45     this.selector = selector;
46   }
47
48   /** Returns the selector for filtering messages. */
49   public String JavaDoc getSelector() {
50     return selector;
51   }
52
53   /** <code>true</code> if the request is destinated to a queue. */
54   private boolean queueMode;
55   
56   /** Sets the target destination type. */
57   public void setQueueMode(boolean queueMode) {
58     this.queueMode = queueMode;
59   }
60
61   /** Returns <code>true</code> if the request is destinated to a queue. */
62   public boolean getQueueMode() {
63     return queueMode;
64   }
65
66   private String JavaDoc[] msgIdsToAck;
67
68   public final String JavaDoc[] getMessageIdsToAck() {
69     return msgIdsToAck;
70   }
71
72   private int msgCount;
73
74   public final int getMessageCount() {
75     return msgCount;
76   }
77
78   protected int getClassId() {
79     return CONSUMER_SET_LIST_REQUEST;
80   }
81
82   /**
83    * Constructs a <code>ConsumerSetListRequest</code>.
84    *
85    * @param targetName Name of the target queue or subscription.
86    * @param selector Selector for filtering messages.
87    * @param queueMode <code>true</code> if this request is destinated to a
88    * queue.
89    */

90   public ConsumerSetListRequest(String JavaDoc targetName,
91                                 String JavaDoc selector,
92                                 boolean queueMode,
93                                 String JavaDoc[] msgIdsToAck,
94                                 int msgCount) {
95     super(targetName);
96     this.selector = selector;
97     this.queueMode = queueMode;
98     this.msgIdsToAck = msgIdsToAck;
99     this.msgCount = msgCount;
100   }
101
102   /**
103    * Constructs a <code>ConsumerSetListRequest</code>.
104    */

105   public ConsumerSetListRequest() {
106   }
107
108   public void toString(StringBuffer JavaDoc strbuf) {
109     super.toString(strbuf);
110     strbuf.append(",selector=").append(selector);
111     strbuf.append(",queueMode=").append(queueMode);
112     strbuf.append(",msgIdsToAck=");
113     Strings.toString(strbuf, msgIdsToAck);
114     strbuf.append(",msgCount=").append(msgCount);
115     strbuf.append(')');
116   }
117
118   /**
119    * The object implements the writeTo method to write its contents to
120    * the output stream.
121    *
122    * @param os the stream to write the object to
123    */

124   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
125     super.writeTo(os);
126     StreamUtil.writeTo(selector, os);
127     StreamUtil.writeTo(queueMode, os);
128     if (msgIdsToAck == null) {
129       StreamUtil.writeTo(-1, os);
130     } else {
131       int size = msgIdsToAck.length;
132       StreamUtil.writeTo(size, os);
133       for (int i=0; i<size; i++) {
134         StreamUtil.writeTo(msgIdsToAck[i], os);
135       }
136     }
137     StreamUtil.writeTo(msgCount, os);
138   }
139
140   /**
141    * The object implements the readFrom method to restore its contents from
142    * the input stream.
143    *
144    * @param is the stream to read data from in order to restore the object
145    */

146   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
147     super.readFrom(is);
148     selector = StreamUtil.readStringFrom(is);
149     queueMode = StreamUtil.readBooleanFrom(is);
150     int size = StreamUtil.readIntFrom(is);
151     if (size == -1) {
152       msgIdsToAck = null;
153     } else {
154       msgIdsToAck = new String JavaDoc[size];
155       for (int i=0; i<size; i++) {
156         msgIdsToAck[i] = StreamUtil.readStringFrom(is);
157       }
158     }
159     msgCount = StreamUtil.readIntFrom(is);
160   }
161 }
162
Popular Tags