26 #ifndef _PUBLISHSTORE_H_ 27 #define _PUBLISHSTORE_H_ 56 PublishStore(
const std::string& fileName_,
bool errorOnPublishGap_ =
false)
58 true, errorOnPublishGap_)
59 , _fileName(fileName_)
60 , _initialBlocks(1000)
61 , _truncateOnClose(false)
74 PublishStore(
const std::string& fileName_,
size_t blocksPerRealloc_,
75 bool errorOnPublishGap_ =
false)
77 (amps_uint32_t)blocksPerRealloc_,
78 true, errorOnPublishGap_)
79 , _fileName(fileName_)
80 , _initialBlocks((int)blocksPerRealloc_)
81 , _truncateOnClose(false)
98 PublishStore(
const std::string& fileName_,
size_t blocksPerRealloc_,
99 amps_uint32_t blockSize_,
bool errorOnPublishGap_ =
false)
101 (amps_uint32_t)blocksPerRealloc_,
102 true, errorOnPublishGap_, blockSize_)
103 , _fileName(fileName_)
104 , _initialBlocks((int)blocksPerRealloc_)
105 , _truncateOnClose(false)
122 _truncateOnClose = truncate_;
134 BufferLock guard(_blockStore);
136 if (_truncateOnClose && unpersisted == 0)
140 HANDLE file = INVALID_HANDLE_VALUE;
141 while ( file == INVALID_HANDLE_VALUE && retries++ < 5)
143 file = CreateFileA(_fileName.c_str(),
144 GENERIC_READ | GENERIC_WRITE, 0, NULL,
145 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
148 if ( file != INVALID_HANDLE_VALUE )
150 SetFilePointer(file, (LONG)(_initialBlocks * _blockStore.
getBlockSize()),
156 if (truncate(_fileName.c_str(),
157 (off_t)_initialBlocks * (off_t)_blockStore.
getBlockSize()) == -1)
170 BufferLock guard(_blockStore);
174 std::string _fileName;
176 bool _truncateOnClose;
181 #endif //_PUBLISHSTORE_H_ PublishStore(const std::string &fileName_, size_t blocksPerRealloc_, amps_uint32_t blockSize_, bool errorOnPublishGap_=false)
Create a PublishStore that uses fileName_ for the storage.
Definition: PublishStore.hpp:98
Buffer * getBuffer()
Return the buffer underlying the store for direct write/read.
Definition: BlockStore.hpp:597
Provides AMPS::MMapStoreBuffer, an AMPS::Buffer implementation used by the AMPS::MMapBookmarkStore.
void truncateOnClose(bool truncate_)
Tell the PublishStore if it should return the file to its initial capacity when the store is closed i...
Definition: PublishStore.hpp:120
Provides AMPS::BlockPublishStore, a concrete implementation of a store that breaks the allocated stor...
A StoreImpl implementation that uses a memory-mapped file to provide a publish store that persists ac...
Definition: PublishStore.hpp:46
Core type, function, and class declarations for the AMPS C++ client.
size_t unpersistedCount() const
Method to return the count of messages that currently in the Store because they have not been discard...
Definition: BlockPublishStore.hpp:642
A Buffer implementation that uses a memory mapped file as its storage.
Definition: MMapStoreBuffer.hpp:49
void sync()
Force the PublishStore to sync to disk.
Definition: PublishStore.hpp:168
Used as a base class for other stores in the AMPS C++ client, this is an implementation of StoreImpl ...
Definition: BlockPublishStore.hpp:60
PublishStore(const std::string &fileName_, size_t blocksPerRealloc_, bool errorOnPublishGap_=false)
Create a PublishStore that uses fileName_ for the storage.
Definition: PublishStore.hpp:74
void close()
Close the PublishStore and associated file.
Definition: PublishStore.hpp:127
amps_uint32_t getBlockSize() const
Get the size of each Block, as set in the constructor.
Definition: BlockStore.hpp:160
Definition: ampsplusplus.hpp:103
PublishStore(const std::string &fileName_, bool errorOnPublishGap_=false)
Create a PublishStore that uses fileName_ for the storage.
Definition: PublishStore.hpp:56