util/qos/QosData.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      QosData.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00031 #include <util/qos/QosData.h>
00032 #include <util/Constants.h>
00033 #include <util/lexical_cast.h>
00034 #include <util/Global.h>
00035 #include <util/PriorityEnum.h>
00036 
00037 using namespace org::xmlBlaster::util;
00038 using namespace org::xmlBlaster::util::cluster;
00039 
00040 using namespace std;
00041 
00042 namespace org { namespace xmlBlaster { namespace util { namespace qos {
00043                                           
00044 const bool DEFAULT_isSubscribable = true;
00045 const bool DEFAULT_isVolatile   = false;
00046 const bool DEFAULT_persistent   = false;
00047 const bool DEFAULT_forceUpdate  = true;
00048 const bool DEFAULT_forceDestroy = false;
00049 
00050 void QosData::init()
00051 {
00052    state_ = Constants::STATE_OK;
00053    stateInfo_ = "";
00054    rcvTimestamp_ = 0;
00055    rcvTimestampFound_ = false;
00056    serialData_ = "";
00057    priority_ = NORM_PRIORITY;
00058    fromPersistenceStore_ = false;
00059    persistent_ = DEFAULT_persistent;
00060 }
00061 
00062 void QosData::copy(const QosData& data)
00063 {
00064    SessionName *p = new SessionName(global_, data.getSender()->getAbsoluteName());
00065    SessionNameRef r(p);
00066    sender_ = r;
00067 
00068    clientProperties_ = data.clientProperties_;
00069    state_ = data.state_;
00070    stateInfo_ = data.stateInfo_;
00071    rcvTimestamp_ = data.rcvTimestamp_;
00072    rcvTimestampFound_ = data.rcvTimestampFound_;
00073    serialData_ = data.serialData_;
00074    priority_ = data.priority_;
00075    fromPersistenceStore_ = data.fromPersistenceStore_;
00076    persistent_ = data.persistent_;
00077 }
00078 
00079 
00080 QosData::QosData(Global& global, const string& serialData)
00081    : ME("QosData"),
00082      global_(global),
00083      log_(global.getLog("org.xmlBlaster.util.qos")),
00084      routeNodeList_(),
00085      clientProperties_(),
00086      sender_(new SessionName(global))
00087 {
00088    init();
00089    serialData_ = serialData;
00090 }
00091 
00092 
00093 QosData::QosData(const QosData& data)
00094    : ME(data.ME),
00095      global_(data.global_),
00096      log_(data.log_),
00097      routeNodeList_(data.routeNodeList_),
00098      clientProperties_(),
00099      sender_(0)
00100 {
00101    copy(data);
00102 }
00103 
00104 QosData& QosData::operator=(const QosData& data)
00105 {
00106    copy(data);
00107    return *this;
00108 }
00109 
00110 
00111 QosData::~QosData()
00112 {
00113 }
00114 
00115 void QosData::setState(const string& state)
00116 {
00117    state_ = state;
00118 }
00119 
00120 string QosData::getState() const
00121 {
00122    return state_;
00123 }
00124 
00125 void QosData::setStateInfo(const string& stateInfo)
00126 {
00127    stateInfo_ = stateInfo;
00128 }
00129 
00130 string QosData::getStateInfo() const
00131 {
00132    return stateInfo_;
00133 }
00134 
00135 bool QosData::isOk() const
00136 {
00137    return Constants::STATE_OK == state_;
00138 }
00139 
00140 bool QosData::isErased() const
00141 {
00142    return Constants::STATE_ERASED == state_;
00143 }
00144 
00145 bool QosData::isTimeout() const
00146 {
00147    return Constants::STATE_TIMEOUT == state_;
00148 }
00149 
00150 bool QosData::isForwardError() const
00151 {
00152    return Constants::STATE_FORWARD_ERROR == state_;
00153 }
00154 
00155 void QosData::addRouteInfo(const RouteInfo& routeInfo)
00156 {
00157    routeNodeList_.insert(routeNodeList_.end(), routeInfo);
00158 
00159    // Set stratum to new values
00160    int offset = routeInfo.getStratum();
00161    if (offset < 0) offset = 0;
00162 
00163    vector<RouteInfo>::reverse_iterator iter = routeNodeList_.rbegin();
00164    while (iter != routeNodeList_.rend()) {
00165       (*iter).setStratum(offset++);
00166       iter++;
00167    }
00168 }
00169 
00170 int QosData::count(const NodeId& nodeId) const
00171 {
00172    int cnt = 0;
00173    if (routeNodeList_.empty()) return cnt;
00174    vector<RouteInfo>::const_iterator iter = routeNodeList_.begin();
00175    while (iter != routeNodeList_.end()) {
00176       if ((*iter).getNodeId() == nodeId) cnt++;
00177       iter++;
00178    }
00179    return cnt;
00180 }
00181 
00182 bool QosData::dirtyRead(NodeId nodeId) const
00183 {
00184    if (routeNodeList_.empty()) return false;
00185    vector<RouteInfo>::const_iterator iter = routeNodeList_.begin();
00186    while (iter != routeNodeList_.end()) {
00187       if ((*iter).getNodeId() == nodeId) return (*iter).getDirtyRead();
00188    }
00189    return false;
00190 }
00191 
00192 void QosData::setRcvTimestamp(Timestamp rcvTimestamp)
00193 {
00194    rcvTimestamp_ = rcvTimestamp;
00195 }
00196 
00197 Timestamp QosData::getRcvTimestamp() const
00198 {
00199    return rcvTimestamp_;
00200 }
00201 
00202 void QosData::touchRcvTimestamp()
00203 {
00204    rcvTimestamp_ = TimestampFactory::getInstance().getTimestamp();
00205 }
00206 
00207 void QosData::addClientProperty(const ClientProperty& clientProperty)
00208 {
00209    clientProperties_.insert(ClientPropertyMap::value_type(clientProperty.getName(), clientProperty));   
00210 }
00211 
00212 bool QosData::hasClientProperty(const string& name) const
00213 {
00214    return clientProperties_.count(name) > 0;
00215 }
00216 
00217 const QosData::ClientPropertyMap& QosData::getClientProperties() const
00218 {
00219    return clientProperties_;
00220 }
00221 
00222 void QosData::setClientProperties(const QosData::ClientPropertyMap& cm)
00223 {
00224    clientProperties_ = cm;
00225 }
00226 
00227 RouteVector QosData::getRouteNodes() const
00228 {
00229    return routeNodeList_;
00230 }
00231 
00232 void QosData::clearRoutes()
00233 {
00234    routeNodeList_.erase(routeNodeList_.begin(), routeNodeList_.end());
00235 }
00236 
00237 int QosData::size() const
00238 {
00239    return (int)toXml().size();
00240 }
00241 
00247 PriorityEnum QosData::getPriority() const
00248 {
00249    return priority_;
00250 }
00251 
00258 void QosData::setPriority(PriorityEnum priority)
00259 {
00260    priority_ = priority;
00261 }
00262 
00267 bool QosData::isFromPersistenceStore() const
00268 {
00269    return fromPersistenceStore_;
00270 }
00271 
00276 void QosData::setFromPersistenceStore(bool fromPersistenceStore)
00277 {
00278    fromPersistenceStore_ = fromPersistenceStore;
00279 }
00280 
00284 void QosData::setPersistent(bool persistent)
00285 {
00286    persistent_ = persistent;
00287 }
00288 
00292 bool QosData::isPersistent() const
00293 {
00294    return persistent_;
00295 }
00296 
00297 SessionNameRef QosData::getSender() const
00298 {
00299    return sender_;
00300 }
00301 
00302 void QosData::setSender(org::xmlBlaster::util::SessionNameRef sender) const
00303 {
00304    sender_ = sender;
00305 }
00306 
00307 string QosData::dumpClientProperties(const string& extraOffset, bool clearText) const
00308 {
00309    string ret = "";
00310    QosData::ClientPropertyMap::const_iterator iter = clientProperties_.begin();
00311    while (iter != clientProperties_.end()) {
00312       const ClientProperty& cp = (*iter).second;
00313       ret += cp.toXml(extraOffset, clearText);
00314       iter++;
00315    }
00316    return ret;
00317 }
00318 
00319 QosData* QosData::getClone() const
00320 {
00321    return new QosData(*this);
00322 }
00323 
00324 std::string QosData::toXml(const std::string& /*extraOffset*/) const
00325 {
00326    return "<error>QosData::toXml: PLEASE IMPLEMENT IN_BASE CLASS</error>";
00327 }
00328 
00329 }}}}
00330