BufferedMemoryMixin< _CoreSegmentT > Class Template Referenceabstract

#include <RobotAPI/libraries/armem/server/ltm/detail/mixins/BufferedMemoryMixin.h>

Public Types

using StorageItem = std::variant<std::shared_ptr<const armem::wm::Memory>, PendingConversion>
 Can hold either pre-converted Memory or pending conversion data.
 

Public Member Functions

 BufferedMemoryMixin (const MemoryID &id)
 
void bufferFinished ()
 
void directlyStore (const armem::server::wm::Memory &serverMemory, bool simulatedVersion=false)
 
void directlyStore (const armem::wm::Memory &memory, bool simulatedVersion=false)
 
bool flushAsyncStorage (int timeoutMs=0)
 Flush the async storage queue and wait for all pending items to be stored.
 
const AsyncStorageStatisticsgetAsyncStorageStatistics () const
 Get the async storage statistics.
 
size_t getNumThreadsProcessing () const
 Get the number of threads currently processing items.
 
size_t getQueueSize () const
 Get the current size of the async storage queue.
 
void resetAsyncStorageStatistics ()
 Reset the async storage statistics.
 
virtual ~BufferedMemoryMixin ()
 

Protected Member Functions

virtual void _directlyStore (const armem::wm::Memory &memory, bool simulatedVersion=false)=0
 
virtual std::shared_ptr< armem::wm::Memory_preFilterMemory (const armem::wm::Memory &memory, uint64_t &filteredCount, uint64_t &passedCount)=0
 Pre-filter a memory object before enqueuing for async storage.
 
void addToBuffer (const armem::wm::Memory &memory)
 
void asyncStorageWorker (size_t threadId)
 Worker thread that processes the async storage queue.
 
void configureMixin (const nlohmann::json &json)
 configuration
 
size_t countSnapshotsInItem (const StorageItem &item) const
 Count the number of snapshots in a storage item.
 
void createPropertyDefinitions (PropertyDefinitionsPtr &defs, const std::string &prefix)
 
void enqueueForAsyncStorage (std::shared_ptr< const armem::wm::Memory > memory)
 Enqueue a memory object for async storage.
 
void enqueueForAsyncStoragePublic (std::shared_ptr< const armem::wm::Memory > memory)
 Public interface to enqueue memory for async storage This allows MemoryBase::store() to use the async thread pool.
 
void enqueuePendingConversion (PendingConversion pending)
 Enqueue snapshots for deferred conversion and async storage This defers the expensive toMemory() conversion to the async thread.
 
void enqueueStorageItem (StorageItem item)
 Internal method to enqueue any storage item (Memory or PendingConversion) PERFORMANCE: Uses lock-free queue to avoid mutex contention at 50Hz commit rate NON-BLOCKING: If the queue is full, the item is DROPPED immediately to prevent upstream queue (e.g., RobotWriterQueue) from backing up.
 
armem::wm::Memory getBuffer () const
 
void setMixinMemoryID (const MemoryID &id)
 
void start ()
 
void stop ()
 
void storeBuffer ()
 

Protected Attributes

std::unique_ptr< armem::wm::Memorybuffer
 Internal memory for data consolidated from wm to ltm (double-buffer) The to-put-to-ltm buffer (contains data in plain text) This buffer may still be filtered (e.g.
 
size_t maxAsyncQueueSize = 1000
 Maximum size of the async storage queue (default 100 items)
 
size_t numAsyncStorageThreads = 4
 Number of worker threads for async storage (default 4)
 
std::atomic_flag storeFlag = ATOMIC_FLAG_INIT
 
float storeFrequency = 10
 The frequency (Hz) to store data to the ltm.
 
std::unique_ptr< armem::wm::Memoryto_store
 
int workerShutdownTimeoutSeconds = 30
 Timeout in seconds for worker thread shutdown (default 30 seconds)
 

Detailed Description

template<class _CoreSegmentT>
class armarx::armem::server::ltm::detail::mixin::BufferedMemoryMixin< _CoreSegmentT >

Definition at line 127 of file BufferedMemoryMixin.h.

Member Typedef Documentation

◆ StorageItem

template<class _CoreSegmentT>
using StorageItem = std::variant<std::shared_ptr<const armem::wm::Memory>, PendingConversion>

Can hold either pre-converted Memory or pending conversion data.

Definition at line 131 of file BufferedMemoryMixin.h.

Constructor & Destructor Documentation

◆ BufferedMemoryMixin()

template<class _CoreSegmentT>
BufferedMemoryMixin ( const MemoryID & id)
inline

Definition at line 133 of file BufferedMemoryMixin.h.

◆ ~BufferedMemoryMixin()

template<class _CoreSegmentT>
virtual ~BufferedMemoryMixin ( )
inlinevirtual

Definition at line 142 of file BufferedMemoryMixin.h.

Member Function Documentation

◆ _directlyStore()

template<class _CoreSegmentT>
virtual void _directlyStore ( const armem::wm::Memory & memory,
bool simulatedVersion = false )
protectedpure virtual

Implemented in Memory.

+ Here is the caller graph for this function:

◆ _preFilterMemory()

template<class _CoreSegmentT>
virtual std::shared_ptr< armem::wm::Memory > _preFilterMemory ( const armem::wm::Memory & memory,
uint64_t & filteredCount,
uint64_t & passedCount )
protectedpure virtual

Pre-filter a memory object before enqueuing for async storage.

This method applies snapshot filters BEFORE the memory enters the async queue, reducing queue pressure and avoiding work on the async worker threads.

Parameters
memoryThe memory to filter
filteredCountOutput: number of snapshots that were filtered out
passedCountOutput: number of snapshots that passed the filter
Returns
A new memory containing only the snapshots that passed the filters, or nullptr if all snapshots were filtered out

Implemented in Memory.

+ Here is the caller graph for this function:

◆ addToBuffer()

template<class _CoreSegmentT>
void addToBuffer ( const armem::wm::Memory & memory)
inlineprotected

Definition at line 413 of file BufferedMemoryMixin.h.

◆ asyncStorageWorker()

template<class _CoreSegmentT>
void asyncStorageWorker ( size_t threadId)
inlineprotected

Worker thread that processes the async storage queue.

Parameters
threadIdID of this worker thread (for logging)

Definition at line 641 of file BufferedMemoryMixin.h.

◆ bufferFinished()

template<class _CoreSegmentT>
void bufferFinished ( )
inline

Definition at line 180 of file BufferedMemoryMixin.h.

◆ configureMixin()

template<class _CoreSegmentT>
void configureMixin ( const nlohmann::json & json)
inlineprotected

configuration

Definition at line 355 of file BufferedMemoryMixin.h.

◆ countSnapshotsInItem()

template<class _CoreSegmentT>
size_t countSnapshotsInItem ( const StorageItem & item) const
inlineprotected

Count the number of snapshots in a storage item.

Definition at line 613 of file BufferedMemoryMixin.h.

+ Here is the caller graph for this function:

◆ createPropertyDefinitions()

template<class _CoreSegmentT>
void createPropertyDefinitions ( PropertyDefinitionsPtr & defs,
const std::string & prefix )
inlineprotected

Definition at line 384 of file BufferedMemoryMixin.h.

◆ directlyStore() [1/2]

template<class _CoreSegmentT>
void directlyStore ( const armem::server::wm::Memory & serverMemory,
bool simulatedVersion = false )
inline

Definition at line 170 of file BufferedMemoryMixin.h.

◆ directlyStore() [2/2]

template<class _CoreSegmentT>
void directlyStore ( const armem::wm::Memory & memory,
bool simulatedVersion = false )
inline

Definition at line 155 of file BufferedMemoryMixin.h.

+ Here is the caller graph for this function:

◆ enqueueForAsyncStorage()

template<class _CoreSegmentT>
void enqueueForAsyncStorage ( std::shared_ptr< const armem::wm::Memory > memory)
inlineprotected

Enqueue a memory object for async storage.

Definition at line 434 of file BufferedMemoryMixin.h.

+ Here is the caller graph for this function:

◆ enqueueForAsyncStoragePublic()

template<class _CoreSegmentT>
void enqueueForAsyncStoragePublic ( std::shared_ptr< const armem::wm::Memory > memory)
inlineprotected

Public interface to enqueue memory for async storage This allows MemoryBase::store() to use the async thread pool.

Definition at line 424 of file BufferedMemoryMixin.h.

◆ enqueuePendingConversion()

template<class _CoreSegmentT>
void enqueuePendingConversion ( PendingConversion pending)
inlineprotected

Enqueue snapshots for deferred conversion and async storage This defers the expensive toMemory() conversion to the async thread.

Definition at line 444 of file BufferedMemoryMixin.h.

◆ enqueueStorageItem()

template<class _CoreSegmentT>
void enqueueStorageItem ( StorageItem item)
inlineprotected

Internal method to enqueue any storage item (Memory or PendingConversion) PERFORMANCE: Uses lock-free queue to avoid mutex contention at 50Hz commit rate NON-BLOCKING: If the queue is full, the item is DROPPED immediately to prevent upstream queue (e.g., RobotWriterQueue) from backing up.

Definition at line 559 of file BufferedMemoryMixin.h.

+ Here is the caller graph for this function:

◆ flushAsyncStorage()

template<class _CoreSegmentT>
bool flushAsyncStorage ( int timeoutMs = 0)
inline

Flush the async storage queue and wait for all pending items to be stored.

This blocks until the queue is empty and all storage operations are complete.

Parameters
timeoutMsMaximum time to wait in milliseconds (0 = wait indefinitely)
Returns
true if queue was flushed successfully, false if timeout occurred

Definition at line 192 of file BufferedMemoryMixin.h.

◆ getAsyncStorageStatistics()

template<class _CoreSegmentT>
const AsyncStorageStatistics & getAsyncStorageStatistics ( ) const
inline

Get the async storage statistics.

Definition at line 238 of file BufferedMemoryMixin.h.

◆ getBuffer()

template<class _CoreSegmentT>
armem::wm::Memory getBuffer ( ) const
inlineprotected

Definition at line 303 of file BufferedMemoryMixin.h.

◆ getNumThreadsProcessing()

template<class _CoreSegmentT>
size_t getNumThreadsProcessing ( ) const
inline

Get the number of threads currently processing items.

Definition at line 256 of file BufferedMemoryMixin.h.

◆ getQueueSize()

template<class _CoreSegmentT>
size_t getQueueSize ( ) const
inline

Get the current size of the async storage queue.

Definition at line 229 of file BufferedMemoryMixin.h.

+ Here is the caller graph for this function:

◆ resetAsyncStorageStatistics()

template<class _CoreSegmentT>
void resetAsyncStorageStatistics ( )
inline

Reset the async storage statistics.

Definition at line 247 of file BufferedMemoryMixin.h.

◆ setMixinMemoryID()

template<class _CoreSegmentT>
void setMixinMemoryID ( const MemoryID & id)
inlineprotected

Definition at line 263 of file BufferedMemoryMixin.h.

◆ start()

template<class _CoreSegmentT>
void start ( )
inlineprotected

Definition at line 272 of file BufferedMemoryMixin.h.

◆ stop()

template<class _CoreSegmentT>
void stop ( )
inlineprotected

Definition at line 290 of file BufferedMemoryMixin.h.

◆ storeBuffer()

template<class _CoreSegmentT>
void storeBuffer ( )
inlineprotected

Definition at line 310 of file BufferedMemoryMixin.h.

+ Here is the caller graph for this function:

Member Data Documentation

◆ buffer

template<class _CoreSegmentT>
std::unique_ptr<armem::wm::Memory> buffer
protected

Internal memory for data consolidated from wm to ltm (double-buffer) The to-put-to-ltm buffer (contains data in plain text) This buffer may still be filtered (e.g.

snapshot filters). This means that it is not guaranteed that all data in the buffer will be stored in the ltm

Definition at line 868 of file BufferedMemoryMixin.h.

◆ maxAsyncQueueSize

template<class _CoreSegmentT>
size_t maxAsyncQueueSize = 1000
protected

Maximum size of the async storage queue (default 100 items)

Definition at line 876 of file BufferedMemoryMixin.h.

◆ numAsyncStorageThreads

template<class _CoreSegmentT>
size_t numAsyncStorageThreads = 4
protected

Number of worker threads for async storage (default 4)

Definition at line 879 of file BufferedMemoryMixin.h.

◆ storeFlag

template<class _CoreSegmentT>
std::atomic_flag storeFlag = ATOMIC_FLAG_INIT
protected

Definition at line 870 of file BufferedMemoryMixin.h.

◆ storeFrequency

template<class _CoreSegmentT>
float storeFrequency = 10
protected

The frequency (Hz) to store data to the ltm.

Definition at line 873 of file BufferedMemoryMixin.h.

◆ to_store

template<class _CoreSegmentT>
std::unique_ptr<armem::wm::Memory> to_store
protected

Definition at line 869 of file BufferedMemoryMixin.h.

◆ workerShutdownTimeoutSeconds

template<class _CoreSegmentT>
int workerShutdownTimeoutSeconds = 30
protected

Timeout in seconds for worker thread shutdown (default 30 seconds)

Definition at line 882 of file BufferedMemoryMixin.h.


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