KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2006 ScalAgent Distributed Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): ScalAgent Distributed Technologies
21  * Contributor(s):
22  */

23 package org.objectweb.joram.shared.client;
24
25 import java.io.Externalizable JavaDoc;
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 /**
34  * A <code>ConsumerSubRequest</code> is sent by a constructing
35  * <code>MessageConsumer</code> destinated to consume messages on a topic.
36  */

37 public final class ConsumerSubRequest extends AbstractJmsRequest {
38   /** The subscription's name. */
39   private String JavaDoc subName;
40
41   /** Sets the subscription name. */
42   public void setSubName(String JavaDoc subName) {
43     this.subName = subName;
44   }
45
46   /** Returns the name of the subscription. */
47   public String JavaDoc getSubName() {
48     return subName;
49   }
50
51   /** The selector for filtering messages. */
52   private String JavaDoc selector;
53
54   /** Sets the selector. */
55   public void setSelector(String JavaDoc selector) {
56     this.selector = selector;
57   }
58
59   /** Returns the selector for filtering the messages. */
60   public String JavaDoc getSelector() {
61     return selector;
62   }
63
64   /**
65    * <code>true</code> if the subscriber does not wish to consume messages
66    * produced by its connection.
67    */

68   private boolean noLocal;
69
70   /** Sets the noLocal attribute. */
71   public void setNoLocal(boolean noLocal) {
72     this.noLocal = noLocal;
73   }
74
75   /** Returns <code>true</code> for not consuming the local messages. */
76   public boolean getNoLocal() {
77     return noLocal;
78   }
79
80   /** <code>true</code> if the subscription is durable. */
81   private boolean durable;
82
83   /** Sets the durable attribute. */
84   public void setDurable(boolean durable) {
85     this.durable = durable;
86   }
87
88   /** Returns <code>true</code> for a durable subscription. */
89   public boolean getDurable() {
90     return durable;
91   }
92
93   protected int getClassId() {
94     return CONSUMER_SUB_REQUEST;
95   }
96
97   /**
98    * Constructs a <code>ConsumerSubRequest</code>.
99    *
100    * @param topic The topic identifier the client wishes to subscribe to.
101    * @param subName The subscription's name.
102    * @param selector The selector for filtering messages, if any.
103    * @param noLocal <code>true</code> for not consuming the local messages.
104    * @param durable <code>true</code> for a durable subscription.
105    */

106   public ConsumerSubRequest(String JavaDoc topic, String JavaDoc subName, String JavaDoc selector,
107                             boolean noLocal, boolean durable) {
108     super(topic);
109     this.subName = subName;
110     this.selector = selector;
111     this.noLocal = noLocal;
112     this.durable = durable;
113   }
114
115   /**
116    * Constructs a <code>ConsumerSubRequest</code>.
117    */

118   public ConsumerSubRequest() {}
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     StreamUtil.writeTo(subName, os);
133     StreamUtil.writeTo(selector, os);
134     StreamUtil.writeTo(noLocal, os);
135     StreamUtil.writeTo(durable, 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     subName = StreamUtil.readStringFrom(is);
147     selector = StreamUtil.readStringFrom(is);
148     noLocal = StreamUtil.readBooleanFrom(is);
149     durable = StreamUtil.readBooleanFrom(is);
150   }
151 }
152
Popular Tags