25 #ifndef __AMPS_MESSAGE_HPP__ 26 #define __AMPS_MESSAGE_HPP__ 27 #include "amps/util.hpp" 28 #include "amps/constants.hpp" 29 #include "amps/amps_generated.h" 35 #define AMPS_UNSET_SEQUENCE (amps_uint64_t)-1 44 #define AMPS_OPTIONS_NONE "" 45 #define AMPS_OPTIONS_LIVE "live," 46 #define AMPS_OPTIONS_OOF "oof," 47 #define AMPS_OPTIONS_REPLACE "replace," 48 #define AMPS_OPTIONS_NOEMPTIES "no_empties," 49 #define AMPS_OPTIONS_SENDKEYS "send_keys," 50 #define AMPS_OPTIONS_TIMESTAMP "timestamp," 51 #define AMPS_OPTIONS_NOSOWKEY "no_sowkey," 52 #define AMPS_OPTIONS_CANCEL "cancel," 53 #define AMPS_OPTIONS_RESUME "resume," 54 #define AMPS_OPTIONS_PAUSE "pause," 55 #define AMPS_OPTIONS_FULLY_DURABLE "fully_durable," 56 #define AMPS_OPTIONS_EXPIRE "expire," 57 #define AMPS_OPTIONS_TOPN(x) "top_n=##x," 58 #define AMPS_OPTIONS_MAXBACKLOG(x) "max_backlog=##x," 59 #define AMPS_OPTIONS_RATE(x) "rate=##x," 63 typedef void* amps_subscription_handle;
77 mutable bool _isIgnoreAutoAck;
78 size_t _bookmarkSeqNo;
79 amps_subscription_handle _subscription;
80 ClientImpl* _clientImpl;
94 bool ignoreAutoAck_ =
false,
size_t bookmarkSeqNo_ = 0,
95 amps_subscription_handle subscription_ = NULL,
96 ClientImpl* clientImpl_ = NULL)
97 : _message(message_), _owner(owner_), _isIgnoreAutoAck(ignoreAutoAck_)
98 , _bookmarkSeqNo(bookmarkSeqNo_)
99 , _subscription(subscription_), _clientImpl(clientImpl_)
107 : _message(NULL), _owner(true), _isIgnoreAutoAck(false), _bookmarkSeqNo(0), _subscription(NULL), _clientImpl(NULL)
115 if (_owner && _message)
124 return new MessageImpl(copy,
true, _isIgnoreAutoAck, _bookmarkSeqNo,
125 _subscription, _clientImpl);
130 if (_owner && _message)
136 _bookmarkSeqNo = rhs_._bookmarkSeqNo;
137 _subscription = rhs_._subscription;
138 _isIgnoreAutoAck = rhs_._isIgnoreAutoAck;
139 _clientImpl = rhs_._clientImpl;
142 void setClientImpl(ClientImpl* clientImpl_)
144 _clientImpl = clientImpl_;
147 ClientImpl* clientImpl(
void)
const 164 _subscription = NULL;
165 _isIgnoreAutoAck =
false;
177 if (_message == message_)
181 if (_owner && _message)
188 _subscription = NULL;
189 _isIgnoreAutoAck =
false;
198 static unsigned long newId()
200 return (
unsigned long)(AMPS_FETCH_ADD_VOLATILE(&_AMPS_NEXT_ID, 1));
203 void setBookmarkSeqNo(
size_t val_)
205 _bookmarkSeqNo = val_;
208 size_t getBookmarkSeqNo(
void)
const 210 return _bookmarkSeqNo;
213 void setSubscriptionHandle(amps_subscription_handle subscription_)
215 _subscription = subscription_;
218 amps_subscription_handle getSubscriptionHandle(
void)
const 220 return _subscription;
223 void setIgnoreAutoAck()
const 225 _isIgnoreAutoAck =
true;
228 bool getIgnoreAutoAck()
const 230 return _isIgnoreAutoAck;
240 #ifdef DOXYGEN_PREPROCESSOR 242 #define DOX_COMMENTHEAD(s) / ## ** ## s ## * ## / 243 #define DOX_GROUPNAME(s) DOX_COMMENTHEAD(@name s Functions) 244 #define DOX_OPENGROUP(s) DOX_COMMENTHEAD(@{) \ 246 #define DOX_CLOSEGROUP() DOX_COMMENTHEAD(@}) 247 #define DOX_MAKEGETCOMMENT(x) DOX_COMMENTHEAD( Retrieves the value of the x header of the Message as a Field which references the underlying buffer managed by this Message. Notice that not all headers are present on all messages returned by AMPS. See the AMPS %Command Reference for details on which fields will be present in response to a specific command. ) 248 #define DOX_MAKEGETRAWCOMMENT(x) DOX_COMMENTHEAD( Modifies the passed in arguments to reference the value of the x header of self in the underlying buffer managed by this Message. Notice that not all headers are present on all messages returned by AMPS. See the AMPS %Command Reference for details on which fields will be present in response to a specific command. ) 249 #define DOX_MAKESETCOMMENT(x) DOX_COMMENTHEAD( Sets the value of the x header for this Message. Not all headers are processed by AMPS for all commands. See the AMPS %Command Reference for which headers are used by AMPS for a specific command. ) 250 #define DOX_MAKEASSIGNCOMMENT(x) DOX_COMMENTHEAD( Assigns the value of the x header for this Message without copying. Not all headers are processed by AMPS for all commands. See the AMPS %Command Reference for which headers are used by AMPS for a specific command. ) 251 #define DOX_MAKEASSIGNOWNCOMMENT(x) DOX_COMMENTHEAD( Assigns the value of the x header for this Message without copying and makes this Message responsible for deleting the value. Not all headers are processed by AMPS for all commands. See the AMPS %Command Reference for which headers are used by AMPS for a specific command. ) 252 #define DOX_MAKENEWCOMMENT(x) DOX_COMMENTHEAD(Creates and sets a new sequential value for the x header for this Message. This function is most useful for headers such as %CommandId and %SubId.) 256 #define DOX_COMMENTHEAD(s) 257 #define DOX_GROUPNAME(s) 258 #define DOX_OPENGROUP(x) 259 #define DOX_CLOSEGROUP() 260 #define DOX_MAKEGETCOMMENT(x) 261 #define DOX_MAKEGETRAWCOMMENT(x) 262 #define DOX_MAKESETCOMMENT(x) 263 #define DOX_MAKEASSIGNCOMMENT(x) 264 #define DOX_MAKEASSIGNOWNCOMMENT(x) 265 #define DOX_MAKENEWCOMMENT(x) 273 #define AMPS_FIELD(x) \ 275 DOX_MAKEGETCOMMENT(x) \ 276 Field get##x() const {\ 280 amps_message_get_field_value(_body.get().getMessage(),\ 281 AMPS_##x, &ptr, &sz);\ 282 returnValue.assign(ptr, sz);\ 285 DOX_MAKEGETRAWCOMMENT(x) \ 286 void getRaw##x(const char** dataptr, size_t* sizeptr) const {\ 287 amps_message_get_field_value(_body.get().getMessage(),\ 288 AMPS_##x, dataptr, sizeptr);\ 291 DOX_MAKESETCOMMENT(x) \ 292 Message& set##x(const std::string& v) {\ 293 amps_message_set_field_value(_body.get().getMessage(),\ 294 AMPS_##x, v.c_str(), v.length());\ 297 DOX_MAKESETCOMMENT(x) \ 298 Message& set##x(amps_uint64_t v) {\ 300 AMPS_snprintf_amps_uint64_t(buf,22,v);\ 301 amps_message_set_field_value_nts(_body.get().getMessage(),\ 305 DOX_MAKEASSIGNCOMMENT(x) \ 306 Message& assign##x(const std::string& v) {\ 307 amps_message_assign_field_value(_body.get().getMessage(),\ 308 AMPS_##x, v.c_str(), v.length());\ 311 DOX_MAKEASSIGNCOMMENT(x) \ 312 Message& assign##x(const char* data, size_t len) {\ 313 amps_message_assign_field_value(_body.get().getMessage(),\ 314 AMPS_##x, data, len);\ 317 DOX_MAKEASSIGNOWNCOMMENT(x) \ 318 Message& assignOwnership##x(const Field& f) {\ 319 amps_message_assign_field_value_ownership(_body.get().getMessage(),\ 320 AMPS_##x, f.data(), f.len());\ 323 DOX_MAKESETCOMMENT(x) \ 324 Message& set##x(const char* str) {\ 325 amps_message_set_field_value_nts(_body.get().getMessage(),\ 329 DOX_MAKESETCOMMENT(x) \ 330 Message& set##x(const char* str,size_t len) {\ 331 amps_message_set_field_value(_body.get().getMessage(),\ 335 DOX_MAKENEWCOMMENT(x) \ 337 char buf[Message::IdentifierLength+1];\ 338 buf[Message::IdentifierLength] = 0;\ 339 AMPS_snprintf(buf, Message::IdentifierLength+1, "auto%lu" , (unsigned long)(_body.get().newId()));\ 340 amps_message_set_field_value_nts(_body.get().getMessage(),\ 346 #define AMPS_FIELD_ALIAS(x,y) \ 348 DOX_MAKEGETCOMMENT(y) \ 349 Field get##y() const {\ 353 amps_message_get_field_value(_body.get().getMessage(),\ 354 AMPS_##y, &ptr, &sz);\ 355 returnValue.assign(ptr, sz);\ 358 DOX_MAKEGETRAWCOMMENT(y) \ 359 void getRaw##y(const char** dataptr, size_t* sizeptr) const {\ 360 amps_message_get_field_value(_body.get().getMessage(),\ 361 AMPS_##y, dataptr, sizeptr);\ 364 DOX_MAKESETCOMMENT(y) \ 365 Message& set##y(const std::string& v) {\ 366 amps_message_set_field_value(_body.get().getMessage(),\ 367 AMPS_##y, v.c_str(), v.length());\ 370 DOX_MAKESETCOMMENT(y) \ 371 Message& set##y(amps_uint64_t v) {\ 373 AMPS_snprintf_amps_uint64_t(buf,22,v);\ 374 amps_message_set_field_value_nts(_body.get().getMessage(),\ 378 DOX_MAKEASSIGNCOMMENT(y) \ 379 Message& assign##y(const std::string& v) {\ 380 amps_message_assign_field_value(_body.get().getMessage(),\ 381 AMPS_##y, v.c_str(), v.length());\ 384 DOX_MAKEASSIGNCOMMENT(y) \ 385 Message& assign##y(const char* data, size_t len) {\ 386 amps_message_assign_field_value(_body.get().getMessage(),\ 387 AMPS_##y, data, len);\ 390 DOX_MAKESETCOMMENT(y) \ 391 Message& set##y(const char* str) {\ 392 amps_message_set_field_value_nts(_body.get().getMessage(),\ 396 DOX_MAKESETCOMMENT(y) \ 397 Message& set##y(const char* str,size_t len) {\ 398 amps_message_set_field_value(_body.get().getMessage(),\ 402 DOX_MAKENEWCOMMENT(y) \ 404 char buf[Message::IdentifierLength+1];\ 405 buf[Message::IdentifierLength] = 0;\ 406 AMPS_snprintf(buf, Message::IdentifierLength+1, "auto%lux" , (unsigned long)(_body.get().newId()));\ 407 amps_message_set_field_value_nts(_body.get().getMessage(),\ 411 DOX_MAKEGETCOMMENT(y) \ 412 Field get##x() const {\ 416 amps_message_get_field_value(_body.get().getMessage(),\ 417 AMPS_##y, &ptr, &sz);\ 418 returnValue.assign(ptr, sz);\ 421 DOX_MAKEGETRAWCOMMENT(y) \ 422 void getRaw##x(const char** dataptr, size_t* sizeptr) const {\ 423 amps_message_get_field_value(_body.get().getMessage(),\ 424 AMPS_##y, dataptr, sizeptr);\ 427 DOX_MAKESETCOMMENT(y) \ 428 Message& set##x(const std::string& v) {\ 429 amps_message_set_field_value(_body.get().getMessage(),\ 430 AMPS_##y, v.c_str(), v.length());\ 433 DOX_MAKESETCOMMENT(y) \ 434 Message& set##x(amps_uint64_t v) {\ 436 AMPS_snprintf_amps_uint64_t(buf,22,v);\ 437 amps_message_set_field_value_nts(_body.get().getMessage(),\ 441 DOX_MAKEASSIGNCOMMENT(y) \ 442 Message& assign##x(const std::string& v) {\ 443 amps_message_assign_field_value(_body.get().getMessage(),\ 444 AMPS_##y, v.c_str(), v.length());\ 447 DOX_MAKEASSIGNCOMMENT(y) \ 448 Message& assign##x(const char* data, size_t len) {\ 449 amps_message_assign_field_value(_body.get().getMessage(),\ 450 AMPS_##y, data, len);\ 453 DOX_MAKESETCOMMENT(y) \ 454 Message& set##x(const char* str) {\ 455 amps_message_set_field_value_nts(_body.get().getMessage(),\ 459 DOX_MAKESETCOMMENT(y) \ 460 Message& set##x(const char* str,size_t len) {\ 461 amps_message_set_field_value(_body.get().getMessage(),\ 465 DOX_MAKENEWCOMMENT(y) \ 467 char buf[Message::IdentifierLength+1];\ 468 buf[Message::IdentifierLength] = 0;\ 469 AMPS_snprintf(buf, Message::IdentifierLength+1, "auto%lux" , (unsigned long)(_body.get().newId()));\ 470 amps_message_set_field_value_nts(_body.get().getMessage(),\ 519 RefHandle<MessageImpl> _body;
528 static const unsigned int IdentifierLength = 32;
532 static const size_t BOOKMARK_NONE = AMPS_UNSET_INDEX;
567 return Message(_body.get().copy());
574 _body.get().copy(rhs_._body.get());
590 static const char* None(
void)
592 return AMPS_OPTIONS_NONE;
594 static const char* Live(
void)
596 return AMPS_OPTIONS_LIVE;
598 static const char* OOF(
void)
600 return AMPS_OPTIONS_OOF;
602 static const char* Replace(
void)
604 return AMPS_OPTIONS_REPLACE;
606 static const char* NoEmpties(
void)
608 return AMPS_OPTIONS_NOEMPTIES;
610 static const char* SendKeys(
void)
612 return AMPS_OPTIONS_SENDKEYS;
614 static const char* Timestamp(
void)
616 return AMPS_OPTIONS_TIMESTAMP;
618 static const char* NoSowKey(
void)
620 return AMPS_OPTIONS_NOSOWKEY;
622 static const char* Cancel(
void)
624 return AMPS_OPTIONS_CANCEL;
626 static const char* Resume(
void)
628 return AMPS_OPTIONS_RESUME;
630 static const char* Pause(
void)
632 return AMPS_OPTIONS_PAUSE;
634 static const char* FullyDurable(
void)
636 return AMPS_OPTIONS_FULLY_DURABLE;
638 static const char* Expire(
void)
640 return AMPS_OPTIONS_EXPIRE;
642 static std::string Conflation(
const char* conflation_)
645 AMPS_snprintf(buf,
sizeof(buf),
"conflation=%s,", conflation_);
648 static std::string ConflationKey(
const char* conflationKey_)
650 std::string option(
"conflation_key=");
651 option.append(conflationKey_).append(
",");
654 static std::string TopN(
int topN_)
657 AMPS_snprintf(buf,
sizeof(buf),
"top_n=%d,", topN_);
660 static std::string MaxBacklog(
int maxBacklog_)
663 AMPS_snprintf(buf,
sizeof(buf),
"max_backlog=%d,", maxBacklog_);
666 static std::string Rate(
const char* rate_)
669 AMPS_snprintf(buf,
sizeof(buf),
"rate=%s,", rate_);
672 static std::string RateMaxGap(
const char* rateMaxGap_)
675 AMPS_snprintf(buf,
sizeof(buf),
"rate_max_gap=%s,", rateMaxGap_);
678 static std::string SkipN(
int skipN_)
681 AMPS_snprintf(buf,
sizeof(buf),
"skip_n=%d,", skipN_);
685 static std::string Projection(
const std::string& projection_)
687 return "projection=[" + projection_ +
"],";
690 template<
class Iterator>
691 static std::string Projection(Iterator begin_, Iterator end_)
693 std::string projection =
"projection=[";
694 for (Iterator i = begin_; i != end_; ++i)
699 projection.insert(projection.length() - 1,
"]");
703 static std::string Grouping(
const std::string& grouping_)
705 return "grouping=[" + grouping_ +
"],";
708 template<
class Iterator>
709 static std::string Grouping(Iterator begin_, Iterator end_)
711 std::string grouping =
"grouping=[";
712 for (Iterator i = begin_; i != end_; ++i)
717 grouping.insert(grouping.length() - 1,
"]");
721 static std::string Select(
const std::string& select_)
723 return "select=[" + select_ +
"],";
726 template<
class Iterator>
727 static std::string Select(Iterator begin_, Iterator end_)
729 std::string select =
"select=[";
730 for (Iterator i = begin_; i != end_; ++i)
735 select.insert(select.length() - 1,
"]");
739 static std::string AckConflationInterval(
const std::string& interval_)
741 return "ack_conflation=" + interval_ +
",";
744 static std::string AckConflationInterval(
const char* interval_)
746 static const std::string start(
"ack_conflation=");
747 return start + interval_ +
",";
750 static std::string BookmarkNotFound(
const char* action_)
752 static const std::string start(
"bookmark_not_found=");
753 return start + action_ +
",";
756 static std::string BookmarkNotFoundNow()
758 return BookmarkNotFound(
"now");
761 static std::string BookmarkNotFoundEpoch()
763 return BookmarkNotFound(
"epoch");
766 static std::string BookmarkNotFoundFail()
768 return BookmarkNotFound(
"fail");
774 : _optionStr(options_)
780 int getMaxBacklog(
void)
const 784 std::string getConflation(
void)
const 788 std::string getConflationKey(
void)
const 790 return _conflationKey;
792 int getTopN(
void)
const 796 std::string getRate(
void)
const 800 std::string getRateMaxGap(
void)
const 824 _optionStr += AMPS_OPTIONS_LIVE;
833 _optionStr += AMPS_OPTIONS_OOF;
842 _optionStr += AMPS_OPTIONS_REPLACE;
850 _optionStr += AMPS_OPTIONS_NOEMPTIES;
858 _optionStr += AMPS_OPTIONS_SENDKEYS;
867 _optionStr += AMPS_OPTIONS_TIMESTAMP;
875 _optionStr += AMPS_OPTIONS_NOSOWKEY;
883 _optionStr += AMPS_OPTIONS_CANCEL;
894 _optionStr += AMPS_OPTIONS_RESUME;
909 _optionStr += AMPS_OPTIONS_PAUSE;
920 _optionStr += AMPS_OPTIONS_FULLY_DURABLE;
936 AMPS_snprintf(buf,
sizeof(buf),
"max_backlog=%d,", maxBacklog_);
938 _maxBacklog = maxBacklog_;
949 AMPS_snprintf(buf,
sizeof(buf),
"conflation=%s,", conflation_);
951 _conflation = conflation_;
966 AMPS_snprintf(buf,
sizeof(buf),
"conflation_key=%s,", conflationKey_);
968 _conflationKey = conflationKey_;
979 AMPS_snprintf(buf,
sizeof(buf),
"top_n=%d,", topN_);
993 AMPS_snprintf(buf,
sizeof(buf),
"rate=%s,", rate_);
1015 AMPS_snprintf(buf,
sizeof(buf),
"rate_max_gap=%s,", rateMaxGap_);
1017 _rateMaxGap = rateMaxGap_;
1028 AMPS_snprintf(buf,
sizeof(buf),
"skip_n=%d,", skipN_);
1039 _projection =
"projection=[" + projection_ +
"],";
1040 _optionStr += _projection;
1049 template<
class Iterator>
1052 _projection =
"projection=[";
1053 for (Iterator i = begin_; i != end_; ++i)
1058 _projection.insert(_projection.length() - 1,
"]");
1059 _optionStr += _projection;
1068 _grouping =
"grouping=[" + grouping_ +
"],";
1069 _optionStr += _grouping;
1078 template<
class Iterator>
1081 _grouping =
"grouping=[";
1082 for (Iterator i = begin_; i != end_; ++i)
1087 _grouping.insert(_grouping.length() - 1,
"]");
1088 _optionStr += _grouping;
1097 _optionStr += BookmarkNotFound(action_);
1105 _optionStr += BookmarkNotFoundNow();
1113 _optionStr += BookmarkNotFoundEpoch();
1121 _optionStr += BookmarkNotFoundFail();
1127 operator std::string()
1129 return _optionStr.substr(0, _optionStr.length() - 1);
1136 return (_optionStr.empty() ? 0 : _optionStr.length() - 1);
1145 return (_optionStr.empty() ? 0 : _optionStr.data());
1149 std::string _optionStr;
1151 std::string _conflation;
1152 std::string _conflationKey;
1155 std::string _rateMaxGap;
1157 std::string _projection;
1158 std::string _grouping;
1165 typedef enum :
unsigned 1167 None = 0, Received = 1, Parsed = 2, Processed = 4, Persisted = 8, Completed = 16, Stats = 32
1173 static inline
AckType::Type decodeSingleAckType(const
char* begin, const
char* end)
1175 switch (end - begin)
1178 return AckType::Stats;
1180 return AckType::Parsed;
1182 return AckType::Received;
1186 case 'e':
return AckType::Persisted;
1187 case 'r':
return AckType::Processed;
1188 case 'o':
return AckType::Completed;
1195 return AckType::None;
1202 unsigned result = AckType::None;
1203 const char* data = NULL;
size_t len = 0;
1205 const char* mark = data;
1206 for (
const char* end = data + len; data != end; ++data)
1210 result |= decodeSingleAckType(mark, data);
1216 result |= decodeSingleAckType(mark, data);
1225 if (ackType_ < AckTypeConstants<0>::Entries)
1228 AckTypeConstants<0>::Values[ackType_], AckTypeConstants<0>::Lengths[ackType_]);
1233 AMPS_FIELD(BatchSize)
1234 AMPS_FIELD(Bookmark)
1253 SOWAndSubscribe = 256,
1254 DeltaSubscribe = 512,
1255 SOWAndDeltaSubscribe = 1024,
1263 NoDataCommands = Publish | Unsubscribe | Heartbeat | SOWDelete | DeltaPublish
1264 | Logon | StartTimer | StopTimer | Flush
1270 const char* data = NULL;
size_t len = 0;
1274 case 1:
return Command::Publish;
1278 case 's':
return Command::SOW;
1279 case 'o':
return Command::OOF;
1280 case 'a':
return Command::Ack;
1286 case 'l':
return Command::Logon;
1287 case 'f':
return Command::Flush;
1291 return Command::Publish;
1296 case 's':
return Command::Subscribe;
1297 case 'h':
return Command::Heartbeat;
1298 case 'g':
return Command::GroupEnd;
1304 case 'o':
return Command::SOWDelete;
1305 case 't':
return Command::StopTimer;
1311 case 'g':
return Command::GroupBegin;
1312 case 'u':
return Command::Unsubscribe;
1316 return Command::DeltaPublish;
1318 return Command::DeltaSubscribe;
1320 return Command::SOWAndSubscribe;
1322 return Command::SOWAndDeltaSubscribe;
1324 return Command::Unknown;
1331 unsigned command = command_;
1338 CommandConstants<0>::Values[bits], CommandConstants<0>::Lengths[bits]);
1342 AMPS_FIELD(CommandId)
1343 AMPS_FIELD(ClientName)
1344 AMPS_FIELD(CorrelationId)
1345 AMPS_FIELD(Expiration)
1347 AMPS_FIELD(GroupSequenceNumber)
1348 AMPS_FIELD(Heartbeat)
1349 AMPS_FIELD(LeasePeriod)
1351 AMPS_FIELD(MessageLength)
1352 AMPS_FIELD(MessageType)
1356 Field getOptions()
const 1362 AMPS_Options, &ptr, &sz);
1363 if (sz && ptr[sz - 1] ==
',')
1367 returnValue.assign(ptr, sz);
1371 DOX_MAKEGETRAWCOMMENT(
Options)
1372 void getRawOptions(const
char** dataptr,
size_t* sizeptr)
const 1375 AMPS_Options, dataptr, sizeptr);
1376 if (*sizeptr && *dataptr && (*dataptr)[*sizeptr - 1] ==
',')
1386 size_t sz = v.length();
1387 if (sz && v[sz - 1] ==
',')
1392 AMPS_Options, v.c_str(), sz);
1396 DOX_MAKEASSIGNCOMMENT(
Options)
1399 size_t sz = v.length();
1400 if (sz && v[sz - 1] ==
',')
1405 AMPS_Options, v.c_str(), sz);
1409 DOX_MAKEASSIGNCOMMENT(
Options)
1410 Message& assignOptions(const
char* data,
size_t len)
1412 if (len && data[len - 1] ==
',')
1417 AMPS_Options, data, len);
1426 size_t sz = strlen(str);
1427 if (sz && str[sz - 1] ==
',')
1432 AMPS_Options, str, sz);
1437 AMPS_Options, str, 0);
1445 if (len && str[len - 1] ==
',')
1450 AMPS_Options, str, len);
1456 AMPS_FIELD(Password)
1457 AMPS_FIELD_ALIAS(QueryId, QueryID)
1459 AMPS_FIELD(RecordsInserted)
1460 AMPS_FIELD(RecordsReturned)
1461 AMPS_FIELD(RecordsUpdated)
1462 AMPS_FIELD(Sequence)
1463 AMPS_FIELD(SowDelete)
1467 AMPS_FIELD_ALIAS(SubId, SubscriptionId)
1468 AMPS_FIELD(SubscriptionIds)
1469 AMPS_FIELD(TimeoutInterval)
1470 AMPS_FIELD(Timestamp)
1477 return getTimestamp();
1486 getRawTimestamp(dataptr, sizeptr);
1490 AMPS_FIELD(TopicMatches)
1491 AMPS_FIELD(TopNRecordsReturned)
1506 returnValue.assign(ptr, sz);
1510 void getRawData(
const char** data,
size_t* sz)
const 1521 Message& assignData(
const std::string& v_)
1535 Message& assignData(
const char* data_,
size_t length_)
1548 Message& assignData(
const char* data_)
1555 return _body.get().getMessage();
1559 _body.get().replace(message, owner);
1563 _body.get().disown();
1569 bool isValid(
void)
const 1571 return _body.isValid();
1575 _body.get().reset();
1579 void setBookmarkSeqNo(
size_t val)
1581 _body.get().setBookmarkSeqNo(val);
1584 size_t getBookmarkSeqNo()
const 1586 return _body.get().getBookmarkSeqNo();
1591 _body.get().setSubscriptionHandle(val);
1596 return _body.get().getSubscriptionHandle();
1599 void ack(
const char* options_ = NULL)
const;
1601 void setClientImpl(ClientImpl* pClientImpl)
1603 _body.get().setClientImpl(pClientImpl);
1606 void setIgnoreAutoAck()
const 1608 _body.get().setIgnoreAutoAck();
1611 bool getIgnoreAutoAck()
const 1613 return _body.get().getIgnoreAutoAck();
1618 void throwFor(
const T& ,
const std::string& ackReason_)
const 1620 switch (ackReason_[0])
1623 throw AuthenticationException(
"Logon failed for user \"" +
1624 (std::string)getUserId() +
"\"");
1627 switch (ackReason_.length())
1630 throw BadFilterException(
"bad filter '" +
1631 (std::string)getFilter() +
1635 if (getSowKeys().len())
1637 throw BadSowKeyException(
"bad sow key '" +
1638 (std::string)getSowKeys() +
1643 throw BadSowKeyException(
"bad sow key '" +
1644 (std::string)getSowKey() +
1649 throw BadRegexTopicException(
"bad regex topic '" +
1650 (std::string)getTopic() +
1658 if (ackReason_.length() == 23)
1660 throw DuplicateLogonException(
"Client '" +
1661 (std::string)getClientName() +
1663 (std::string)getUserId() +
1664 "' duplicate logon attempt");
1668 if (ackReason_.length() >= 9)
1670 switch (ackReason_[8])
1673 throw InvalidBookmarkException(
"invalid bookmark '" +
1674 (std::string)getBookmark() +
1678 throw CommandException(std::string(
"invalid message type '") +
1679 (std::string)getMessageType() +
1683 if (ackReason_[9] ==
'p')
1685 throw InvalidOptionsException(
"invalid options '" +
1686 (std::string)getOptions() +
1689 else if (ackReason_[9] ==
'r')
1691 throw InvalidOrderByException(
"invalid order by '" +
1692 (std::string)getOrderBy() +
1697 throw InvalidSubIdException(
"invalid subid '" +
1698 (std::string)getSubscriptionId() +
1702 if (ackReason_.length() == 13)
1704 throw InvalidTopicException(
"invalid topic '" +
1705 (std::string)getTopic() +
1708 else if (ackReason_.length() == 23)
1710 throw InvalidTopicException(
"invalid topic or filter. Topic '" +
1711 (std::string)getTopic() +
1713 (std::string)getFilter() +
1723 if (ackReason_.length() == 14)
1725 throw LogonRequiredException(
"logon required before command");
1729 switch (ackReason_[4])
1732 throw NameInUseException(
"name in use '" +
1733 (std::string)getClientName() +
1737 throw NotEntitledException(
"User \"" +
1738 (std::string)getUserId() +
1739 "\" not entitled to topic \"" +
1740 (std::string)getTopic() +
1744 throw MissingFieldsException(
"command sent with no filter or bookmark.");
1747 throw MissingFieldsException(
"command sent with no client name.");
1750 throw MissingFieldsException(
"command sent with no topic or filter.");
1753 throw CommandException(
"operation on topic '" +
1754 (std::string)getTopic() +
1755 "' with options '" +
1756 (std::string)getOptions() +
1757 "' not supported.");
1764 switch (ackReason_.length())
1767 throw MissingFieldsException(
"orderby required");
1770 throw CommandException(
"orderby too large '" +
1771 (std::string)getOrderBy() +
1777 throw CommandException(
"projection clause too large in options '" +
1778 (std::string)getOptions() +
1782 switch (ackReason_[2])
1785 throw BadRegexTopicException(
"'regex topic not supported '" +
1786 (std::string)getTopic() +
1794 switch (ackReason_[5])
1797 throw SubidInUseException(
"subid in use '" +
1798 (std::string)getSubscriptionId() +
1802 throw CommandException(
"sow_delete command only supports one of: filter '" +
1803 (std::string)getFilter() +
1805 (std::string)getSowKeys() +
1807 (std::string)getBookmark() +
1809 (std::string)getData() +
1813 throw PublishException(
"sow store failed.");
1820 switch (ackReason_[2])
1823 throw PublishException(
"tx store failure.");
1826 throw ReplayFailedException(
"txn replay failed for '" 1827 + (std::string)getSubId()
1835 throw CommandException(
"Error from server while processing this command: '" +
1843 return lhs + std::string(rhs);
1846 inline std::basic_ostream<char>&
1847 operator<<(std::basic_ostream<char>& os,
const Message::Field& rhs)
1849 os.write(rhs.
data(), (std::streamsize)rhs.
len());
1853 AMPS::Field::operator<(
const AMPS::Field& rhs)
const 1857 return rhs.
data() != NULL;
1863 return std::lexicographical_compare(data(), data() + len(), rhs.
data(), rhs.
data() + rhs.
len());
void setFullyDurable(void)
Set the option to only provide messages that have been persisted to all replication destinations that...
Definition: Message.hpp:918
Class to hold string versions of failure reasons.
Definition: ampsplusplus.hpp:151
Message & setData(const std::string &v_)
Sets the data portion of self.
Definition: Message.hpp:1516
AMPSDLL amps_handle amps_message_create(amps_handle client)
Functions for creation and manipulation of AMPS messages.
void setRateMaxGap(const char *rateMaxGap_)
Set the option for the maximum amount of time that a bookmark replay with a specified rate will allow...
Definition: Message.hpp:1012
Command::Type getCommandEnum() const
Decode self's "command" field and return one of the values from Command.
Definition: Message.hpp:1268
AMPSDLL amps_handle amps_message_copy(amps_handle message)
Creates and returns a handle to a new AMPS message object that is a deep copy of the message passed i...
void setBookmarkNotFoundNow()
Set the option for the action to take if the requested bookmark to start the subscription is not foun...
Definition: Message.hpp:1103
void setNoEmpties(void)
Set the option to not send empty messages on a delta subscription.
Definition: Message.hpp:848
Message deepCopy(void) const
Returns a deep copy of self.
Definition: Message.hpp:565
void setOOF(void)
Set the option to receive out of focus (OOF) messages on a subscription, where applicable.
Definition: Message.hpp:831
Message encapsulates a single message sent to or received from an AMPS server, and provides methods f...
Definition: Message.hpp:517
Message & setAckTypeEnum(unsigned ackType_)
Encode self's "ack type" field from a bitmask of values from AckType.
Definition: Message.hpp:1223
void setNoSowKey(void)
Set the option to not set the SowKey header on messages.
Definition: Message.hpp:873
MessageImpl(amps_handle message_, bool owner_=false, bool ignoreAutoAck_=false, size_t bookmarkSeqNo_=0, amps_subscription_handle subscription_=NULL, ClientImpl *clientImpl_=NULL)
Constructs a messageImpl from an existing AMPS message.
Definition: Message.hpp:93
AMPSDLL void amps_message_set_field_value(amps_handle message, FieldId field, const amps_char *value, size_t length)
Sets the value of a header field in an AMPS message.
Message & setCommandEnum(Command::Type command_)
Set self's "command" field from one of the values in Command.
Definition: Message.hpp:1328
void setSendKeys(void)
Set the option to send key fields with a delta subscription.
Definition: Message.hpp:856
void * amps_handle
Opaque handle type used to refer to objects in the AMPS api.
Definition: amps.h:211
Class for constructing the options string to pass to AMPS in a Message.
Definition: Message.hpp:587
AMPSDLL void amps_message_assign_data(amps_handle message, const amps_char *value, size_t length)
Assigns the data component of an AMPS message, without copying the value.
const char * data() const
Returns the (non-null-terminated) data underlying this field.
Definition: Field.hpp:279
void setPause(void)
Set the option to pause a bookmark subscription.
Definition: Message.hpp:907
void setReplace(void)
Set the option to replace a current subscription with this one.
Definition: Message.hpp:840
Valid values for setCommandEnum() and getCommandEnum().
Definition: Message.hpp:1240
Message & setData(const char *data_)
Sets the data portion of self from a null-terminated string.
Definition: Message.hpp:1543
void setGrouping(Iterator begin_, Iterator end_)
Set the option for grouping the results of an aggregated query or subscription.
Definition: Message.hpp:1079
Message(CtorFlag)
Constructs a new empty, invalid Message.
Definition: Message.hpp:541
AMPSDLL void amps_message_set_data_nts(amps_handle message, const amps_char *value)
Sets the data component of an AMPS message.
AMPSDLL void amps_message_reset(amps_handle message)
Clears all fields and data in a message.
void setTimestamp(void)
Set the option to send a timestamp that the message was processed on a subscription or query...
Definition: Message.hpp:865
amps_handle getMessage() const
Returns the underling AMPS message object from the C layer.
Definition: Message.hpp:154
Defines the AMPS::Field class, which represents the value of a field in a message.
size_t len() const
Returns the length of the data underlying this field.
Definition: Field.hpp:286
void setResume(void)
Set the option to resume a subscription.
Definition: Message.hpp:892
AMPSDLL void amps_message_get_field_value(amps_handle message, FieldId field, const amps_char **value_ptr, size_t *length_ptr)
Retrieves the value of a header field in an AMPS message.
void setConflation(const char *conflation_)
Set the options for conflation on a subscription.
Definition: Message.hpp:946
void replace(amps_handle message_, bool owner_=false)
Causes self to refer to a new AMPS message, freeing any current message owned by self along the way...
Definition: Message.hpp:174
AMPSDLL void amps_message_get_data(amps_handle message, amps_char **value_ptr, size_t *length_ptr)
Gets the data component of an AMPS message.
AMPSDLL void amps_message_destroy(amps_handle message)
Destroys and frees the memory associated with an AMPS message object.
Options(std::string options_="")
ctor - default to None
Definition: Message.hpp:773
size_t getLength() const
Return the length of this Options object as a string.
Definition: Message.hpp:1134
AMPSDLL void amps_message_assign_field_value(amps_handle message, FieldId field, const amps_char *value, size_t length)
Assigns the value of a header field in an AMPS message, without copying the value.
void setRate(const char *rate_)
Set the option for the maximum rate at which messages are provided to the subscription.
Definition: Message.hpp:990
Valid values for the setAckTypeEnum() and getAckTypeEnum() methods.
Definition: Message.hpp:1163
void setGrouping(const std::string &grouping_)
Set the option for grouping the results of an aggregated query or subscription.
Definition: Message.hpp:1066
void setBookmarkNotFoundEpoch()
Set the option for the action to take if the requested bookmark to start the subscription is not foun...
Definition: Message.hpp:1111
void setTopN(int topN_)
Set the top N option, which specifies the maximum number of messages to return for this command...
Definition: Message.hpp:976
AMPSDLL void amps_message_set_data(amps_handle message, const amps_char *value, size_t length)
Sets the data component of an AMPS message.
void setMaxBacklog(int maxBacklog_)
Set the option for maximum backlog this subscription is willing to accept.
Definition: Message.hpp:933
void setBookmarkNotFoundFail()
Set the option for the action to take if the requested bookmark to start the subscription is not foun...
Definition: Message.hpp:1119
void getRawTransmissionTime(const char **dataptr, size_t *sizeptr) const
Definition: Message.hpp:1484
void deepCopy(const Message &rhs_)
Makes self a deep copy of rhs_.
Definition: Message.hpp:572
MessageImpl()
Constructs a MessageImpl with a new, empty AMPS message.
Definition: Message.hpp:106
Field represents the value of a single field in a Message.
Definition: Field.hpp:87
void setBookmarkNotFound(const char *action_)
Set the option for the action to take if the requested bookmark to start the subscription is ot found...
Definition: Message.hpp:1095
void setConflationKey(const char *conflationKey_)
Set the options for the conflation key, the identifiers for the field or fields used by AMPS to deter...
Definition: Message.hpp:963
void setProjection(const std::string &projection_)
Set the option for projecting the results of an aggregated query or subscription. ...
Definition: Message.hpp:1037
void setSkipN(int skipN_)
Set the option for skip N, the number of messages in the result set to skip before returning messages...
Definition: Message.hpp:1025
Message(amps_handle message_, bool owner_=false)
Constructs a new Message to wrap message.
Definition: Message.hpp:551
CtorFlag
A flag to indicate not to create a body.
Definition: Message.hpp:537
void setNone(void)
Clear any previously set options and set the options to an empty string (AMPS_OPTIONS_NONE).
Definition: Message.hpp:808
Implementation class for a Message.
Definition: Message.hpp:71
void setProjection(Iterator begin_, Iterator end_)
Set the option for projecting the results of an aggregated query or subscription. ...
Definition: Message.hpp:1050
unsigned getAckTypeEnum() const
Decode self's "ack type" field and return the corresponding bitmask of values from AckType...
Definition: Message.hpp:1200
Message & setData(const char *data_, size_t length_)
Sets the data portion of self from a char array.
Definition: Message.hpp:1530
Definition: AMPSException.hpp:32
void setCancel(void)
Set the cancel option, used on a sow_delete command to return a message to the queue.
Definition: Message.hpp:881
const char * getStr() const
Return this Options object as a non-NULL-terminated string.
Definition: Message.hpp:1143
Message()
Construct a new, empty Message.
Definition: Message.hpp:559
void setLive(void)
Set the live option for a bookmark subscription, which requests that the subscription receives messag...
Definition: Message.hpp:822