1 /*------------------------------------------------------------------------------
2 Name: QueryQosData.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6
7 /**
8 * Data container handling of query / access QoS.
9 * <p>
10 * This data holder is accessible through decorators, each of them allowing a specialized view on the data:
11 * </p>
12 * <ul>
13 * <li>SubscribeQos QoS of a subscribe() invocation (Client side)</i>
14 * <li>UnSubscribeQos QoS of a unSubscribe() invocation (Client side)</i>
15 * <li>EraseQos QoS of an erase() invocation (Client side)</i>
16 * <li>GetQos QoS of an get() invocation (Client side)</i>
17 * </ul>
18 * <p>
19 * For the xml representation see QueryQosSaxFactory.
20 * </p>
21 * @see org.xmlBlaster.util.qos.QueryQosSaxFactory
22 * @see org.xmlBlaster.test.classtest.qos.QueryQosFactoryTest
23 * @author xmlBlaster@marcelruff.info
24 * @author michele@laghi.eu
25 */
26
27 #include <util/qos/QueryQosData.h>
28 # include <util/Constants.h>
29 # include <util/Global.h>
30
31 using namespace org::xmlBlaster::util;
32 using namespace org::xmlBlaster::util::cluster;
33
34 using namespace std;
35
36 namespace org { namespace xmlBlaster { namespace util { namespace qos {
37
38 void QueryQosData::init()
39 {
40 // QosData::init();
41 subscriptionId_ = "";
42 forceDestroy_ = false;
43 meta_ = true;
44 content_ = true;
45 multiSubscribe_ = true;
46 local_ = true;
47 initialUpdate_ = true;
48 updateOneway_ = false;
49 notify_ = true;
50 maxEntries_ = -10;
51 consumable_ = false;
52 timeout_ = 0;
53 }
54
55 void QueryQosData::copy(const QueryQosData& data)
56 {
57 QosData::copy(data);
58 subscriptionId_ = data.subscriptionId_;
59 forceDestroy_ = data.forceDestroy_;
60 meta_ = data.meta_;
61 content_ = data.content_;
62 multiSubscribe_ = data.multiSubscribe_;
63 local_ = data.local_;
64 initialUpdate_ = data.initialUpdate_;
65 updateOneway_ = data.updateOneway_;
66 notify_ = data.notify_;
67 maxEntries_ = data.maxEntries_;
68 consumable_ = data.consumable_;
69 timeout_ = data.timeout_;
70 }
71
72
73 /**
74 * Constructs the specialized quality of service object for query informations,
75 * e.g. for a subscribe() call
76 * @param The factory which knows how to serialize and parse me
77 */
78 QueryQosData::QueryQosData(Global& global)
79 : QosData(global),
80 forceDestroy_(false),
81 meta_(true),
82 content_(true),
83 multiSubscribe_(true),
84 local_(true),
85 initialUpdate_(true),
86 updateOneway_(false),
87 notify_(true),
88 filters_(),
89 historyQos_(global),
90 maxEntries_(-10),
91 consumable_(false),
92 timeout_(0L)
93 {
94 ME = "QueryQosData";
95 }
96
97
98 /**
99 * Do we want to have an initial update on subscribe if the message
100 * exists already?
101 *
102 * @return true if initial update wanted
103 * false if only updates on new publishes are sent
104 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/engine.qos.subscribe.initialUpdate.html">The engine.qos.subscribe.initialUpdate requirement</a>
105 */
106 void QueryQosData::setWantInitialUpdate(bool initialUpdate)
107 {
108 initialUpdate_ = initialUpdate;
109 }
110
111 bool QueryQosData::getWantInitialUpdate() const
112 {
113 return initialUpdate_;
114 }
115
116 /**
117 * Do we want the callback messages of this subscription as oneway with <tt>updateOneway()</tt> or with
118 * the acknowledged <tt>update()</tt>.
119 * @param updateOneway Defaults to false.
120 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/interface.subscribe.html">The interface.subscribe requirement</a>
121 * @see QueryQosData#setWantUpdateOneway(boolean)
122 */
123 void QueryQosData::setWantUpdateOneway(bool updateOneway)
124 {
125 updateOneway_ = updateOneway;
126 }
127
128 bool QueryQosData::getWantUpdateOneway() const
129 {
130 return updateOneway_;
131 }
132
133 void QueryQosData::setWantNotify(bool notify)
134 {
135 notify_ = notify;
136 }
137
138 bool QueryQosData::getWantNotify() const
139 {
140 return notify_;
141 }
142
143 void QueryQosData::setMultiSubscribe(bool multiSubscribe)
144 {
145 multiSubscribe_ = multiSubscribe;
146 }
147
148 bool QueryQosData::getMultiSubscribe() const
149 {
150 return multiSubscribe_;
151 }
152
153 /**
154 * false Inhibit the delivery of messages to myself if i have published it.
155 */
156 void QueryQosData::setWantLocal(bool local)
157 {
158 local_ = local;
159 }
160
161 /**
162 * false Inhibit the delivery of messages to myself if i have published it.
163 */
164 bool QueryQosData::getWantLocal() const
165 {
166 return local_;
167 }
168
169 /**
170 * @param meta false: Don't send me the meta information of a message key
171 */
172 void QueryQosData::setWantMeta(bool meta)
173 {
174 meta_ = meta;
175 }
176
177 /**
178 * @return false: Don't send me the meta information of a message key
179 */
180 bool QueryQosData::getWantMeta() const
181 {
182 return meta_;
183 }
184
185 /**
186 * If false, the update contains not the content (it is a notify of change only)
187 * TODO: Implement in server!!!
188 */
189 void QueryQosData::setWantContent(bool content)
190 {
191 content_ = content;
192 }
193
194 bool QueryQosData::getWantContent() const
195 {
196 return content_;
197 }
198
199 /**
200 * @param forceDestroy
201 */
202 void QueryQosData::setForceDestroy(bool forceDestroy)
203 {
204 forceDestroy_ = forceDestroy;
205 }
206
207 /**
208 * @return for erase behaviour
209 */
210 bool QueryQosData::getForceDestroy() const
211 {
212 return forceDestroy_;
213 }
214
215 /**
216 * Adds your subplied subscribe filter
217 */
218 void QueryQosData::addAccessFilter(const AccessFilterQos& filter)
219 {
220 filters_.insert(filters_.begin(), filter);
221 }
222
223 AccessFilterVector QueryQosData::getAccessFilters() const
224 {
225 return filters_;
226 }
227
228
229 /**
230 * Set the QoS which describes the history query settings.
231 */
232 void QueryQosData::setHistoryQos(const HistoryQos& historyQos)
233 {
234 historyQos_ = historyQos;
235 }
236
237 /**
238 * Get the QoS which describes the history query settings.
239 * @return never null
240 */
241 HistoryQos QueryQosData::getHistoryQos() const
242 {
243 return historyQos_;
244 }
245
246 void QueryQosData::setQueryQos(int maxEntries, long timeout, bool consumable) {
247 maxEntries_ = maxEntries;
248 timeout_ = timeout;
249 consumable_ = consumable;
250 }
251
252 /**
253 * Get the identifier (unique handle) for this subscription.
254 * @return The id or null if not specified by client.
255 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/engine.qos.subscribe.id.html">The engine.qos.subscribe.id requirement</a>
256 */
257 string QueryQosData::getSubscriptionId() const
258 {
259 return subscriptionId_;
260 }
261
262 /**
263 * Force the identifier (unique handle) for this subscription.
264 * Usually you let the identifier be generated by xmlBlaster.
265 * @see <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/engine.qos.subscribe.id.html">The engine.qos.subscribe.id requirement</a>
266 */
267 void QueryQosData::setSubscriptionId(const string& subscriptionId)
268 {
269 subscriptionId_ = subscriptionId;
270 }
271
272
273 /**
274 * Dump state of this object into a XML ASCII string.
275 * <br>
276 * @param extraOffset indenting of tags for nice output
277 * @return internal state of the query as a XML ASCII string
278 */
279 string QueryQosData::toXml(const string& extraOffset) const
280 {
281 string ret;
282 string offset = Constants::OFFSET + extraOffset;
283
284 ret += offset + "<qos>"; // <!-- SubscribeRetQos -->");
285 if (!subscriptionId_.empty())
286 ret += offset + " <subscribe id='" + subscriptionId_ + "'/>";
287 ret += offset + " <erase forceDestroy='" + Global::getBoolAsString(forceDestroy_) + "'/>";
288
289 if (!meta_) ret += offset + " <meta>false</meta>";
290 if (!content_) ret += offset + " <content>false</content>";
291 if (!multiSubscribe_) ret += offset + " <multiSubscribe>false</multiSubscribe>";
292 if (!local_) ret += offset + " <local>false</local>";
293 if (!initialUpdate_) ret += offset + " <initialUpdate>false</initialUpdate>";
294 if (updateOneway_) ret += offset + " <updateOneway/>";
295 if (!notify_) ret += offset + " <notify>false</notify>";
296 if (isPersistent())
297 ret += offset + " <persistent/>";
298
299 AccessFilterVector::const_iterator iter = filters_.begin();
300 while (iter != filters_.end()) {
301 ret += (*iter).toXml(extraOffset + Constants::INDENT);
302 iter++;
303 }
304
305 if (maxEntries_ != -10) {
306 ret += offset +
307 "<querySpec type='QueueQuery'>" +
308 "maxEntries="+
309 lexical_cast<std::string>(maxEntries_)+
310 "&maxSize=-1&consumable="+
311 lexical_cast<std::string>(consumable_)+
312 "&waitingDelay="+
313 lexical_cast<std::string>(timeout_)+
314 "</querySpec>";
315 }
316
317 ret += historyQos_.toXml(extraOffset + Constants::INDENT);
318 bool clearText = false;
319 ret += dumpClientProperties(extraOffset + Constants::INDENT, clearText);
320 ret += offset + "</qos>";
321
322 if (ret.length() < 16)
323 return "<qos/>"; // minimal footprint
324
325 return ret;
326 }
327
328 QueryQosData* QueryQosData::getClone() const
329 {
330 return new QueryQosData(*this);
331 }
332
333 }}}} // namespace
syntax highlighted by Code2HTML, v. 0.9.1