00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef SEMAINE_CMS_SENDER_SENDER_H
00011 #define SEMAINE_CMS_SENDER_SENDER_H
00012
00013 #include <semaine/config.h>
00014
00015 #include <cms/MessageProducer.h>
00016 #include <cms/Message.h>
00017
00018 #include <semaine/cms/IOBase.h>
00019 #include <semaine/cms/message/SEMAINEMessage.h>
00020 #include <semaine/cms/exceptions/SEMAINEException.h>
00021 #include <semaine/cms/exceptions/SystemConfigurationException.h>
00022
00023 using namespace cms;
00024 using namespace semaine::cms;
00025 using namespace semaine::cms::message;
00026 using namespace semaine::cms::exceptions;
00027
00028 namespace semaine {
00029 namespace cms {
00030 namespace sender {
00037 class Sender : public IOBase
00038 {
00039 public:
00040
00055 Sender(const std::string & topicName, const std::string & datatype, const std::string & source)
00056 throw (CMSException);
00057
00068 Sender(const std::string & cmsUrl, const std::string & cmsUser, const std::string & cmsPassword,
00069 const std::string & topicName, const std::string & datatype, const std::string & source)
00070 throw (CMSException);
00071
00072
00077 const std::string getDatatype()
00078 {
00079 return datatype;
00080 }
00081
00086 const std::string getSource()
00087 {
00088 return source;
00089 }
00090
00096 void setPeriodic(int aPeriod) throw(SEMAINEException)
00097 {
00098 if (aPeriod <= 0)
00099 throw SEMAINEException("Period must be positive");
00100 this->period = aPeriod;
00101 }
00102
00108 void setEventBased()
00109 {
00110 this->period = 0;
00111 }
00112
00117 bool isPeriodic()
00118 {
00119 return period != 0;
00120 }
00121
00126 bool isEventBased()
00127 {
00128 return period == 0;
00129 }
00130
00135 int getPeriod()
00136 {
00137 if (isEventBased())
00138 throw SEMAINEException("Cannot report period for event-based Sender!");
00139 return period;
00140 }
00141
00150 void setTimeToLive(long long aTimeToLive) throw(CMSException)
00151 {
00152 CMSLogger::getLog(getTopicName()+" Sender")->warn("Ignoring deprecated call to setTimeToLive");
00153
00154 }
00155
00164 long long getTimeToLive() throw(CMSException)
00165 {
00166 return producer->getTimeToLive();
00167 }
00168
00190 void sendTextMessage(const std::string & text, long long usertime)
00191 throw(CMSException, SystemConfigurationException);
00192
00222 void sendTextMessage(const std::string & text, long long usertime, const std::string & contentID,
00223 long long contentCreationTime, const std::string & contentType = "")
00224 throw(CMSException, SystemConfigurationException);
00225
00246 void sendTextMessage(const std::string & text, long long usertime, const std::string & eventType)
00247 throw(CMSException, SystemConfigurationException);
00248
00276 void sendTextMessage(const std::string & text, long long usertime, const std::string & eventType, const std::string & contentID,
00277 long long contentCreationTime, const std::string & contentType = "")
00278 throw(CMSException, SystemConfigurationException);
00279
00280
00281
00282 protected:
00283 MessageProducer * producer;
00287 const std::string datatype;
00291 const std::string source;
00297 int period;
00298
00299 void initialise() throw (CMSException);
00300
00309 virtual void fillMessageProperties(Message * message, long long usertime)
00310 throw(CMSException)
00311 {
00312 message->setStringProperty(SEMAINEMessage::DATATYPE, getDatatype());
00313 message->setStringProperty(SEMAINEMessage::SOURCE, getSource());
00314 message->setLongProperty(SEMAINEMessage::USERTIME, usertime);
00315 }
00316
00317 void fillMessageProperties(Message * message, long long usertime, const std::string & contentID,
00318 long long contentCreationTime, const std::string & contentType = "")
00319 throw(CMSException)
00320 {
00321 fillMessageProperties(message, usertime);
00322
00323 if (contentID != "") {
00324 message->setStringProperty(SEMAINEMessage::CONTENT_ID, contentID);
00325 }
00326 if (contentCreationTime >= 0) {
00327 message->setLongProperty(SEMAINEMessage::CONTENT_CREATION_TIME, contentCreationTime);
00328 }
00329 if (contentType != "") {
00330 message->setStringProperty(SEMAINEMessage::CONTENT_TYPE, contentType);
00331 }
00332
00333 }
00334
00335
00336 };
00337
00338 }
00339 }
00340 }
00341
00342 #endif
00343