util/qos/QosData.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      QosData.h
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00031 #ifndef _UTIL_QOS_QOSDATA_H
00032 #define _UTIL_QOS_QOSDATA_H
00033 
00034 #include <util/xmlBlasterDef.h>
00035 #include <util/cluster/RouteInfo.h>
00036 #include <util/SessionName.h>
00037 #include <util/qos/ClientProperty.h>
00038 #include <util/PriorityEnum.h>
00039 #include <util/ReferenceCounterBase.h>
00040 #include <util/ReferenceHolder.h>
00041 #include <vector>
00042 #include <map>
00043 #include <string>
00044 
00045 namespace org { namespace xmlBlaster { namespace util { namespace qos {
00046 
00047 extern Dll_Export const bool DEFAULT_isSubscribable;
00048 extern Dll_Export const bool DEFAULT_isVolatile;
00049 extern Dll_Export const bool DEFAULT_persistent;
00050 extern Dll_Export const bool DEFAULT_forceUpdate;
00051 extern Dll_Export const bool DEFAULT_forceDestroy;
00052 
00053 // extern Dll_Export const bool DEFAULT_readonly;
00054 
00055 typedef std::vector<org::xmlBlaster::util::cluster::RouteInfo> RouteVector;
00056 
00057 class Dll_Export QosData : public org::xmlBlaster::util::ReferenceCounterBase
00058 {
00059 
00060 private:
00061    void init();
00062 
00063 protected:
00064    std::string  ME;
00065    org::xmlBlaster::util::Global& global_;
00066    org::xmlBlaster::util::I_Log&    log_;
00067    std::string  serialData_;
00068 
00070    std::string state_; // = Constants::STATE_OK;
00072    std::string stateInfo_;
00073 
00079    Timestamp rcvTimestamp_;
00080    bool rcvTimestampFound_; // = false;
00081 
00083    org::xmlBlaster::util::PriorityEnum priority_; // = org::xmlBlaster::util::PriorityEnum.NORM_PRIORITY;
00084 
00086    bool fromPersistenceStore_; // = false;
00087 
00088    bool persistent_; // = DEFAULT_persistent;
00089 
00093    RouteVector routeNodeList_;
00094 
00095 public:   typedef std::map<std::string, org::xmlBlaster::util::qos::ClientProperty> ClientPropertyMap;
00096 protected:
00097 
00098    ClientPropertyMap clientProperties_; 
00099 
00101    mutable org::xmlBlaster::util::SessionNameRef sender_;
00102 
00103    void copy(const QosData& data);
00104 
00105    std::string dumpClientProperties(const std::string& extraOffset, bool clearText) const;
00106 
00107 public:
00112 //   long size_;
00113 
00114    QosData(org::xmlBlaster::util::Global& global, const std::string& serialData="");
00115 
00116    QosData(const QosData& data);
00117 
00118    QosData& operator=(const QosData& data);
00119 
00120    virtual ~QosData();
00121 
00125    void setState(const std::string& state);
00126 
00131    std::string getState() const;
00132 
00136    void setStateInfo(const std::string& stateInfo);
00137 
00142    std::string getStateInfo() const;
00143 
00147    bool isOk() const;
00148 
00153    bool isErased() const;
00154 
00162    bool isTimeout() const;
00163 
00167    bool isForwardError() const;
00168 
00175    void addRouteInfo(const org::xmlBlaster::util::cluster::RouteInfo& routeInfo);
00176 
00181    int count(const org::xmlBlaster::util::cluster::NodeId& nodeId) const;
00182 
00187    bool dirtyRead(org::xmlBlaster::util::cluster::NodeId nodeId) const;
00188 
00194    void setRcvTimestamp(Timestamp rcvTimestamp);
00195 
00201    Timestamp getRcvTimestamp() const;
00202 
00206    void touchRcvTimestamp();
00207 
00213    void addClientProperty(const ClientProperty& clientProperty);
00214 
00227    template <typename T_VALUE> void addClientProperty(
00228             const std::string& name,
00229             const T_VALUE& value,
00230             const std::string& type="",
00231             const std::string& encoding="",
00232             const std::string& charset="");
00233 
00238    template <typename T_VALUE> T_VALUE getClientProperty(
00239             const std::string& name,
00240             const T_VALUE& defaultValue);
00241         
00242    bool hasClientProperty(const std::string& name) const;
00243    const ClientPropertyMap& getClientProperties() const;
00244    void setClientProperties(const ClientPropertyMap& cm);
00245 
00250    org::xmlBlaster::util::SessionNameRef getSender() const;
00251 
00256    void setSender(org::xmlBlaster::util::SessionNameRef sender) const;
00257 
00265    virtual std::string toXml(const std::string& extraOffset="") const;
00266 
00271    virtual QosData* getClone() const;
00272 
00273     // the following where not present before ...
00274    RouteVector getRouteNodes() const;
00275 
00276    void clearRoutes();
00277 
00278    int size() const;
00279 
00285    org::xmlBlaster::util::PriorityEnum getPriority() const;
00286 
00293    void setPriority(org::xmlBlaster::util::PriorityEnum priority);
00294 
00299    bool isFromPersistenceStore() const;
00300 
00305    void setFromPersistenceStore(bool fromPersistenceStore);
00306 
00310    void setPersistent(bool persistent);
00311 
00315    bool isPersistent() const;
00316 };
00317 
00318 typedef org::xmlBlaster::util::ReferenceHolder<org::xmlBlaster::util::qos::QosData> QosDataRef;
00319 
00320 template <typename T_VALUE> void QosData::addClientProperty(
00321              const std::string& name, const T_VALUE& value,
00322              const std::string& type, const std::string& encoding,
00323              const std::string& charset)
00324 {
00325    org::xmlBlaster::util::qos::ClientProperty clientProperty(name, value, type, encoding, charset);
00326    clientProperties_.insert(ClientPropertyMap::value_type(name, clientProperty));   
00327 }
00328 
00329 template <typename T_VALUE> T_VALUE QosData::getClientProperty(
00330              const std::string& name, const T_VALUE& defaultValue)
00331 {
00332    ClientPropertyMap::const_iterator iter = clientProperties_.find(name);
00333    if (iter != clientProperties_.end()) {
00334       T_VALUE tmp;
00335       (*iter).second.getValue(tmp);
00336       return tmp;
00337    }
00338    return defaultValue;
00339 }
00340         
00341 }}}}
00342 
00343 #endif