AMPS C/C++ Client Class Reference AMPS C/C++ Client Version 5.3.5.6

Public Member Functions | List of all members
AMPS::HybridPublishStore Class Reference

An implementation of StoreImpl for publication. More...

`#include <HybridPublishStore.hpp>`

Inheritance diagram for AMPS::HybridPublishStore:

## Public Member Functions
| HybridPublishStore (const char *fileName_, size_t maxMemoryCapacity_, bool errorOnPublishGap_=false)
| Create a HybridPublishStore that will use fileName_ as its file storage and stores at most maxMemoryCapacity_ messages in memory before offloading some messages to the file. More...
| HybridPublishStore (const std::string &fileName_, size_t maxMemoryCapacity_, bool errorOnPublishGap_=false)
| Create a HybridPublishStore that will use fileName_ as its file storage and stores at most maxMemoryCapacity_ messages in memory before offloading some messages to the file. More...
| HybridPublishStore (const std::string &fileName_, size_t maxMemoryCapacity_, amps_uint32_t blockSize_, bool errorOnPublishGap_=false)
| Create a HybridPublishStore that will use fileName_ as its file storage and stores at most maxMemoryCapacity_ messages in memory before offloading some messages to the file. More...
void | setLowWatermark (size_t lowWatermark_)
| Set how many messags remain in memory after messages get offlined. More...
size_t | getLowWatermark ()
| Get how many messags remain in memory after messages get offlined. More...
void | discardUpTo (amps_uint64_t index_)
| Discard all messages in the store up to and including index_. More...
void | replay (StoreReplayer &replayer_)
| Used internally by Client to replay messages in the store to AMPS after a successful connection. More...
size_t | unpersistedCount () const
| The number of messages in the Store that have not been discarded. 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...
bool | replaySingle (StoreReplayer &replayer_, amps_uint64_t index_)
| Called by Client to get a single message replayed by the store onto the StoreReplayer. More...
amps_uint64_t | store (const Message &message_)
| Used internally by Client to put messages into the Store. More...
void | setResizeHandler (PublishStoreResizeHandler handler_, void *data_)
| Set a handler to be called if the Store needs to resize in order to keep storing messages. 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...

## Additional Inherited Members
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

An implementation of StoreImpl for publication.

This store uses memory up to a specified capacity, then starts using a file if it will exceed the set maximum memory capacity. This store does not provide guaranteed durable publication if the application is restarted. However, this store does help to limit the amount of memory consumed by a publisher when the publisher cannot connect to AMPS.

## Constructor & Destructor Documentation

## ◆ HybridPublishStore() [1/3]

AMPS::HybridPublishStore::HybridPublishStore | ( | const char * | fileName_,
|  | size_t | maxMemoryCapacity_,
|  | bool | errorOnPublishGap_ = `false`
| ) |  |
| inline

Create a HybridPublishStore that will use fileName_ as its file storage and stores at most maxMemoryCapacity_ messages in memory before offloading some messages to the file.

Parameters

  fileName_ | The name to use for the file-based storage.
  maxMemoryCapacity_ | The maximum number of messages to store in in memory before starting to use a file.
  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.

## ◆ HybridPublishStore() [2/3]

AMPS::HybridPublishStore::HybridPublishStore | ( | const std::string & | fileName_,
|  | size_t | maxMemoryCapacity_,
|  | bool | errorOnPublishGap_ = `false`
| ) |  |
| inline

Create a HybridPublishStore that will use fileName_ as its file storage and stores at most maxMemoryCapacity_ messages in memory before offloading some messages to the file.

Parameters

  fileName_ | The name to use for the file-based storage.
  maxMemoryCapacity_ | The maximum number of messages to store in in memory before starting to use a file.
  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.

## ◆ HybridPublishStore() [3/3]

AMPS::HybridPublishStore::HybridPublishStore | ( | const std::string & | fileName_,
|  | size_t | maxMemoryCapacity_,
|  | amps_uint32_t | blockSize_,
|  | bool | errorOnPublishGap_ = `false`
| ) |  |
| inline

Create a HybridPublishStore that will use fileName_ as its file storage and stores at most maxMemoryCapacity_ messages in memory before offloading some messages to the file.

Parameters

  fileName_ | The name to use for the file-based storage.
  maxMemoryCapacity_ | The maximum number of messages to store in in memory before starting to use a file.
  blockSize_ | The size of each block, default is 2KB. Should be a 64-byte aligned value that is > 64 + expected message size. Larger messages can span blocks but 1 block per message is most efficient.
  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.

## Member Function Documentation

## ◆ discardUpTo()

void AMPS::HybridPublishStore::discardUpTo | ( | amps_uint64_t | index_ | ) |
| inline virtual

Discard all messages in the store up to and including index_.

Parameters

  index_ | The maximum index to remove from storage.

Implements AMPS::StoreImpl.

## ◆ flush()

virtual void AMPS::HybridPublishStore::flush | ( | long | timeout_ | ) |
| inline virtual

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

  DisconnectedException | The Client is no longer connected to a server.
  ConnectionException | An error occurred while sending the message.
  TimedOutException | The publish command was not acked in the allowed time.

Implements AMPS::StoreImpl.

## ◆ getLastPersisted()

amps_uint64_t AMPS::HybridPublishStore::getLastPersisted | ( | void |  | ) |
| inline virtual

Get the last persisted sequence number.

Returns
  The sequence of the last persisted message.

Implements AMPS::StoreImpl.

## ◆ getLowestUnpersisted()

amps_uint64_t AMPS::HybridPublishStore::getLowestUnpersisted | ( |  | ) | const
| inline virtual

Get the oldest unpersisted message sequence in the store.

Returns
  The sequence of the oldest message.

Implements AMPS::StoreImpl.

## ◆ getLowWatermark()

size_t AMPS::HybridPublishStore::getLowWatermark | ( |  | ) |
| inline

Get how many messags remain in memory after messages get offlined.

When memory storage reaches its cap, it will write its oldest messages to its file until it is holding only lowWatermark_ messages.

Returns
  The number of messages that remain in memory after offlining completes.

## ◆ replay()

void AMPS::HybridPublishStore::replay | ( | StoreReplayer & | replayer_ | ) |
| inline virtual

Used internally by Client to replay messages in the store to AMPS after a successful connection.

Parameters

  replayer_ | The StoreReplayer that replays the messages.

Implements AMPS::StoreImpl.

## ◆ replaySingle()

bool AMPS::HybridPublishStore::replaySingle | ( | StoreReplayer & | replayer_,
|  | amps_uint64_t | index_
| ) |  |
| inline virtual

Called by Client to get a single message replayed by the store onto the StoreReplayer.

Parameters

  replayer_ | The StoreReplayer to be used to replay the messages.
  index_ | The index of the message to replay.

Returns
  Returns true for success, false for failure such as an invalid index.

Implements AMPS::StoreImpl.

## ◆ setLowWatermark()

void AMPS::HybridPublishStore::setLowWatermark | ( | size_t | lowWatermark_ | ) |
| inline

Set how many messags remain in memory after messages get offlined.

When memory storage reaches its cap, it will write its oldest messages to its file until it is holding only lowWatermark_ messages.

Parameters

  lowWatermark_ | The number of messages that remain in memory after offlining completes.

## ◆ setResizeHandler()

void AMPS::HybridPublishStore::setResizeHandler | ( | PublishStoreResizeHandler | handler_,
|  | void * | userData_
| ) |  |
| inline virtual

Set a handler to be called if the Store needs to resize in order to keep storing messages.

Resize could be caused by not being connected to the server, publishing messages faster than the network or AMPS can keep up, not properly discarding messages when receiving persisted acks, or AMPS being unable to complete persistence such as when its connection to a sync replication destination is unavailable.

Parameters

  handler_ | The handler to be called when a resize event is required.
  userData_ | The data to pass to the handler each time it is called.

Reimplemented from AMPS::StoreImpl.

## ◆ store()

amps_uint64_t AMPS::HybridPublishStore::store | ( | const Message & | message_ | ) |
| inline virtual

Used internally by Client to put messages into the Store.

Parameters

  message_ | The Message to be stored.

Implements AMPS::StoreImpl.

## ◆ unpersistedCount()

size_t AMPS::HybridPublishStore::unpersistedCount | ( |  | ) | const
| inline virtual

The number of messages in the Store that have not been discarded.

Returns
  The number of messages still in the Store.

Implements AMPS::StoreImpl.

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

- include/amps/HybridPublishStore.hpp