util/qos/QueryQosData.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      QueryQosData.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00027 #include <util/qos/QueryQosData.h>
00028 # include <util/Constants.h>
00029 # include <util/Global.h>
00030 
00031 using namespace org::xmlBlaster::util;
00032 using namespace org::xmlBlaster::util::cluster;
00033 
00034 using namespace std;
00035 
00036 namespace org { namespace xmlBlaster { namespace util { namespace qos {
00037 
00038 void QueryQosData::init() 
00039 {
00040 //   QosData::init();
00041    subscriptionId_ = "";
00042    forceDestroy_   = false;
00043    meta_           = true;
00044    content_        = true;
00045    multiSubscribe_ = true;
00046    local_          = true;
00047    initialUpdate_  = true;
00048    updateOneway_   = false;
00049    notify_         = true;
00050    maxEntries_     = -10;
00051    consumable_     = false;
00052    timeout_        = 0;
00053 }
00054 
00055 void QueryQosData::copy(const QueryQosData& data) 
00056 {
00057    QosData::copy(data);
00058    subscriptionId_ = data.subscriptionId_;
00059    forceDestroy_   = data.forceDestroy_;
00060    meta_           = data.meta_;
00061    content_        = data.content_;
00062    multiSubscribe_ = data.multiSubscribe_;
00063    local_          = data.local_;
00064    initialUpdate_  = data.initialUpdate_;
00065    updateOneway_   = data.updateOneway_;
00066    notify_         = data.notify_;
00067    maxEntries_     = data.maxEntries_;
00068    consumable_     = data.consumable_;
00069    timeout_        = data.timeout_;
00070 }
00071 
00072 
00078 QueryQosData::QueryQosData(Global& global)
00079    : QosData(global),
00080       forceDestroy_(false),
00081       meta_(true), 
00082       content_(true),
00083       multiSubscribe_(true),
00084       local_(true),
00085       initialUpdate_(true),
00086       updateOneway_(false),
00087       notify_(true),
00088       filters_(),
00089       historyQos_(global), 
00090       maxEntries_(-10),
00091       consumable_(false),
00092       timeout_(0L)
00093 {
00094    ME = "QueryQosData";
00095 }
00096 
00097 
00106 void QueryQosData::setWantInitialUpdate(bool initialUpdate)
00107 {
00108    initialUpdate_ = initialUpdate;
00109 }
00110 
00111 bool QueryQosData::getWantInitialUpdate() const
00112 {
00113    return initialUpdate_;
00114 }
00115 
00123 void QueryQosData::setWantUpdateOneway(bool updateOneway)
00124 {
00125    updateOneway_ = updateOneway;
00126 }
00127 
00128 bool QueryQosData::getWantUpdateOneway() const
00129 {
00130    return updateOneway_;
00131 }
00132 
00133 void QueryQosData::setWantNotify(bool notify)
00134 {
00135    notify_ = notify;
00136 }
00137 
00138 bool QueryQosData::getWantNotify() const
00139 {
00140    return notify_;
00141 }
00142 
00143 void QueryQosData::setMultiSubscribe(bool multiSubscribe)
00144 {
00145    multiSubscribe_ = multiSubscribe;
00146 }
00147 
00148 bool QueryQosData::getMultiSubscribe() const
00149 {
00150    return multiSubscribe_;
00151 }
00152 
00156 void QueryQosData::setWantLocal(bool local)
00157 {
00158    local_ = local;
00159 }
00160 
00164 bool QueryQosData::getWantLocal() const
00165 {
00166    return local_;
00167 }
00168 
00172 void QueryQosData::setWantMeta(bool meta)
00173 {
00174    meta_ = meta;
00175 }
00176 
00180 bool QueryQosData::getWantMeta() const
00181 {
00182    return meta_;
00183 }
00184 
00189 void QueryQosData::setWantContent(bool content)
00190 {
00191    content_ = content;
00192 }
00193 
00194 bool QueryQosData::getWantContent() const
00195 {
00196    return content_;
00197 }
00198 
00202 void QueryQosData::setForceDestroy(bool forceDestroy)
00203 {
00204    forceDestroy_ = forceDestroy;
00205 }
00206 
00210 bool QueryQosData::getForceDestroy() const
00211 {
00212    return forceDestroy_;
00213 }
00214 
00218 void QueryQosData::addAccessFilter(const AccessFilterQos& filter)
00219 {
00220    filters_.insert(filters_.begin(), filter);
00221 }
00222 
00223 AccessFilterVector QueryQosData::getAccessFilters() const
00224 {
00225    return filters_;
00226 }
00227 
00228 
00232 void QueryQosData::setHistoryQos(const HistoryQos& historyQos)
00233 {
00234    historyQos_ = historyQos;
00235 }
00236 
00241 HistoryQos QueryQosData::getHistoryQos() const
00242 {
00243    return historyQos_;
00244 }
00245 
00246 void QueryQosData::setQueryQos(int maxEntries, long timeout, bool consumable) {
00247     maxEntries_ = maxEntries;
00248     timeout_ = timeout;
00249     consumable_ = consumable;
00250 }
00251 
00257 string QueryQosData::getSubscriptionId() const
00258 {
00259    return subscriptionId_;
00260 }
00261 
00267 void QueryQosData::setSubscriptionId(const string& subscriptionId)
00268 {
00269    subscriptionId_ = subscriptionId;
00270 }
00271 
00272 
00279 string QueryQosData::toXml(const string& extraOffset) const
00280 {
00281    string ret;
00282    string offset = Constants::OFFSET + extraOffset;
00283 
00284    ret += offset + "<qos>"; // <!-- SubscribeRetQos -->");
00285    if (!subscriptionId_.empty())
00286       ret += offset + " <subscribe id='" + subscriptionId_ + "'/>";
00287    ret += offset + " <erase forceDestroy='" + Global::getBoolAsString(forceDestroy_) + "'/>";
00288 
00289    if (!meta_) ret += offset + " <meta>false</meta>";
00290    if (!content_) ret += offset + " <content>false</content>";
00291    if (!multiSubscribe_) ret += offset + " <multiSubscribe>false</multiSubscribe>";
00292    if (!local_) ret += offset + " <local>false</local>";
00293    if (!initialUpdate_) ret += offset + " <initialUpdate>false</initialUpdate>";
00294    if (updateOneway_) ret += offset + " <updateOneway/>";
00295    if (!notify_) ret += offset + " <notify>false</notify>";
00296    if (isPersistent())
00297       ret += offset + " <persistent/>";
00298 
00299    AccessFilterVector::const_iterator iter = filters_.begin();
00300    while (iter != filters_.end()) {
00301       ret += (*iter).toXml(extraOffset + Constants::INDENT);
00302       iter++;
00303    }
00304    
00305    if (maxEntries_ != -10) {
00306       ret += offset + 
00307              "<querySpec type='QueueQuery'>" +
00308                    "maxEntries="+
00309                    lexical_cast<std::string>(maxEntries_)+
00310                    "&amp;maxSize=-1&amp;consumable="+
00311                    lexical_cast<std::string>(consumable_)+
00312                    "&amp;waitingDelay="+
00313                    lexical_cast<std::string>(timeout_)+
00314              "</querySpec>";
00315    }
00316    
00317    ret += historyQos_.toXml(extraOffset + Constants::INDENT);
00318         bool clearText = false;
00319    ret += dumpClientProperties(extraOffset + Constants::INDENT, clearText);
00320    ret += offset + "</qos>";
00321 
00322    if (ret.length() < 16)
00323       return "<qos/>";  // minimal footprint
00324 
00325    return ret;
00326 }
00327 
00328 QueryQosData* QueryQosData::getClone() const
00329 {
00330    return new QueryQosData(*this);
00331 }
00332 
00333 }}}} // namespace
00334 
00335