util/qos/ConnectQos.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      ConnectQos.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 Comment:   Implementation of ConnectQos (ConnectReturnQos ConnectQosData)
00006 ------------------------------------------------------------------------------*/
00007 
00008 #include <util/qos/ConnectQos.h>
00009 #include <util/Global.h>
00010 #include <util/Constants.h>
00011 #include <util/lexical_cast.h>
00012 #include <util/Global.h>
00013 
00014 
00015 namespace org { namespace xmlBlaster { namespace util { namespace qos {
00016 
00017 using namespace std;
00018 using namespace org::xmlBlaster::authentication;
00019 using namespace org::xmlBlaster::util;
00020 using namespace org::xmlBlaster::util::qos::storage;
00021 using namespace org::xmlBlaster::util::qos::address;
00022 
00023 /*---------------------------- ConnectQosData --------------------------------*/
00024 
00025 ConnectQosData::ConnectQosData(Global& global, const string& user, const string& passwd, long publicSessionId)
00026     : global_(global),
00027       log_(global.getLog("org.xmlBlaster.util.qos")),
00028       securityQos_(global, user, passwd),
00029       sessionQos_(new SessionQos(global, user, publicSessionId)),
00030       ptp_(true),
00031       //addresses_(),
00032       //cbAddresses_(),
00033       clientQueueProperties_(),
00034       sessionCbQueueProperty_(global, Constants::RELATING_CALLBACK, ""),
00035       serverReferences_(),
00036       clientProperties_()
00037 {
00038    clusterNode_      = false;
00039    refreshSession_   = false;
00040    duplicateUpdates_ = true;
00041    reconnected_      = false;
00042    instanceId_       = global_.getInstanceId();
00043    persistent_       = false;
00044    if (user=="") { // Copy env setting to SecurityQos
00045       securityQos_.setUserId(sessionQos_->getSessionName()->getSubjectId());
00046    }
00047    getAddress();      // Force creation, to read environment, Note: The CB address is only read if a callback server is created
00048 }
00049 
00050 ConnectQosData::ConnectQosData(const ConnectQosData& data)
00051     : global_(data.global_),
00052       log_(data.log_),
00053       securityQos_(data.securityQos_),
00054       sessionQos_(data.sessionQos_),
00055       //addresses_(data.addresses_),
00056       //cbAddresses_(data.cbAddresses_),
00057       clientQueueProperties_(data.clientQueueProperties_),
00058       sessionCbQueueProperty_(data.sessionCbQueueProperty_),
00059       serverReferences_(data.serverReferences_),
00060       clientProperties_()
00061 {
00062    copy(data);
00063 }
00064 
00065 ConnectQosData& ConnectQosData::operator =(const ConnectQosData& data)
00066 {
00067    copy(data);
00068    return *this;
00069 }
00070 
00071 bool ConnectQosData::getPtp() const
00072 {
00073    return ptp_;
00074 }
00075 
00076 const string& ConnectQosData::getBoolAsString(bool val) const
00077 {
00078    return global_.getBoolAsString(val);
00079 }
00080 
00081 void ConnectQosData::setPtp(bool ptp)
00082 {
00083    ptp_ = ptp;
00084 }
00085 
00086 void ConnectQosData::setSessionQos(const SessionQos& sessionQos)
00087 {
00088    SessionQos *p = new SessionQos(sessionQos);
00089    SessionQosRef r(p);
00090    sessionQos_ = r;
00091 }
00092 
00093 SessionQos& ConnectQosData::getSessionQos() const
00094 {
00095    return *sessionQos_;
00096 }
00097 
00098 
00099 void ConnectQosData::setSessionQos(SessionQosRef sessionQos) {
00100    sessionQos_ = sessionQos;
00101 }
00102 
00103 SessionQosRef ConnectQosData::getSessionQosRef() const {
00104    return sessionQos_;
00105 }
00106 
00107 
00108 
00109 string ConnectQosData::getSecretSessionId() const
00110 {
00111    return sessionQos_->getSecretSessionId();
00112 }
00113 
00114 string ConnectQosData::getUserId() const
00115 {
00116    return sessionQos_->getAbsoluteName();
00117 }
00118 
00119 string ConnectQosData::getCallbackType() const
00120 {
00121    return sessionCbQueueProperty_.getType();
00122 }
00123 
00124 void ConnectQosData::setSecurityQos(const SecurityQos& securityQos)
00125 {
00126    securityQos_ = securityQos;
00127 }
00128 
00129 SecurityQos& ConnectQosData::getSecurityQos() const
00130 {
00131    return securityQos_;
00132 }
00133 
00134 void ConnectQosData::setClusterNode(bool clusterNode)
00135 {
00136    clusterNode_ = clusterNode;
00137 }
00138 
00139 bool ConnectQosData::isClusterNode() const
00140 {
00141    return clusterNode_;
00142 }
00143 
00144 void ConnectQosData::setRefreshSession(bool refreshSession)
00145 {
00146    refreshSession_ = refreshSession;
00147 }
00148 
00149 bool ConnectQosData::isRefreshSession() const
00150 {
00151    return refreshSession_;
00152 }
00153 
00154 void ConnectQosData::setDuplicateUpdates(bool duplicateUpdates)
00155 {
00156    duplicateUpdates_ = duplicateUpdates;
00157 }
00158 
00159 bool ConnectQosData::isDuplicateUpdates() const
00160 {
00161    return duplicateUpdates_;
00162 }
00163 
00164 void ConnectQosData::addServerRef(const ServerRef& serverRef)
00165 {
00166    serverReferences_.insert(serverReferences_.begin(), serverRef);
00167 }
00168 
00169 const vector<ServerRef> ConnectQosData::getServerReferences() const
00170 {
00171    return serverReferences_;
00172 }
00173 
00174 ServerRef ConnectQosData::getServerRef()
00175 {
00176    if (serverReferences_.empty()) {
00177       addServerRef(ServerRef(Global::getDefaultProtocol()));
00178    }
00179    return *(serverReferences_.begin());
00180 }
00181 
00182 // methods for queues and addresses ...
00183 
00184 void ConnectQosData::setAddress(const AddressBaseRef& address)
00185 {
00186    getClientQueueProperty().setAddress(address);
00187    //addresses_.insert(addresses_.begin(), address);
00188 }
00189 
00190 AddressBaseRef ConnectQosData::getAddress()
00191 {
00192    return getClientQueueProperty().getCurrentAddress();
00193    //return reinterpret_cast<Address&>(ab);
00194    /*
00195    if (addresses_.empty()) {
00196       setAddress(Address(global_));
00197    }
00198    return *(addresses_.begin());
00199    */
00200 }
00201 
00202 void ConnectQosData::addCbAddress(const AddressBaseRef& cbAddress)
00203 {
00204    sessionCbQueueProperty_.setCallbackAddress(cbAddress);
00205    //cbAddresses_.insert(cbAddresses_.begin(), cbAddress);
00206 }
00207 
00208 AddressBaseRef ConnectQosData::getCbAddress()
00209 {
00210    return sessionCbQueueProperty_.getCurrentCallbackAddress();
00211    //org::xmlBlaster::util::qos::address::AddressBaseRef ab = sessionCbQueueProperty_.getCurrentCallbackAddress();
00212    //return ab; reinterpret_cast<CallbackAddress&>(ab);//sessionCbQueueProperty_.getCurrentCallbackAddress();
00213    //if (cbAddresses_.empty()) {
00214    //   addCbAddress(CallbackAddress(global_));
00215    //}
00216    //return *(cbAddresses_.begin());
00217 }
00218 
00219 void ConnectQosData::addClientQueueProperty(const ClientQueueProperty& prop)
00220 {
00221    clientQueueProperties_.insert(clientQueueProperties_.begin(), prop);
00222 }
00223 
00224 ClientQueueProperty& ConnectQosData::getClientQueueProperty()
00225 {
00226    if (clientQueueProperties_.empty()) {
00227       addClientQueueProperty(ClientQueueProperty(global_, ""));
00228    }
00229    return *(clientQueueProperties_.begin());
00230 }
00231 
00232 void ConnectQosData::setSessionCbQueueProperty(const CbQueueProperty& prop)
00233 {
00234    sessionCbQueueProperty_ = prop;
00235 }
00236 
00237 CbQueueProperty& ConnectQosData::getSessionCbQueueProperty()
00238 {
00239    return sessionCbQueueProperty_;
00240 }
00241 
00242 void ConnectQosData::addClientProperty(const ClientProperty& clientProperty)
00243 {
00244    clientProperties_.insert(ClientPropertyMap::value_type(clientProperty.getName(), clientProperty));   
00245 }
00246 
00247 const ConnectQosData::ClientPropertyMap& ConnectQosData::getClientProperties() const
00248 {
00249    return clientProperties_;
00250 }
00251 
00252 bool ConnectQosData::isReconnected() const
00253 {
00254    return reconnected_;
00255 }
00256 
00257 void ConnectQosData::setReconnected(bool reconnected)
00258 {
00259    reconnected_ = reconnected;
00260 }
00261 
00262 std::string ConnectQosData::getInstanceId() const
00263 {
00264    return instanceId_;
00265 }
00266 
00267 void ConnectQosData::setInstanceId(std::string instanceId)
00268 {
00269    instanceId_ = instanceId;
00270 }
00271 
00275 void ConnectQosData::setPersistent(bool persistent)
00276 {
00277    persistent_ = persistent;
00278 }
00279 
00283 bool ConnectQosData::isPersistent() const
00284 {
00285    return persistent_;
00286 }
00287 
00288 string ConnectQosData::dumpClientProperties(const string& extraOffset, bool clearText) const
00289 {
00290    string ret = "";
00291    QosData::ClientPropertyMap::const_iterator iter = clientProperties_.begin();
00292    while (iter != clientProperties_.end()) {
00293       const ClientProperty& cp = (*iter).second;
00294       ret += cp.toXml(extraOffset, clearText);
00295       iter++;
00296    }
00297    return ret;
00298 }
00299 
00306 string ConnectQosData::toXml(const string& extraOffset) const
00307 {
00308    string offset = Constants::OFFSET + extraOffset;
00309    string offset2 = offset + Constants::INDENT;
00310    string indent = extraOffset+Constants::INDENT;
00311    string ret;
00312    ret += offset + string("<qos>");
00313 
00314    // <securityService ...
00315    ret += securityQos_.toXml(indent);
00316    ret += offset2 + string("<ptp>") + getBoolAsString(ptp_)  + string("</ptp>");
00317 
00318    if (isClusterNode())
00319       ret += offset2 + string("<clusterNode>") + getBoolAsString(isClusterNode()) + string("</clusterNode>");
00320 
00321    if (isRefreshSession())
00322       ret += offset2 + string("<refreshSession>") + getBoolAsString(isRefreshSession()) + string("</refreshSession>");
00323 
00324    if (isDuplicateUpdates() == false)
00325       ret += offset2 + string("<duplicateUpdates>") + getBoolAsString(isDuplicateUpdates()) + string("</duplicateUpdates>");
00326 
00327    if (isReconnected())
00328       ret += offset + " <reconnected/>";
00329 
00330    if (getInstanceId().length() > 0)
00331       ret += offset + " <instanceId>" + getInstanceId() + "</instanceId>";
00332 
00333    if (isPersistent())
00334       ret += offset + " <persistent/>";
00335 
00336    ret += sessionQos_->toXml(indent);
00337 
00338    {  // client queue properties 
00339       vector<ClientQueueProperty>::const_iterator
00340          iter = clientQueueProperties_.begin();
00341       while (iter != clientQueueProperties_.end()) {
00342          ret += (*iter).toXml(indent);
00343          iter++;
00344       }
00345    }
00346 
00347    ret += sessionCbQueueProperty_.toXml(indent);
00348 
00349    {  //serverReferences
00350       vector<ServerRef>::const_iterator
00351          iter = serverReferences_.begin();
00352       while (iter != serverReferences_.end()) {
00353          ret += (*iter).toXml(indent);
00354          iter++;
00355       }
00356    }
00357 
00358    ret += dumpClientProperties(offset2);
00359 
00360    ret += offset + string("</qos>");
00361    return ret;
00362 }
00363 
00364 }}}} // namespaces
00365