AMPS C# Client  5.3.5.0
AMPS C# Client for .NET
AMPS.Client.PublishStore Class Reference

PublishStore is a memory-mapped file-backed store for storing outgoing messages. As messages are stored, space is allocated from a pre-created flat buffer on disk. As messages are discarded, space in that buffer is marked "free" for future store operations. If messages are stored faster than they are published, the buffer is re-sized to create more capacity. PublishStore helps in keeping track of unacknowledged messages. If messages are published at a rate exceeding the storage capacity, the buffer is resized to accommodate more messages. More...

+ Inheritance diagram for AMPS.Client.PublishStore:

Public Member Functions

 PublishStore (string path, bool errorOnPublishGap=false)
 Create a PublishStore using a file at path More...
 
 PublishStore (string path, int blocksPerRealloc, bool errorOnPublishGap=false)
 Create a PublishStore using a file at path with an initial size and resize value of blocksPerRealloc. More...
 
void setCrc (Utilities.CRC32 crc_)
 Set an implementation of CRC32 to be used by the Store to prevent message corruption Default implementation is AMPS.Client.Utilities.DefaultCRC32 Passing in null will mean no crc calculation and no checking for file corruption. More...
 
void open ()
 Opens the memory-mapped file buffer. More...
 
void truncateOnClose (bool truncate)
 Sets whether to truncate the file on close. More...
 
override void Dispose ()
 Disposes of the current instance, closing the memory-mapped file and performing any necessary cleanup. More...
 
void close ()
 Closes the memory-mapped file and performs any necessary cleanup. More...
 
void sync ()
 Flushes any buffered data to the memory-mapped file and underlying file stream, ensuring that all changes are persisted. More...
 
- Public Member Functions inherited from AMPS.Client.BlockPublishStore
void store (Message m)
 Stores a message in the BlockPublishStore. More...
 
void store (Message m, Boolean assignSequence)
 Internal utility method for storing messages in the BlockPublishStore. More...
 
virtual void discardUpTo (ulong sequence)
 Discard messages in the store, up to and including the message specified by the passed in sequnence number. This is called by the client when it's notified a message is persisted on the server. The space used by discarded messages is made available for reuse by later messages. More...
 
ulong getLastPersisted ()
 Gets the last persisted sequence number More...
 
ulong getLowestUnpersisted ()
 Gets the lowest unpersisted sequence number. More...
 
ulong getHighestUnpersisted ()
 Gets the highest unpersisted sequence number. More...
 
void setMessage (Message message)
 Used internally by the Client to give the store a Message implementing the correct protocol for the connection. This Message instance is also used for replay operations. More...
 
virtual void replay (StoreReplayer replayer)
 Implemented to replay unpersisted messages from the stored blocks onto the provided StoreReplayer. More...
 
bool replaySingle (StoreReplayer replayer, ulong sequence)
 Implemented to find the unpersisted message with the specified sequence among the stored blocks, and replay it onto the provided StoreReplayer. Checks if the specified sequence is less than or equal to the stored metadata block's sequence number. More...
 
long unpersistedCount ()
 Returns the count of unpersisted messages in the store. This count represents the number of messages that have been received but not yet persisted. More...
 
void flush ()
 Wait for the store to discard everything that has been stored up to the point in time when flush is called, then return. More...
 
void flush (int timeout)
 Wait for the store to discard everything that has been stored up to the point in time when flush is called, then return. Throw an exception if this is not completed in the number of milliseconds specified by the timeout. More...
 
void setResizeHandler (PublishStoreResizeHandler handler)
 Set the resize handler for the publish store. An implementation can call the resize handler in the event that it needs to grow the size of the publish store. More...
 
void setErrorOnPublishGap (bool errorOnPublishGap_)
 Set if a PublishStoreGapException should be thrown by the Store if there is an attempt to call discardUpTo with a sequence number lower than the last persisted sequence number. This could occur during logon after a failover event if the new server was not current on messages due to being an async replication destination. More...
 
virtual bool getErrorOnPublishGap ()
 Get if a PublishStoreGapException can be thrown by the Store if there is an attempt to call discardUpTo with a sequence number lower than the last persisted sequence number. This could occur during logon after a failover event if the new server was not current on messages due to being an async replication destination. More...
 

Additional Inherited Members

- Protected Member Functions inherited from AMPS.Client.BlockPublishStore
 BlockPublishStore (Buffer buffer, int blocksPerRealloc, bool errorOnPublishGap_=false)
 Initializes a new instance of the BlockPublishStore class with the specified buffer and block allocation configuration. More...
 
 BlockPublishStore (Buffer buffer, bool useCrc=false, int blocksPerRealloc=10000, bool errorOnPublishGap_=false)
 Initializes a new instance of the BlockPublishStore class with the specified buffer. More...
 
void recover ()
 Recovers the state of the BlockPublishStore by reconstructing the used and free lists from the stored blocks in the buffer. More...
 
void growFreeListIfEmpty ()
 Ensures that the free list has at least one block available for use. More...
 
- Protected Attributes inherited from AMPS.Client.BlockPublishStore
bool _errorOnPublishGap = false
 
PublishStoreResizeHandler _resizeHandler = null
 
Buffer _buffer
 
Utilities.CRC32 _crc = null
 

Detailed Description

PublishStore is a memory-mapped file-backed store for storing outgoing messages. As messages are stored, space is allocated from a pre-created flat buffer on disk. As messages are discarded, space in that buffer is marked "free" for future store operations. If messages are stored faster than they are published, the buffer is re-sized to create more capacity. PublishStore helps in keeping track of unacknowledged messages. If messages are published at a rate exceeding the storage capacity, the buffer is resized to accommodate more messages.

The PublishStore class provides a robust foundation for implementing features such as tracking unacknowledged messages and ensuring message persistence.

Constructor & Destructor Documentation

◆ PublishStore() [1/2]

AMPS.Client.PublishStore.PublishStore ( string  path,
bool  errorOnPublishGap = false 
)
inline

Create a PublishStore using a file at path

Parameters
pathThe file to use for the store
errorOnPublishGap_Indicates if an excpetion should be thrown if discardUpTo is called with an idex below the last persisted.

◆ PublishStore() [2/2]

AMPS.Client.PublishStore.PublishStore ( string  path,
int  blocksPerRealloc,
bool  errorOnPublishGap = false 
)
inline

Create a PublishStore using a file at path with an initial size and resize value of blocksPerRealloc.

Parameters
pathThe file to use for the store.
blocksPerReallocThe number of 2k blocks to use as initial size and resize increment.
errorOnPublishGap_Indicates if an excpetion should be thrown if discardUpTo is called with an idex below the last persisted.

Member Function Documentation

◆ close()

void AMPS.Client.PublishStore.close ( )
inline

Closes the memory-mapped file and performs any necessary cleanup.

◆ Dispose()

override void AMPS.Client.PublishStore.Dispose ( )
inlinevirtual

Disposes of the current instance, closing the memory-mapped file and performing any necessary cleanup.

Reimplemented from AMPS.Client.BlockPublishStore.

◆ open()

void AMPS.Client.PublishStore.open ( )
inline

Opens the memory-mapped file buffer.

◆ setCrc()

void AMPS.Client.PublishStore.setCrc ( Utilities.CRC32  crc_)
inline

Set an implementation of CRC32 to be used by the Store to prevent message corruption Default implementation is AMPS.Client.Utilities.DefaultCRC32 Passing in null will mean no crc calculation and no checking for file corruption.

Parameters
crc_The CRC32 checksum to set.

◆ sync()

void AMPS.Client.PublishStore.sync ( )
inline

Flushes any buffered data to the memory-mapped file and underlying file stream, ensuring that all changes are persisted.

◆ truncateOnClose()

void AMPS.Client.PublishStore.truncateOnClose ( bool  truncate)
inline

Sets whether to truncate the file on close.

Parameters
truncateA boolean indicating whether to truncate the file on close.

The documentation for this class was generated from the following file: