AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.4.3
AMPS::BlockPublishStore Class Reference

Used as a base class for other stores in the AMPS C++ client, this is an implementation of StoreImpl that breaks a provided Buffer into uniform blocks for storing messages and tracks used and unused blocks. More...

#include <BlockPublishStore.hpp>

+ Inheritance diagram for AMPS::BlockPublishStore:

Public Types

Public Member Functions

amps_uint32_t getBlockSize ()
 Return the size left in a block for data when it has a header in it. More...
 
amps_uint32_t getBlockDataSize ()
 Return the size left in a block for data when it has a header in it. More...
 
 BlockPublishStore (Buffer *buffer_, amps_uint32_t blocksPerRealloc_=1000, bool isFile_=false, bool errorOnPublishGap_=false, amps_uint32_t blockSize_=DEFAULT_BLOCK_SIZE)
 Create a BlockPublishStore using buffer_, that grows by blocksPerRealloc_ blocks when it must grow. More...
 
virtual ~BlockPublishStore ()
 Destructor that cleans up the buffer and other associated memory.
 
virtual amps_uint64_t store (const Message &message_)
 Store a given message that will be delivered to AMPS. More...
 
amps_uint64_t store (const Message &message_, bool assignSequence_)
 Store a given message that will be delivered to AMPS. More...
 
virtual void discardUpTo (amps_uint64_t index_)
 Remove all messages with an index up to and including index_. More...
 
void replay (StoreReplayer &replayer_)
 Replay all messages in the Store onto the given StoreReplayer. More...
 
bool replaySingle (StoreReplayer &replayer_, amps_uint64_t index_)
 Replay one message in the Store onto the given StoreReplayer. More...
 
size_t unpersistedCount () const
 Method to return the count of messages that currently in the Store because they have not been discarded, presumably because AMPS has not yet acknowledged them. More...
 
virtual void flush (long timeout_)
 Method to wait for the Store to discard everything that has been stored up to the point in time when flush is called. More...
 
amps_uint64_t getLowestUnpersisted () const
 Get the oldest unpersisted message sequence in the store. More...
 
amps_uint64_t getLastPersisted (void)
 Get the last persisted sequence number. More...
 
- Public Member Functions inherited from AMPS::StoreImpl
 StoreImpl (bool errorOnPublishGap_=false)
 Default constructor. More...
 
virtual void setResizeHandler (PublishStoreResizeHandler handler_, void *userData_)
 Set a handler to be called if the Store needs to resize in order to keep storing messages. More...
 

Static Public Member Functions

static amps_uint32_t getBlockHeaderSize ()
 Block header is number of blocks, total length, sequence number, crc, next in chain offset. More...
 
static amps_uint32_t getBlockChainHeaderSize ()
 Block chain header is operation, command id length, correlation id length, expiration length, sow key length, topic length, sow delete flag, ack types. More...
 
- Static Public Member Functions inherited from AMPS::StoreImpl
static size_t getUnsetPosition ()
 Method to return the value used to represent not found or unset.
 
static amps_uint64_t getUnsetSequence ()
 Method to return the value used to represent no such sequence.
 

Detailed Description

Used as a base class for other stores in the AMPS C++ client, this is an implementation of StoreImpl that breaks a provided Buffer into uniform blocks for storing messages and tracks used and unused blocks.

Constructor & Destructor Documentation

AMPS::BlockPublishStore::BlockPublishStore ( Buffer buffer_,
amps_uint32_t  blocksPerRealloc_ = 1000,
bool  isFile_ = false,
bool  errorOnPublishGap_ = false,
amps_uint32_t  blockSize_ = DEFAULT_BLOCK_SIZE 
)
inline

Create a BlockPublishStore using buffer_, that grows by blocksPerRealloc_ blocks when it must grow.

If isFile_ is true, it will use CRCs for all storage and retrieval.

Parameters
buffer_Pointer to an allocated Buffer implementation that will be used for storage. The store will delete buffer_ when it is destructed.
blocksPerRealloc_Number of blocks to add to when growing the size of the Buffer.
isFile_Whether or not the buffer is a recoverable file. If false, the buffer is intialized as if empty, otherwise recovery remains possible and a CRC will be used for all stored items.
errorOnPublishGap_If true, PublishStoreGapException can be thrown by the store if the client logs onto a server that appears to be missing messages no longer held in the store.
blockSize_Size in bytes for each Block

Member Function Documentation

virtual void AMPS::BlockPublishStore::discardUpTo ( amps_uint64_t  index_)
inlinevirtual

Remove all messages with an index up to and including index_.

This method is used internally by the Client to remove messages once they have been acknowledged by AMPS as stored on the server side.

Parameters
index_The highest index to remove.
Exceptions
PublishStoreGapExceptionIf index_ < getLastPersisted() which could leave a gap on the server of missing messages from this Client.

Implements AMPS::StoreImpl.

virtual void AMPS::BlockPublishStore::flush ( long  timeout_)
inlinevirtual

Method to wait for the Store to discard everything that has been stored up to the point in time when flush is called.

It will get the current max and wait up to timeout for that message to be discarded

Parameters
timeout_The number of milliseconds to wait.
Exceptions
DisconnectedExceptionThe Client is no longer connected to a server.
ConnectionExceptionAn error occurred while sending the message.
TimedOutExceptionThe publish command was not acked in the allowed time.

Implements AMPS::StoreImpl.

static amps_uint32_t AMPS::BlockPublishStore::getBlockChainHeaderSize ( )
inlinestatic

Block chain header is operation, command id length, correlation id length, expiration length, sow key length, topic length, sow delete flag, ack types.

Returns
The size of Block chain header
amps_uint32_t AMPS::BlockPublishStore::getBlockDataSize ( )
inline

Return the size left in a block for data when it has a header in it.

Returns
The amount of room left in a block for data
static amps_uint32_t AMPS::BlockPublishStore::getBlockHeaderSize ( )
inlinestatic

Block header is number of blocks, total length, sequence number, crc, next in chain offset.

Returns
The size of Block header
amps_uint32_t AMPS::BlockPublishStore::getBlockSize ( )
inline

Return the size left in a block for data when it has a header in it.

Returns
The amount of room left in a block for data
amps_uint64_t AMPS::BlockPublishStore::getLastPersisted ( void  )
inlinevirtual

Get the last persisted sequence number.

Returns
The sequence of the last persisted message.

Implements AMPS::StoreImpl.

amps_uint64_t AMPS::BlockPublishStore::getLowestUnpersisted ( ) const
inlinevirtual

Get the oldest unpersisted message sequence in the store.

Returns
The sequence of the oldest message.

Implements AMPS::StoreImpl.

void AMPS::BlockPublishStore::replay ( StoreReplayer replayer_)
inlinevirtual

Replay all messages in the Store onto the given StoreReplayer.

This is used internally by the Client to replay any messages to the server after a successful connection or reconnection to AMPS.

Parameters
replayer_The StoreReplayer that will transmit the message.

Implements AMPS::StoreImpl.

bool AMPS::BlockPublishStore::replaySingle ( StoreReplayer replayer_,
amps_uint64_t  index_ 
)
inlinevirtual

Replay one message in the Store onto the given StoreReplayer.

This is used internally by replay to replay each message.

Parameters
replayer_The StoreReplayer that will transmit the message.
index_The index of the message to replay.
Returns
Returns true for success, false for failure such as an invalid index.

Implements AMPS::StoreImpl.

virtual amps_uint64_t AMPS::BlockPublishStore::store ( const Message message_)
inlinevirtual

Store a given message that will be delivered to AMPS.

This method will also assign a sequence number to the Message. This method is primarily used internally by the Client to store outgoing messages.

Parameters
message_The Message to put into the store.

Implements AMPS::StoreImpl.

amps_uint64_t AMPS::BlockPublishStore::store ( const Message message_,
bool  assignSequence_ 
)
inline

Store a given message that will be delivered to AMPS.

This method will also assign a sequence number to the Message if assignSequence_ is true. HybridPublishStore uses this method with false when moving messages from memory to file.

Parameters
message_The Message to put into the store.
assignSequence_If true, message_ will be updated with the next sequence number from the store.
Returns
The sequence number of the message_.
size_t AMPS::BlockPublishStore::unpersistedCount ( ) const
inlinevirtual

Method to return the count of messages that currently in the Store because they have not been discarded, presumably because AMPS has not yet acknowledged them.

This assumes that there are no gaps in sequence numbers for better performance.

Returns
The count of messages in the store.

Implements AMPS::StoreImpl.


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