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

BlockPublishStore is a base class that implements the Store interface. It is designed for publish store implementations, allowing messages to be stored and managed efficiently. 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. More...

+ Inheritance diagram for AMPS.Client.BlockPublishStore:

Classes

class  Block
 
interface  Buffer
 Interface which is used to hold the BlockPublishStore buffer data. More...
 
class  ByteSequence
 A simple wrapper object around a byte array that allows a sub-range to be specified using its offset and length properties. More...
 

Public Member Functions

virtual void Dispose ()
 Performs implementation-defined tasks associated with freeing, releasing, or resetting resources. This method has no effect for the BlockPublishStore class. Publish store implementations that sub-class this class, should override it as needed. More...
 
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...
 

Protected Member Functions

 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

bool _errorOnPublishGap = false
 
PublishStoreResizeHandler _resizeHandler = null
 
Buffer _buffer
 
Utilities.CRC32 _crc = null
 

Detailed Description

BlockPublishStore is a base class that implements the Store interface. It is designed for publish store implementations, allowing messages to be stored and managed efficiently. 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.

Constructor & Destructor Documentation

◆ BlockPublishStore() [1/2]

AMPS.Client.BlockPublishStore.BlockPublishStore ( Buffer  buffer,
int  blocksPerRealloc,
bool  errorOnPublishGap_ = false 
)
inlineprotected

Initializes a new instance of the BlockPublishStore class with the specified buffer and block allocation configuration.

Parameters
bufferThe buffer used for storing messages.
blocksPerReallocThe number of blocks per reallocation, determining the block allocation during buffer resizing.
errorOnPublishGap_Indicates if an excpetion should be thrown if discardUpTo is called with an index below the last persisted.

◆ BlockPublishStore() [2/2]

AMPS.Client.BlockPublishStore.BlockPublishStore ( Buffer  buffer,
bool  useCrc = false,
int  blocksPerRealloc = 10000,
bool  errorOnPublishGap_ = false 
)
inlineprotected

Initializes a new instance of the BlockPublishStore class with the specified buffer.

Parameters
bufferThe buffer used for storing messages.
useCrcA boolean flag indicating whether to use CRC (Cyclic Redundancy Check).
blocksPerReallocThe number of blocks per reallocation, determining the block allocation during buffer resizing.
errorOnPublishGap_Indicates if an excpetion should be thrown if discardUpTo is called with an index below the last persisted.

Member Function Documentation

◆ discardUpTo()

virtual void AMPS.Client.BlockPublishStore.discardUpTo ( ulong  sequence)
inlinevirtual

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.

Parameters
sequenceThe highest sequence number of the messages that can be safely discarded. The specified message and all prior messages are removed from the store.
Exceptions
StoreExceptionIf an error occurred during discarding.

Implements AMPS.Client.Store.

Reimplemented in AMPS.Client.MemoryPublishStore.

◆ Dispose()

virtual void AMPS.Client.BlockPublishStore.Dispose ( )
inlinevirtual

Performs implementation-defined tasks associated with freeing, releasing, or resetting resources. This method has no effect for the BlockPublishStore class. Publish store implementations that sub-class this class, should override it as needed.

Reimplemented in AMPS.Client.PublishStore, and AMPS.Client.MemoryPublishStore.

◆ flush() [1/2]

void AMPS.Client.BlockPublishStore.flush ( )
inline

Wait for the store to discard everything that has been stored up to the point in time when flush is called, then return.

Implements AMPS.Client.Store.

◆ flush() [2/2]

void AMPS.Client.BlockPublishStore.flush ( int  timeout)
inline

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.

Parameters
timeoutThe number of milliseconds to wait for the flush.
Exceptions
TimedOutException

Implements AMPS.Client.Store.

◆ getErrorOnPublishGap()

virtual bool AMPS.Client.BlockPublishStore.getErrorOnPublishGap ( )
inlinevirtual

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.

Returns
True if the exception will be thrown

Implements AMPS.Client.Store.

Reimplemented in AMPS.Client.MemoryPublishStore.

◆ getHighestUnpersisted()

ulong AMPS.Client.BlockPublishStore.getHighestUnpersisted ( )
inline

Gets the highest unpersisted sequence number.

Returns
The highest unpersisted sequence number.

◆ getLastPersisted()

ulong AMPS.Client.BlockPublishStore.getLastPersisted ( )
inline

Gets the last persisted sequence number

Returns
The last persisted sequence number.

Implements AMPS.Client.Store.

◆ getLowestUnpersisted()

ulong AMPS.Client.BlockPublishStore.getLowestUnpersisted ( )
inline

Gets the lowest unpersisted sequence number.

Returns
The lowest unpersisted sequence number or -1 if no sequence numbers are unpersisted.

◆ growFreeListIfEmpty()

void AMPS.Client.BlockPublishStore.growFreeListIfEmpty ( )
inlineprotected

Ensures that the free list has at least one block available for use.

◆ recover()

void AMPS.Client.BlockPublishStore.recover ( )
inlineprotected

Recovers the state of the BlockPublishStore by reconstructing the used and free lists from the stored blocks in the buffer.

◆ replay()

virtual void AMPS.Client.BlockPublishStore.replay ( StoreReplayer  replayer)
inlinevirtual

Implemented to replay unpersisted messages from the stored blocks onto the provided StoreReplayer.

Parameters
replayerThe StoreReplayer used to replay undiscarded messages.

Implements AMPS.Client.Store.

◆ replaySingle()

bool AMPS.Client.BlockPublishStore.replaySingle ( StoreReplayer  replayer,
ulong  sequence 
)
inline

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.

Parameters
replayerThe StoreReplayer onto which the block will be replayed.
sequenceThe sequence number of the block to be replayed.
Returns
True if the block is successfully replayed, false otherwise.

Implements AMPS.Client.Store.

◆ setErrorOnPublishGap()

void AMPS.Client.BlockPublishStore.setErrorOnPublishGap ( bool  errorOnPublishGap_)
inline

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.

Parameters
errorOnPublishGap_Indicates if the exception should be thrown

Implements AMPS.Client.Store.

◆ setMessage()

void AMPS.Client.BlockPublishStore.setMessage ( Message  message)
inline

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.

Parameters
messageA Message of the correct protocol type.

Implements AMPS.Client.Store.

◆ setResizeHandler()

void AMPS.Client.BlockPublishStore.setResizeHandler ( PublishStoreResizeHandler  handler)
inline

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.

Parameters
handlerThe resize handler to set

Implements AMPS.Client.Store.

◆ store() [1/2]

void AMPS.Client.BlockPublishStore.store ( Message  m)
inline

Stores a message in the BlockPublishStore.

Parameters
mThe message to be stored.
Exceptions
StoreExceptionIf an error occurs during message storage.

Implements AMPS.Client.Store.

◆ store() [2/2]

void AMPS.Client.BlockPublishStore.store ( Message  m,
Boolean  assignSequence 
)
inline

Internal utility method for storing messages in the BlockPublishStore.

Parameters
mThe messge to be stored.
assignSequenceA boolean flag indicating whether to assign a sequence number to the message.
Exceptions
StoreExceptionIf an error occurs during message storage.

◆ unpersistedCount()

long AMPS.Client.BlockPublishStore.unpersistedCount ( )
inline

Returns the count of unpersisted messages in the store. This count represents the number of messages that have been received but not yet persisted.

Returns
The count of unpersisted messages.

Implements AMPS.Client.Store.


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