26 #ifndef _PUBLISHSTORE_H_
27 #define _PUBLISHSTORE_H_
56 PublishStore(
const std::string& fileName_,
bool errorOnPublishGap_ =
false)
58 fileName_, AMPS_MEMORYBUFFER_DEFAULT_LENGTH,
59 DEFAULT_BLOCK_SIZE, true), 1000,
60 true, errorOnPublishGap_)
61 , _fileName(fileName_)
62 , _initialBlocks(1000)
63 , _truncateOnClose(false)
65 recoverUsingPersistedBlockSize();
76 PublishStore(
const std::string& fileName_,
size_t blocksPerRealloc_,
77 bool errorOnPublishGap_ =
false)
80 getInitialBufferSize(blocksPerRealloc_, DEFAULT_BLOCK_SIZE),
82 blocksPerRealloc_, DEFAULT_BLOCK_SIZE), true),
83 normalizeBlocksPerRealloc(
84 blocksPerRealloc_, DEFAULT_BLOCK_SIZE),
85 true, errorOnPublishGap_,
87 blocksPerRealloc_, DEFAULT_BLOCK_SIZE))
88 , _fileName(fileName_)
89 , _initialBlocks((int)normalizeBlocksPerRealloc(
90 blocksPerRealloc_, DEFAULT_BLOCK_SIZE))
91 , _truncateOnClose(false)
93 recoverUsingPersistedBlockSize();
109 amps_uint32_t blockSize_,
bool errorOnPublishGap_ =
false)
112 getInitialBufferSize(blocksPerRealloc_, blockSize_),
113 normalizeBlockSize(blocksPerRealloc_, blockSize_), true),
114 normalizeBlocksPerRealloc(
115 blocksPerRealloc_, blockSize_),
116 true, errorOnPublishGap_,
117 normalizeBlockSize(blocksPerRealloc_, blockSize_))
118 , _fileName(fileName_)
119 , _initialBlocks((int)normalizeBlocksPerRealloc(
120 blocksPerRealloc_, blockSize_))
121 , _truncateOnClose(false)
123 recoverUsingPersistedBlockSize();
138 _truncateOnClose = truncate_;
150 BufferLock guard(_blockStore);
152 if (_truncateOnClose && unpersisted == 0)
156 HANDLE file = INVALID_HANDLE_VALUE;
157 while ( file == INVALID_HANDLE_VALUE && retries++ < 5)
159 file = CreateFileA(_fileName.c_str(),
160 GENERIC_READ | GENERIC_WRITE, 0, NULL,
161 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
164 if ( file != INVALID_HANDLE_VALUE )
166 SetFilePointer(file, (LONG)(_initialBlocks * _blockStore.
getBlockSize()),
172 if (truncate(_fileName.c_str(),
173 (off_t)_initialBlocks * (off_t)_blockStore.
getBlockSize()) == -1)
186 BufferLock guard(_blockStore);
190 void recoverUsingPersistedBlockSize()
193 BufferLock guard(_blockStore);
196 if (buffer->
getSize() >=
sizeof(amps_uint32_t))
199 amps_uint32_t persistedBlockSize = buffer->
getUint32();
202 if (persistedBlockSize > 1)
209 BlockPublishStore::recover();
212 std::string _fileName;
214 bool _truncateOnClose;
Provides AMPS::BlockPublishStore, a concrete implementation of a store that breaks the allocated stor...
Provides AMPS::MMapStoreBuffer, an AMPS::Buffer implementation used by the AMPS::MMapBookmarkStore.
Core type, function, and class declarations for the AMPS C++ client.
Used as a base class for other stores in the AMPS C++ client, this is an implementation of StoreImpl ...
Definition: BlockPublishStore.hpp:61
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
Buffer * getBuffer()
Return the buffer underlying the store for direct write/read.
Definition: BlockStore.hpp:677
amps_uint32_t setBlockSize(amps_uint32_t blockSize_)
Set the size to use for all Blocks.
Definition: BlockStore.hpp:648
amps_uint32_t getBlockSize() const
Get the size of each Block, as set in the constructor.
Definition: BlockStore.hpp:189
A Buffer implementation that uses a memory mapped file as its storage.
Definition: MMapStoreBuffer.hpp:51
void setSizeAlignment(size_t sizeAlignment_)
Set the allocation-unit alignment for logical buffer sizes.
Definition: MMapStoreBuffer.hpp:200
virtual void setPosition(size_t position_)
Set the buffer postion to a location.
Definition: MemoryStoreBuffer.hpp:88
virtual amps_uint32_t getUint32()
Get the unsigned 32-bit int value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:170
virtual size_t getSize() const
Get the current size of the Buffer in bytes.
Definition: MemoryStoreBuffer.hpp:62
A StoreImpl implementation that uses a memory-mapped file to provide a publish store that persists ac...
Definition: PublishStore.hpp:47
void close()
Close the PublishStore and associated file.
Definition: PublishStore.hpp:143
PublishStore(const std::string &fileName_, size_t blocksPerRealloc_, bool errorOnPublishGap_=false)
Create a PublishStore that uses fileName_ for the storage.
Definition: PublishStore.hpp:76
PublishStore(const std::string &fileName_, bool errorOnPublishGap_=false)
Create a PublishStore that uses fileName_ for the storage.
Definition: PublishStore.hpp:56
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:136
void sync()
Force the PublishStore to sync to disk.
Definition: PublishStore.hpp:184
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:108