1 /*------------------------------------------------------------------------------
2 Name: ConnectQos.cpp
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: Implementation of ConnectQos (ConnectReturnQos ConnectQosData)
6 ------------------------------------------------------------------------------*/
7
8 #include <util/qos/ConnectQos.h>
9 #include <util/Global.h>
10 #include <util/Constants.h>
11 #include <util/lexical_cast.h>
12 #include <util/Global.h>
13
14
15 namespace org { namespace xmlBlaster { namespace util { namespace qos {
16
17 using namespace std;
18 using namespace org::xmlBlaster::authentication;
19 using namespace org::xmlBlaster::util;
20 using namespace org::xmlBlaster::util::qos::storage;
21 using namespace org::xmlBlaster::util::qos::address;
22
23 /*---------------------------- ConnectQosData --------------------------------*/
24
25 ConnectQosData::ConnectQosData(Global& global, const string& user, const string& passwd, long publicSessionId)
26 : global_(global),
27 log_(global.getLog("org.xmlBlaster.util.qos")),
28 securityQos_(global, user, passwd),
29 sessionQos_(new SessionQos(global, user, publicSessionId)),
30 ptp_(true),
31 //addresses_(),
32 //cbAddresses_(),
33 clientQueueProperties_(),
34 sessionCbQueueProperty_(global, Constants::RELATING_CALLBACK, ""),
35 serverReferences_(),
36 clientProperties_()
37 {
38 clusterNode_ = false;
39 refreshSession_ = false;
40 duplicateUpdates_ = true;
41 reconnected_ = false;
42 instanceId_ = global_.getInstanceId();
43 persistent_ = false;
44 if (user=="") { // Copy env setting to SecurityQos
45 securityQos_.setUserId(sessionQos_->getSessionName()->getSubjectId());
46 }
47 getAddress(); // Force creation, to read environment, Note: The CB address is only read if a callback server is created
48 }
49
50 ConnectQosData::ConnectQosData(const ConnectQosData& data)
51 : global_(data.global_),
52 log_(data.log_),
53 securityQos_(data.securityQos_),
54 sessionQos_(data.sessionQos_),
55 //addresses_(data.addresses_),
56 //cbAddresses_(data.cbAddresses_),
57 clientQueueProperties_(data.clientQueueProperties_),
58 sessionCbQueueProperty_(data.sessionCbQueueProperty_),
59 serverReferences_(data.serverReferences_),
60 clientProperties_()
61 {
62 copy(data);
63 }
64
65 ConnectQosData& ConnectQosData::operator =(const ConnectQosData& data)
66 {
67 copy(data);
68 return *this;
69 }
70
71 ConnectQosData::~ConnectQosData()
72 {
73 }
74
75
76 bool ConnectQosData::getPtp() const
77 {
78 return ptp_;
79 }
80
81 const string& ConnectQosData::getBoolAsString(bool val) const
82 {
83 return global_.getBoolAsString(val);
84 }
85
86 void ConnectQosData::setPtp(bool ptp)
87 {
88 ptp_ = ptp;
89 }
90
91 void ConnectQosData::setSessionQos(const SessionQos& sessionQos)
92 {
93 SessionQos *p = new SessionQos(sessionQos);
94 SessionQosRef r(p);
95 sessionQos_ = r;
96 }
97
98 SessionQos& ConnectQosData::getSessionQos() const
99 {
100 return *sessionQos_;
101 }
102
103
104 void ConnectQosData::setSessionQos(SessionQosRef sessionQos) {
105 sessionQos_ = sessionQos;
106 }
107
108 SessionQosRef ConnectQosData::getSessionQosRef() const {
109 return sessionQos_;
110 }
111
112
113
114 string ConnectQosData::getSecretSessionId() const
115 {
116 return sessionQos_->getSecretSessionId();
117 }
118
119 string ConnectQosData::getUserId() const
120 {
121 return sessionQos_->getAbsoluteName();
122 }
123
124 string ConnectQosData::getCallbackType() const
125 {
126 return sessionCbQueueProperty_.getType();
127 }
128
129 void ConnectQosData::setSecurityQos(const SecurityQos& securityQos)
130 {
131 securityQos_ = securityQos;
132 }
133
134 SecurityQos& ConnectQosData::getSecurityQos() const
135 {
136 return securityQos_;
137 }
138
139 void ConnectQosData::setClusterNode(bool clusterNode)
140 {
141 clusterNode_ = clusterNode;
142 }
143
144 bool ConnectQosData::isClusterNode() const
145 {
146 return clusterNode_;
147 }
148
149 void ConnectQosData::setRefreshSession(bool refreshSession)
150 {
151 refreshSession_ = refreshSession;
152 }
153
154 bool ConnectQosData::isRefreshSession() const
155 {
156 return refreshSession_;
157 }
158
159 void ConnectQosData::setDuplicateUpdates(bool duplicateUpdates)
160 {
161 duplicateUpdates_ = duplicateUpdates;
162 }
163
164 bool ConnectQosData::isDuplicateUpdates() const
165 {
166 return duplicateUpdates_;
167 }
168
169 void ConnectQosData::addServerRef(const ServerRef& serverRef)
170 {
171 serverReferences_.insert(serverReferences_.begin(), serverRef);
172 }
173
174 const vector<ServerRef> ConnectQosData::getServerReferences() const
175 {
176 return serverReferences_;
177 }
178
179 ServerRef ConnectQosData::getServerRef()
180 {
181 if (serverReferences_.empty()) {
182 addServerRef(ServerRef(Global::getDefaultProtocol()));
183 }
184 return *(serverReferences_.begin());
185 }
186
187 // methods for queues and addresses ...
188
189 void ConnectQosData::setAddress(const AddressBaseRef& address)
190 {
191 getClientQueueProperty().setAddress(address);
192 //addresses_.insert(addresses_.begin(), address);
193 }
194
195 AddressBaseRef ConnectQosData::getAddress()
196 {
197 return getClientQueueProperty().getCurrentAddress();
198 //return reinterpret_cast<Address&>(ab);
199 /*
200 if (addresses_.empty()) {
201 setAddress(Address(global_));
202 }
203 return *(addresses_.begin());
204 */
205 }
206
207 void ConnectQosData::addCbAddress(const AddressBaseRef& cbAddress)
208 {
209 sessionCbQueueProperty_.setCallbackAddress(cbAddress);
210 //cbAddresses_.insert(cbAddresses_.begin(), cbAddress);
211 }
212
213 AddressBaseRef ConnectQosData::getCbAddress()
214 {
215 return sessionCbQueueProperty_.getCurrentCallbackAddress();
216 //org::xmlBlaster::util::qos::address::AddressBaseRef ab = sessionCbQueueProperty_.getCurrentCallbackAddress();
217 //return ab; reinterpret_cast<CallbackAddress&>(ab);//sessionCbQueueProperty_.getCurrentCallbackAddress();
218 //if (cbAddresses_.empty()) {
219 // addCbAddress(CallbackAddress(global_));
220 //}
221 //return *(cbAddresses_.begin());
222 }
223
224 void ConnectQosData::addClientQueueProperty(const ClientQueueProperty& prop)
225 {
226 clientQueueProperties_.insert(clientQueueProperties_.begin(), prop);
227 }
228
229 ClientQueueProperty& ConnectQosData::getClientQueueProperty()
230 {
231 if (clientQueueProperties_.empty()) {
232 addClientQueueProperty(ClientQueueProperty(global_, ""));
233 }
234 return *(clientQueueProperties_.begin());
235 }
236
237 void ConnectQosData::setSessionCbQueueProperty(const CbQueueProperty& prop)
238 {
239 sessionCbQueueProperty_ = prop;
240 }
241
242 CbQueueProperty& ConnectQosData::getSessionCbQueueProperty()
243 {
244 return sessionCbQueueProperty_;
245 }
246
247 void ConnectQosData::addClientProperty(const ClientProperty& clientProperty)
248 {
249 clientProperties_.insert(ClientPropertyMap::value_type(clientProperty.getName(), clientProperty));
250 }
251
252 const ConnectQosData::ClientPropertyMap& ConnectQosData::getClientProperties() const
253 {
254 return clientProperties_;
255 }
256
257 bool ConnectQosData::isReconnected() const
258 {
259 return reconnected_;
260 }
261
262 void ConnectQosData::setReconnected(bool reconnected)
263 {
264 reconnected_ = reconnected;
265 }
266
267 std::string ConnectQosData::getInstanceId() const
268 {
269 return instanceId_;
270 }
271
272 void ConnectQosData::setInstanceId(std::string instanceId)
273 {
274 instanceId_ = instanceId;
275 }
276
277 /**
278 * @param persistent mark a message as persistent
279 */
280 void ConnectQosData::setPersistent(bool persistent)
281 {
282 persistent_ = persistent;
283 }
284
285 /**
286 * @return true/false
287 */
288 bool ConnectQosData::isPersistent() const
289 {
290 return persistent_;
291 }
292
293 string ConnectQosData::dumpClientProperties(const string& extraOffset, bool clearText) const
294 {
295 string ret = "";
296 QosData::ClientPropertyMap::const_iterator iter = clientProperties_.begin();
297 while (iter != clientProperties_.end()) {
298 const ClientProperty& cp = (*iter).second;
299 ret += cp.toXml(extraOffset, clearText);
300 iter++;
301 }
302 return ret;
303 }
304
305 /**
306 * Dump state of this object into a XML ASCII string.
307 * <br>
308 * @param extraOffset indenting of tags for nice output
309 * @return internal state of the RequestBroker as a XML ASCII string
310 */
311 string ConnectQosData::toXml(const string& extraOffset) const
312 {
313 string offset = Constants::OFFSET + extraOffset;
314 string offset2 = offset + Constants::INDENT;
315 string indent = extraOffset+Constants::INDENT;
316 string ret;
317 ret += offset + string("<qos>");
318
319 // <securityService ...
320 ret += securityQos_.toXml(indent);
321 ret += offset2 + string("<ptp>") + getBoolAsString(ptp_) + string("</ptp>");
322
323 if (isClusterNode())
324 ret += offset2 + string("<clusterNode>") + getBoolAsString(isClusterNode()) + string("</clusterNode>");
325
326 if (isRefreshSession())
327 ret += offset2 + string("<refreshSession>") + getBoolAsString(isRefreshSession()) + string("</refreshSession>");
328
329 if (isDuplicateUpdates() == false)
330 ret += offset2 + string("<duplicateUpdates>") + getBoolAsString(isDuplicateUpdates()) + string("</duplicateUpdates>");
331
332 if (isReconnected())
333 ret += offset + " <reconnected/>";
334
335 if (getInstanceId().length() > 0)
336 ret += offset + " <instanceId>" + getInstanceId() + "</instanceId>";
337
338 if (isPersistent())
339 ret += offset + " <persistent/>";
340
341 ret += sessionQos_->toXml(indent);
342
343 { // client queue properties
344 vector<ClientQueueProperty>::const_iterator
345 iter = clientQueueProperties_.begin();
346 while (iter != clientQueueProperties_.end()) {
347 ret += (*iter).toXml(indent);
348 iter++;
349 }
350 }
351
352 ret += sessionCbQueueProperty_.toXml(indent);
353
354 { //serverReferences
355 vector<ServerRef>::const_iterator
356 iter = serverReferences_.begin();
357 while (iter != serverReferences_.end()) {
358 ret += (*iter).toXml(indent);
359 iter++;
360 }
361 }
362
363 ret += dumpClientProperties(offset2);
364
365 ret += offset + string("</qos>");
366 return ret;
367 }
368
369 }}}} // namespaces
syntax highlighted by Code2HTML, v. 0.9.1