util/queue/MsgQueueEntry.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      MsgQueueEntry.h
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00007 #ifndef _UTIL_QUEUE_MSGQUEUEENRY_H
00008 #define _UTIL_QUEUE_MSGQUEUEENRY_H
00009 
00010 #include <util/xmlBlasterDef.h>
00011 #include <util/Timestamp.h>
00012 #include <util/MessageUnit.h>
00013 #include <util/qos/ConnectQos.h>
00014 #include <client/qos/PublishQos.h>
00015 #include <client/qos/PublishReturnQos.h>
00016 #include <util/ReferenceCounterBase.h>
00017 #include <util/qos/StatusQosData.h>
00018 #include <util/qos/QueryQosData.h>
00019 #include <util/key/QueryKeyData.h>
00020 //#include <util/msgUtil.h> // from xmlBlaster C library
00021 //#include <socket/xmlBlasterSocket.h> // from xmlBlaster C library ::encodeMsgUnit(&msgUnit, debug);
00022 
00023 // circular dependency I_ConnectionsHandler -> Queue -> MsgQueueEntry
00024 #ifndef _UTIL_DISPATCH_ICONNECTIONSHANDLER_H
00025 namespace org { namespace xmlBlaster { namespace util { namespace dispatch {
00026 class I_ConnectionsHandler;
00027 }}}}
00028 #endif
00029 
00030 
00031 
00040 namespace org { namespace xmlBlaster { namespace util { namespace queue {
00041 
00045 typedef struct {
00046    size_t dataLen; // size_t is the unsigned integer size result of a sizeof operator. Change to uint32_t ?
00047    char *data;
00048 } BlobHolder;
00049 
00050 class Dll_Export MsgQueueEntry : public ReferenceCounterBase
00051 {
00052 protected:
00053    std::string ME;
00054    mutable org::xmlBlaster::util::Global& global_;
00055    org::xmlBlaster::util::I_Log& log_;
00056    int priority_;
00057    bool persistent_;
00058    org::xmlBlaster::util::Timestamp uniqueId_;
00059    std::string embeddedType_;
00060    std::string logId_;
00061    org::xmlBlaster::util::MessageUnit* msgUnit_;
00062    /* TODO: Change that connectQos, queryQos all derive from QosData and are transported inside msgUnit */
00063    org::xmlBlaster::util::qos::ConnectQosRef connectQos_;
00064 
00068    mutable org::xmlBlaster::util::qos::ConnectReturnQosRef connectReturnQos_;
00072    mutable const org::xmlBlaster::client::qos::PublishReturnQos* publishReturnQos_;
00076    mutable org::xmlBlaster::util::qos::StatusQosData* statusQosData_;
00077 
00082    mutable BlobHolder blobHolder_;
00083    
00084 public:
00085 
00092     MsgQueueEntry(org::xmlBlaster::util::Global& global,
00093                   const org::xmlBlaster::util::MessageUnit& msgUnit,
00094                   const std::string& embeddedType,
00095                   int priority,
00096                   bool persistent,
00097                   org::xmlBlaster::util::Timestamp uniqueId = TimestampFactory::getInstance().getTimestamp());
00098 
00103     MsgQueueEntry(org::xmlBlaster::util::Global& global,
00104                   const org::xmlBlaster::util::qos::ConnectQosRef& connectQos,
00105                   const std::string& embeddedType,
00106                   int priority,
00107                   bool persistent,
00108                   org::xmlBlaster::util::Timestamp uniqueId = TimestampFactory::getInstance().getTimestamp());
00109 
00110 
00116     MsgQueueEntry(org::xmlBlaster::util::Global& global,
00117                   const org::xmlBlaster::util::key::QueryKeyData& queryKeyData,
00118                   const org::xmlBlaster::util::qos::QueryQosData& queryQosData,
00119                   const std::string& embeddedType,
00120                   int priority,
00121                   bool persistent,
00122                   org::xmlBlaster::util::Timestamp uniqueId = TimestampFactory::getInstance().getTimestamp());
00123 
00124 
00125     virtual ~MsgQueueEntry();
00126 
00127     org::xmlBlaster::util::Global& getGlobal() const { return global_; }
00128 
00129     void copy(const MsgQueueEntry& entry);
00130 
00134     MsgQueueEntry(const MsgQueueEntry& entry);
00135 
00136     MsgQueueEntry& operator =(const MsgQueueEntry& entry);
00137 
00138     inline bool operator == (const MsgQueueEntry& entry)
00139     {
00140        if (priority_ != entry.priority_) return false;
00141        return (uniqueId_ == entry.uniqueId_);
00142     }
00143 
00148     inline bool operator < (const MsgQueueEntry& entry)
00149     {
00150        if (priority_ < entry.priority_) return true;
00151        if (priority_ > entry.priority_) return false;
00152        return (uniqueId_ > entry.uniqueId_);
00153     }
00154 
00159     virtual MsgQueueEntry *getClone() const = 0;
00160 
00166    int getPriority() const;
00167 
00171    bool isPersistent() const;
00172 
00176    void setSender(org::xmlBlaster::util::SessionNameRef sender);
00177 
00182    org::xmlBlaster::util::Timestamp getUniqueId() const;
00183 
00191    virtual const void* getEmbeddedObject() const;
00192 
00198    virtual std::string getEmbeddedType() const;
00199    
00200    virtual bool isConnect() const;
00201 
00202    virtual bool isPublish() const;
00203 
00204    virtual bool isSubscribe() const;
00205 
00206    virtual bool isUnSubscribe() const;
00207 
00208    virtual bool isErase() const;
00209 
00210 
00217    std::string getLogId() const;
00218 
00222    virtual size_t getSizeInBytes() const;
00223 
00228    org::xmlBlaster::util::MessageUnit& getMsgUnit() const;
00229 
00230    //org::xmlBlaster::util::qos::QueryQosData& getQueryQosData() const;
00231    //org::xmlBlaster::util::key::QueryKeyData& getQueryKeyData() const;
00232 
00233 
00234 
00235    // this should actually be in another interface but since it is an only method we put it here.
00236    virtual const MsgQueueEntry& send(org::xmlBlaster::util::dispatch::I_ConnectionsHandler&) const; // = 0;
00237    
00238    virtual std::string toXml(const std::string& indent="") const; // = 0;
00239 
00240 };
00241 
00242 }}}} // namespace
00243 
00244 #endif
00245