Memory.h
Go to the documentation of this file.
1#pragma once
2
3#include <list>
4
5// Base Class
6#include "detail/MemoryBase.h"
9
10// Persistence
13
14// Segmnet Type
15#include "CoreSegment.h"
16
18{
19 /// @brief A memory storing data on the hard drive and in mongodb (needs 'armarx memory start' to start the mongod instance)
20 class Memory :
21 public detail::MemoryBase<CoreSegment>,
22 public detail::mixin::BufferedMemoryMixin<CoreSegment>,
23 public detail::mixin::CachedMemoryMixin<CoreSegment>
24 {
25 public:
29
30 Memory();
31
32 Memory(const std::string& exportName, const std::string& memoryName);
33
34 Memory(
35 const std::string& exportName,
36 const std::string& memoryName,
37 const std::shared_ptr<persistence::RedundantPersistenceStrategy>& persistenceStrategy);
38
39 void _setExportName(const std::string& memoryName) final;
40 void _setMemoryID(const MemoryID& memoryId) final;
41 void _enable() final;
42 void _disable() final;
43 void _configure(const nlohmann::json& config) final;
44
46 const std::string& prefix) override;
47
48 /**
49 * @brief getAndSaveStatistics generates and saves statistics for a LTM recording
50 */
52
53 /**
54 * @brief Flush the async storage queue and wait for all pending items to be stored.
55 * This blocks until the queue is empty and all storage operations are complete.
56 * @param timeoutMs Maximum time to wait in milliseconds (0 = wait indefinitely)
57 * @return true if queue was flushed successfully, false if timeout occurred
58 */
59 bool flushAsyncStorage(int timeoutMs = 0)
60 {
61 return BufferedBase::flushAsyncStorage(timeoutMs);
62 }
63
64 /**
65 * @brief Get the current size of the async storage queue
66 */
67 size_t getAsyncQueueSize() const
68 {
70 }
71
72 /**
73 * @brief Get the async storage statistics
74 */
79
80 /**
81 * @brief Get the number of threads currently processing items
82 */
87
88 void
90 std::shared_ptr<persistence::RedundantPersistenceStrategy> persistenceStrategy)
91 {
92 persistenceStrategy_ = persistenceStrategy;
93 }
94
95 std::shared_ptr<persistence::RedundantPersistenceStrategy>
97 {
98 return persistenceStrategy_;
99 }
100
101 protected:
102 // Implementation methods
103 bool _implForEachCoreSegment(std::function<void(CoreSegment&)> func) const final;
104 bool _implHasCoreSegment(const std::string& coreSegmentName) const final;
105 std::shared_ptr<CoreSegment> _implFindCoreSegment(const std::string& coreSegmentName) const final;
106
107 void _loadAllReferences(armem::wm::Memory& wmMemory) final;
109 std::list<std::string> coreSegNames) final;
110 void _loadLatestNReferences(int n, armem::wm::Memory& wmMemory) final;
111 void _loadLatestNReferences(int n,
112 armem::wm::Memory& wmMemory,
113 std::list<std::string> coreSegNames) final;
114 void _resolve(armem::wm::Memory& wmMemory) final;
115 void _store(const armem::wm::Memory& wmMemory) final;
116 void _directlyStore(const armem::wm::Memory& wmMemory, bool simulatedVersion) final;
117 std::shared_ptr<armem::wm::Memory> _preFilterMemory(
119 uint64_t& filteredCount,
120 uint64_t& passedCount) final;
121 void _loadOnStartup() final;
122 void _enqueueForAsyncStorage(std::shared_ptr<const armem::wm::Memory> memory) final;
123 void _enqueuePendingConversion(detail::mixin::PendingConversion pending) final;
124
125 private:
126 std::time_t current_date;
127
128 std::shared_ptr<persistence::RedundantPersistenceStrategy> persistenceStrategy_;
129
130 std::vector<std::string> split(std::string str, char delimiter);
131 };
132} // namespace armarx::armem::server::ltm
std::string str(const T &t)
A memory storing data on the hard drive and in mongodb (needs 'armarx memory start' to start the mong...
Definition Memory.h:24
void getAndSaveStatistics()
getAndSaveStatistics generates and saves statistics for a LTM recording
Definition Memory.cpp:573
void _setMemoryID(const MemoryID &memoryId) final
Definition Memory.cpp:176
void _enqueueForAsyncStorage(std::shared_ptr< const armem::wm::Memory > memory) final
Definition Memory.cpp:557
void _resolve(armem::wm::Memory &wmMemory) final
Definition Memory.cpp:399
const detail::mixin::AsyncStorageStatistics & getAsyncStorageStatistics() const
Get the async storage statistics.
Definition Memory.h:75
detail::mixin::BufferedMemoryMixin< CoreSegment > BufferedBase
Definition Memory.h:27
detail::mixin::CachedMemoryMixin< CoreSegment > CachedBase
Definition Memory.h:28
void _loadLatestNReferences(int n, armem::wm::Memory &wmMemory) final
Definition Memory.cpp:325
void _directlyStore(const armem::wm::Memory &wmMemory, bool simulatedVersion) final
Definition Memory.cpp:429
void _setExportName(const std::string &memoryName) final
Definition Memory.cpp:147
bool _implHasCoreSegment(const std::string &coreSegmentName) const final
Definition Memory.cpp:214
bool _implForEachCoreSegment(std::function< void(CoreSegment &)> func) const final
Definition Memory.cpp:188
std::shared_ptr< armem::wm::Memory > _preFilterMemory(const armem::wm::Memory &memory, uint64_t &filteredCount, uint64_t &passedCount) final
Pre-filter a memory object before enqueuing for async storage.
Definition Memory.cpp:470
size_t getNumThreadsProcessing() const
Get the number of threads currently processing items.
Definition Memory.h:83
void setPersistenceStrategy(std::shared_ptr< persistence::RedundantPersistenceStrategy > persistenceStrategy)
Definition Memory.h:89
std::shared_ptr< CoreSegment > _implFindCoreSegment(const std::string &coreSegmentName) const final
Definition Memory.cpp:225
size_t getAsyncQueueSize() const
Get the current size of the async storage queue.
Definition Memory.h:67
std::shared_ptr< persistence::RedundantPersistenceStrategy > getPersistenceStrategy() const
Definition Memory.h:96
bool flushAsyncStorage(int timeoutMs=0)
Flush the async storage queue and wait for all pending items to be stored.
Definition Memory.h:59
void _loadAllReferences(armem::wm::Memory &wmMemory) final
Definition Memory.cpp:253
void _store(const armem::wm::Memory &wmMemory) final
Definition Memory.cpp:422
void createPropertyDefinitions(PropertyDefinitionsPtr &defs, const std::string &prefix) override
default parameters. Implementation should use the configuration to configure
Definition Memory.cpp:244
void _configure(const nlohmann::json &config) final
configuration
Definition Memory.cpp:18
void _enqueuePendingConversion(detail::mixin::PendingConversion pending) final
Definition Memory.cpp:565
detail::MemoryBase< CoreSegment > MemoryBase
Definition Memory.h:26
Interface functions for the longterm memory classes.
Definition MemoryBase.h:50
Client-side working memory.
Brief description of class memory.
Definition memory.h:39
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.