1 /*------------------------------------------------------------------------------
 2 Name:      PublishQueueEntry.cpp
 3 Project:   xmlBlaster.org
 4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
 5 ------------------------------------------------------------------------------*/
 6 
 7 #include <util/queue/PublishQueueEntry.h>
 8 #include <util/dispatch/I_ConnectionsHandler.h>
 9 #include <util/msgUtil.h> // from xmlBlaster C library
10 #include <socket/xmlBlasterSocket.h> // from xmlBlaster C library ::encodeMsgUnit(&msgUnit, debug);
11 
12 namespace org { namespace xmlBlaster { namespace util { namespace queue {
13 
14 using namespace std;
15 using namespace org::xmlBlaster::util::dispatch;
16 using namespace org::xmlBlaster::client::qos;
17 using namespace org::xmlBlaster::client::key;
18 
19 PublishQueueEntry::PublishQueueEntry(Global& global, const MessageUnit& msgUnit,
20                                      int priority, Timestamp uniqueId)
21    : MsgQueueEntry(global, msgUnit, 
22                    org::xmlBlaster::util::Constants::ENTRY_TYPE_MSG_RAW + "|" + org::xmlBlaster::util::MethodName::PUBLISH,
23                    priority, msgUnit.getQos().isPersistent(), uniqueId)
24 {
25    ME = "PublishQueueEntry";
26    if (log_.call()) log_.call(ME, "ctor ...");
27    if (priority < 0) priority_ = msgUnit.getQos().getPriority();
28 }
29 
30 PublishQueueEntry::~PublishQueueEntry() {
31 }
32 
33 /** copy constructor */
34 PublishQueueEntry::PublishQueueEntry(const PublishQueueEntry& rhs)
35     //: MsgQueueEntry((MsgQueueEntry)rhs)
36     : MsgQueueEntry(rhs.getGlobal(), rhs.getMsgUnit(), rhs.getEmbeddedType(), rhs.getPriority(), rhs.isPersistent(), rhs.getUniqueId())
37 {
38 }
39 
40 /** assignment constructor */
41 PublishQueueEntry& PublishQueueEntry::operator=(const PublishQueueEntry& rhs)
42 {
43    if (this == &rhs)
44       return *this;
45    return *this;
46 }
47 
48 MsgQueueEntry *PublishQueueEntry::getClone() const
49 {
50    return new PublishQueueEntry(*this);
51 }
52 
53 const MsgQueueEntry& PublishQueueEntry::send(I_ConnectionsHandler& connectionsHandler) const
54 {
55    if (log_.call()) log_.call(ME, "send");
56    if (publishReturnQos_) {
57       delete publishReturnQos_;
58       publishReturnQos_ = NULL;
59    }
60    if (log_.dump()) log_.dump(ME, string("send: ") + PublishQueueEntry::toXml());
61    publishReturnQos_ = new PublishReturnQos(connectionsHandler.getConnection().publish(*msgUnit_));
62    return *this;
63 }
64 
65 const PublishReturnQos* PublishQueueEntry::getPublishReturnQos() const
66 {
67    return publishReturnQos_;
68 }
69 
70 bool PublishQueueEntry::isPublish() const {
71    return true;
72 }
73 
74 size_t PublishQueueEntry::getSizeInBytes() const
75 {
76    if (msgUnit_) return msgUnit_->getSizeInBytes();
77    return 0;
78 }
79 
80 string PublishQueueEntry::toXml(const string& indent) const
81 {
82    string extraOffset = "   " + indent;
83    string ret = indent + "<publishQueueEntry>\n";
84    if (msgUnit_) {
85       ret += extraOffset + msgUnit_->toXml(indent);
86    }
87    ret += indent + "</publishQueueEntry>\n";
88    return ret;
89 }
90 
91 }}}} // namespace


syntax highlighted by Code2HTML, v. 0.9.1