client/qos/SubscribeQos.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      SubscribeQos.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00016 #include <client/qos/SubscribeQos.h>
00017 #include <util/Global.h>
00018 
00019 using namespace std;
00020 using namespace org::xmlBlaster::util;
00021 using namespace org::xmlBlaster::util::qos;
00022 
00023 namespace org { namespace xmlBlaster { namespace client { namespace qos {
00024 
00025 SubscribeQos::SubscribeQos(Global& global) : GetQos(global)
00026 {
00027    ME = "SubscribeQos";
00028 }
00029 
00030 SubscribeQos::SubscribeQos(Global& global, const QueryQosData& data)
00031    : GetQos(global, data)
00032 {
00033    ME = "SubscribeQos";
00034 }
00035 
00036 SubscribeQos::SubscribeQos(const SubscribeQos& qos) : GetQos(qos)
00037 {
00038 }
00039 
00040 SubscribeQos& SubscribeQos::operator =(const SubscribeQos& qos)
00041 {
00042    data_ = qos.data_;
00043    return *this;
00044 }
00045 
00046 
00055 void SubscribeQos::setWantInitialUpdate(bool initialUpdate)
00056 {
00057    data_.setWantInitialUpdate(initialUpdate);
00058 }
00059 
00067 void SubscribeQos::setWantUpdateOneway(bool updateOneway)
00068 {
00069    data_.setWantUpdateOneway(updateOneway);
00070 }
00071 
00078 void SubscribeQos::setMultiSubscribe(bool multiSubscribe)
00079 {
00080    data_.setMultiSubscribe(multiSubscribe);
00081 }
00082 
00086 void SubscribeQos::setWantLocal(bool local)
00087 {
00088    data_.setWantLocal(local);
00089 }
00090 
00091 void SubscribeQos::setWantNotify(bool notifyOnErase)
00092 {
00093    data_.setWantNotify(notifyOnErase);
00094 }
00095 
00101 void SubscribeQos::setSubscriptionId(const string& subscriptionId) const
00102 {
00103    data_.setSubscriptionId(subscriptionId);
00104 }
00105 
00106 bool SubscribeQos::hasSubscriptionId() const {
00107   return data_.getSubscriptionId().size() > 0;
00108 }
00109 
00110 bool SubscribeQos::getMultiSubscribe() const {
00111   return data_.getMultiSubscribe();
00112 }
00113 
00114 std::string SubscribeQos::generateSubscriptionId(org::xmlBlaster::util::SessionNameRef sessionName, const org::xmlBlaster::client::key::SubscribeKey& subscribeKey)
00115 {
00116       if (sessionName->getPubSessionId() > 0 || !getMultiSubscribe()) {
00117          // This key is assured to be the same on client restart
00118          // a previous subscription in the server will have the same subscriptionId
00119          // Benefit: If on client restart we are queueing the returned faked subscriptionId will
00120          // match the later used one of the xmlBlaster server. We can easily use the subscriptionId
00121          // as a key in client code hashtable to dispatch update() messages
00122          // Note: multiSubscribe==false allows max one subscription on a topic, even it has
00123          // different mime query plugins (the latest wins)
00124          std::string url = subscribeKey.getUrl();
00125          url = StringTrim::replaceAll(url, "'", "&apos;"); // to have valid xml (<subscribe id='bla'/>
00126          setSubscriptionId(Constants::SUBSCRIPTIONID_PREFIX +
00127                                sessionName->getRelativeName(true) + "-" +
00128                                url);
00129       }
00130       else {
00131          TimestampFactory& factory = TimestampFactory::getInstance();
00132          Timestamp timestamp = factory.getTimestamp();
00133          setSubscriptionId(Constants::SUBSCRIPTIONID_PREFIX +
00134                                /* immutableId is also relativeName */
00135                                /*is global_.getImmutableId() better than sessionName?? */
00136                                sessionName->getRelativeName(true) + "-" +
00137                                lexical_cast<string>(timestamp));
00138       }
00139       return data_.getSubscriptionId();
00140    }
00141 
00142 void SubscribeQos::setPersistent(bool persistent) {
00143    data_.setPersistent(persistent);
00144 }
00145 
00146 }}}} // namespace
00147