25 #ifndef _BOOKMARKSTORE_H_ 26 #define _BOOKMARKSTORE_H_ 29 #include "amps/util.hpp" 44 #define AMPS_BOOKMARK_RECENT "recent" 51 #define AMPS_BOOKMARK_EPOCH "0" 55 #define AMPS_BOOKMARK_NOW "0|1|" 70 typedef bool (*BookmarkStoreResizeHandler)(BookmarkStore store_,
71 const Message::Field& subId_,
81 : _resizeHandler(NULL)
82 , _resizeHandlerData(NULL)
83 , _maxSubIdLength(AMPS_MAX_SUBID_LEN)
103 size_t bookmarkSeqNo_) = 0;
135 virtual void purge() = 0;
158 _resizeHandler = handler_;
159 _resizeHandlerData = userData_;
190 bool callResizeHandler(
const Message::Field& subId_,
size_t newSize_);
192 inline void prune(
const std::string& tmpFileName_ = std::string())
194 _prune(tmpFileName_);
197 virtual void _prune(
const std::string&)
208 return _maxSubIdLength;
217 _maxSubIdLength = maxSubIdLength_;
221 BookmarkStoreResizeHandler _resizeHandler;
222 void* _resizeHandlerData;
223 size_t _maxSubIdLength;
230 RefHandle<BookmarkStoreImpl> _body;
259 return _body.isValid();
272 return _body.get().log(message_);
287 _body.get().discard(subId_, bookmarkSeqNo_);
300 _body.get().discard(message_);
314 return _body.get().getMostRecent(subId_);
331 return _body.get().isDiscarded(message_);
358 _body.get().purge(subId_);
372 _body.get().setResizeHandler(handler_, userData_);
383 return _body.get().getOldestBookmarkSeq(
Message::Field(subId_.c_str(),
385 return AMPS_UNSET_INDEX;
396 return _body.get().getOldestBookmarkSeq(subId_);
398 return AMPS_UNSET_INDEX;
409 _body.get().persisted(subId_, bookmark_);
421 _body.get().persisted(subId_, bookmark_);
433 _body.get().setServerVersion(version_);
445 _body.get().setServerVersion(version_);
454 void prune(
const std::string& tmpFileName_ =
"")
458 _body.get().prune(tmpFileName_);
485 return _body.get().getMaxSubIdLength();
501 _body.get().setMaxSubIdLength(maxSubIdLength_);
507 inline bool BookmarkStoreImpl::callResizeHandler(
const Message::Field& subId_,
512 return _resizeHandler(
BookmarkStore(
this), subId_, newSize_, _resizeHandlerData);
523 inline bool ThrowawayBookmarkResizeHandler(
BookmarkStore store_,
525 size_t newSize_,
void* data_)
527 size_t* maxSizep = (
size_t*)data_;
528 if (newSize_ > *maxSizep)
531 store_.
discard(subId_, discardSeq);
540 #endif //_BOOKMARKSTORE_H_ void purge(const Message::Field &subId_)
Called to purge the contents of this store for particular subId.
Definition: BookmarkStore.hpp:354
Defines the AMPS::Message class and related classes.
void setMaxSubIdLength(size_t maxSubIdLength_)
Sets the maximum allowed length for a sub id when recovering a bookmark store from persistent storage...
Definition: BookmarkStore.hpp:497
Abstract base class for storing received bookmarks for HA clients.
Definition: BookmarkStore.hpp:77
void setServerVersion(size_t version_)
Internally used to set the server version so the store knows how to deal with persisted acks and call...
Definition: BookmarkStore.hpp:429
void discard(const Message &message_)
Log a discard-bookmark entry to the persistent log based on a Message.
Definition: BookmarkStore.hpp:296
virtual void setResizeHandler(BookmarkStoreResizeHandler handler_, void *userData_)
Set a handler on the bookmark store that will get called whenever a resize of the store is required d...
Definition: BookmarkStore.hpp:156
void persisted(const Message::Field &subId_, const Message::Field &bookmark_)
Called internally to indicate messages up to and including bookmark are replicated to all replication...
Definition: BookmarkStore.hpp:405
void discard(const Message::Field &subId_, size_t bookmarkSeqNo_)
Log a discard-bookmark entry to the persistent log based on a bookmark sequence number.
Definition: BookmarkStore.hpp:283
bool isDiscarded(Message &message_)
Called for each arriving message to determine if the application has already seen this bookmark and s...
Definition: BookmarkStore.hpp:327
void purge()
Called to purge the contents of this store.
Definition: BookmarkStore.hpp:341
Message encapsulates a single message sent to or received from an AMPS server, and provides methods f...
Definition: Message.hpp:531
BookmarkStore(BookmarkStoreImpl *impl_)
Creates a BookmarkStore based on the given implementation.
Definition: BookmarkStore.hpp:238
virtual Message::Field getMostRecent(const Message::Field &subId_)=0
Returns the most recent bookmark from the log that ought to be used for (re-)subscriptions.
void setServerVersion(const VersionInfo &version_)
Internally used to set the server version so the store knows how to deal with persisted acks and call...
Definition: BookmarkStore.hpp:441
void setResizeHandler(BookmarkStoreResizeHandler handler_, void *userData_)
Set a handler on the bookmark store that will get called whenever a resize of the store is required d...
Definition: BookmarkStore.hpp:368
void setImplementation(BookmarkStoreImpl *impl_)
Sets the BookmarkStore to use the given implementation.
Definition: BookmarkStore.hpp:252
virtual size_t getOldestBookmarkSeq(const Message::Field &subId_)=0
Called to find the oldest bookmark sequence in the store.
Interface for BookmarkStoreImpl classes.
Definition: BookmarkStore.hpp:228
#define AMPS_BOOKMARK_EPOCH
Start the subscription at the beginning of the journal.
Definition: BookmarkStore.hpp:51
virtual void discard(const Message::Field &subId_, size_t bookmarkSeqNo_)=0
Log a discard-bookmark entry to the persistent log based on a bookmark sequence number.
void persisted(const Message::Field &subId_, size_t bookmark_)
Called internally to indicate messages up to and including bookmark are replicated to all replication...
Definition: BookmarkStore.hpp:417
virtual bool isDiscarded(Message &message_)=0
Called for each arriving message to determine if the application has already seen this bookmark and s...
size_t getOldestBookmarkSeq(const Message::Field &subId_)
Called to find the oldest bookmark sequence in the store.
Definition: BookmarkStore.hpp:392
size_t log(Message &message_)
Log a bookmark to the persistent log.
Definition: BookmarkStore.hpp:268
virtual void persisted(const Message::Field &subId_, const Message::Field &bookmark_)=0
Mark the bookmark provided as replicated to all sync replication destinations for the given subscript...
Field represents the value of a single field in a Message.
Definition: Field.hpp:86
virtual void purge()=0
Called to purge the contents of this store.
virtual void setServerVersion(size_t version_)=0
Internally used to set the server version so the store knows how to deal with persisted acks and call...
size_t getMaxSubIdLength() const
Gets the maximum allowed length for a sub id when recovering a bookmark store from persistent storage...
Definition: BookmarkStore.hpp:206
size_t getMaxSubIdLength() const
Gets the maximum allowed length for a sub id when recovering a bookmark store from persistent storage...
Definition: BookmarkStore.hpp:481
Definition: ampsplusplus.hpp:102
size_t getOldestBookmarkSeq(const std::string &subId_)
Called to find the oldest bookmark in the store.
Definition: BookmarkStore.hpp:380
Message::Field getMostRecent(const Message::Field &subId_)
Returns the most recent bookmark from the log that ought to be used for (re-)subscriptions.
Definition: BookmarkStore.hpp:310
virtual size_t log(Message &message_)=0
Log a bookmark to the persistent log.
void setMaxSubIdLength(size_t maxSubIdLength_)
Sets the maximum allowed length for a sub id when recovering a bookmark store from persistent storage...
Definition: BookmarkStore.hpp:215
static const size_t BOOKMARK_NONE
An indicator of no bookmark value.
Definition: Message.hpp:546
BookmarkStore()
Creates a BookmarkStore that does nothing.
Definition: BookmarkStore.hpp:234
void prune(const std::string &tmpFileName_="")
Used to trim the size of a store's storage.
Definition: BookmarkStore.hpp:454