util/queue/SubscribeQueueEntry.cpp

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 Name:      SubscribeQueueEntry.cpp
00003 Project:   xmlBlaster.org
00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
00005 ------------------------------------------------------------------------------*/
00006 
00007 #include <util/queue/SubscribeQueueEntry.h>
00008 #include <util/dispatch/I_ConnectionsHandler.h>
00009 
00010 namespace org { namespace xmlBlaster { namespace util { namespace queue {
00011 
00012 using namespace std;
00013 using namespace org::xmlBlaster::util::dispatch;
00014 using namespace org::xmlBlaster::util::qos;
00015 using namespace org::xmlBlaster::util::key;
00016 using namespace org::xmlBlaster::client::qos;
00017 using namespace org::xmlBlaster::client::key;
00018 
00019 SubscribeQueueEntry::SubscribeQueueEntry(Global& global, const SubscribeKey& subscribeKey,
00020      const SubscribeQos& subscribeQos, int priority, Timestamp uniqueId)
00021    : MsgQueueEntry(global, subscribeKey.getData(), subscribeQos.getData(), 
00022      org::xmlBlaster::util::Constants::ENTRY_TYPE_MSG_RAW + "|" + org::xmlBlaster::util::MethodName::SUBSCRIBE,
00023      priority,
00024      false, // subscribeQos.getData().isPersistent(), TODO: first implement retrieval before we can put it in !!!
00025      uniqueId)
00026 {
00027    ME = "SubscribeQueueEntry";
00028 }
00029 
00030 SubscribeQueueEntry::~SubscribeQueueEntry() {
00031 }
00032 
00034 SubscribeQueueEntry::SubscribeQueueEntry(const SubscribeQueueEntry& rhs)
00035     //: MsgQueueEntry((MsgQueueEntry)rhs)
00036     : MsgQueueEntry(rhs.getGlobal(), rhs.getMsgUnit(), rhs.getEmbeddedType(), rhs.getPriority(), rhs.isPersistent(), rhs.getUniqueId())
00037 {
00038    memset(&blobHolder_, 0, sizeof(BlobHolder)); // reset cache
00039 }
00040 
00042 SubscribeQueueEntry& SubscribeQueueEntry::operator=(const SubscribeQueueEntry& rhs)
00043 {
00044    if (this == &rhs)
00045       return *this;
00046    memset(&blobHolder_, 0, sizeof(BlobHolder)); // reset cache
00047    return *this;
00048 }
00049 
00050 MsgQueueEntry *SubscribeQueueEntry::getClone() const
00051 {
00052    return new SubscribeQueueEntry(*this);
00053 }
00054 
00055 bool SubscribeQueueEntry::isSubscribe() const {
00056    return true;
00057 }
00058 
00059 // this should actually be in another interface but since it is an only method we put it here.
00060 const MsgQueueEntry& SubscribeQueueEntry::send(I_ConnectionsHandler& connectionsHandler) const
00061 {
00062    if (log_.call()) log_.call(ME, "send");
00063    if (statusQosData_) {
00064       delete statusQosData_;
00065       statusQosData_ = NULL;
00066    }
00067    if (log_.dump()) log_.dump(ME, string("send: ") + SubscribeQueueEntry::toXml());
00068    statusQosData_ = new StatusQosData(
00069         connectionsHandler.getConnection().subscribe(
00070             getSubscribeKey(), getSubscribeQos()).getData());
00071    return *this;
00072 }
00073 
00074 SubscribeQos SubscribeQueueEntry::getSubscribeQos() const
00075 {
00076    const QueryQosData *qos = dynamic_cast<const QueryQosData *>(&msgUnit_->getQos());
00077    return SubscribeQos(global_, *qos);
00078 }
00079 
00080 SubscribeKey SubscribeQueueEntry::getSubscribeKey() const
00081 {
00082    const QueryKeyData *key = dynamic_cast<const QueryKeyData *>(&msgUnit_->getKey());
00083    return SubscribeKey(global_, *key);
00084 }
00085 
00086 SubscribeReturnQos SubscribeQueueEntry::getSubscribeReturnQos() const
00087 {
00088    return SubscribeReturnQos(global_, *statusQosData_);
00089 }
00090 
00091 string SubscribeQueueEntry::toXml(const string& indent) const
00092 {
00093    string extraOffset = "   " + indent;
00094    string ret = indent + "<subscribeQueueEntry>\n";
00095    if (msgUnit_) {
00096       ret += extraOffset + msgUnit_->toXml(indent);
00097    }
00098    ret += indent + "</subscribeQueueEntry>\n";
00099    return ret;
00100 }
00101 
00102 
00103 }}}} // namespace
00104 
00105