25 #ifndef _BOOKMARKSTORE_H_ 26 #define _BOOKMARKSTORE_H_ 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&) {
return; }
205 return _maxSubIdLength;
214 _maxSubIdLength = maxSubIdLength_;
218 BookmarkStoreResizeHandler _resizeHandler;
219 void* _resizeHandlerData;
220 size_t _maxSubIdLength;
227 RefHandle<BookmarkStoreImpl> _body;
256 return _body.isValid();
268 return _body.get().log(message_);
281 _body.get().discard(subId_, bookmarkSeqNo_);
292 _body.get().discard(message_);
304 return _body.get().getMostRecent(subId_);
319 return _body.get().isDiscarded(message_);
342 _body.get().purge(subId_);
354 _body.get().setResizeHandler(handler_, userData_);
364 return _body.get().getOldestBookmarkSeq(
Message::Field(subId_.c_str(),
366 return AMPS_UNSET_INDEX;
376 return _body.get().getOldestBookmarkSeq(subId_);
377 return AMPS_UNSET_INDEX;
387 _body.get().persisted(subId_, bookmark_);
397 _body.get().persisted(subId_, bookmark_);
407 _body.get().setServerVersion(version_);
417 _body.get().setServerVersion(version_);
425 void prune(
const std::string& tmpFileName_ =
"")
428 _body.get().prune(tmpFileName_);
449 return _body.get().getMaxSubIdLength();
461 _body.get().setMaxSubIdLength(maxSubIdLength_);
466 inline bool BookmarkStoreImpl::callResizeHandler(
const Message::Field& subId_,
470 return _resizeHandler(
BookmarkStore(
this), subId_, newSize_, _resizeHandlerData);
480 inline bool ThrowawayBookmarkResizeHandler(
BookmarkStore store_,
482 size_t newSize_,
void* data_)
484 size_t* maxSizep = (
size_t*)data_;
485 if (newSize_ > *maxSizep)
488 store_.
discard(subId_, discardSeq);
497 #endif //_BOOKMARKSTORE_H_ void purge(const Message::Field &subId_)
Called to purge the contents of this store for particular subId.
Definition: BookmarkStore.hpp:339
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:458
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:404
void discard(const Message &message_)
Log a discard-bookmark entry to the persistent log based on a Message.
Definition: BookmarkStore.hpp:289
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:384
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:278
bool isDiscarded(Message &message_)
Called for each arriving message to determine if the application has already seen this bookmark and s...
Definition: BookmarkStore.hpp:316
void purge()
Called to purge the contents of this store.
Definition: BookmarkStore.hpp:328
Message encapsulates a single message sent to or received from an AMPS server, and provides methods f...
Definition: Message.hpp:447
BookmarkStore(BookmarkStoreImpl *impl_)
Creates a BookmarkStore based on the given implementation.
Definition: BookmarkStore.hpp:235
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:414
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:351
void setImplementation(BookmarkStoreImpl *impl_)
Sets the BookmarkStore to use the given implementation.
Definition: BookmarkStore.hpp:249
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:225
#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:394
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:373
size_t log(Message &message_)
Log a bookmark to the persistent log.
Definition: BookmarkStore.hpp:265
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:84
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:203
size_t getMaxSubIdLength() const
Gets the maximum allowed length for a sub id when recovering a bookmark store from persistent storage...
Definition: BookmarkStore.hpp:446
Definition: ampsplusplus.hpp:103
size_t getOldestBookmarkSeq(const std::string &subId_)
Called to find the oldest bookmark in the store.
Definition: BookmarkStore.hpp:361
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:301
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:212
static const size_t BOOKMARK_NONE
An indicator of no bookmark value.
Definition: Message.hpp:462
BookmarkStore()
Creates a BookmarkStore that does nothing.
Definition: BookmarkStore.hpp:231
void prune(const std::string &tmpFileName_="")
Used to trim the size of a store's storage.
Definition: BookmarkStore.hpp:425