16 const std::string& exportName,
18 const std::shared_ptr<Processors>&
filters,
19 const std::shared_ptr<persistence::MemoryPersistenceStrategy>& persistenceStrategy) :
20 ProviderSegmentBase(exportName, memoryId,
filters),
21 persistenceStrategy_(persistenceStrategy)
33 for (std::string& entityName : persistenceStrategy_->getContainerKeys(
id()))
37 std::shared_ptr<persistence::MemoryPersistenceStrategy> entityPersistenceStrategy(
38 persistenceStrategy_);
41 id().withEntityName(entityName),
43 entityPersistenceStrategy);
56 return persistenceStrategy_->containsContainer(
id(), entityName);
59 std::shared_ptr<Entity>
69 return std::make_shared<Entity>(
81 if (persistenceStrategy_->containsItem(
88 auto filecontent = persistenceStrategy_->retrieveItem(
90 auto aron = conv.convert(filecontent,
"");
93 catch (
const nlohmann::json::type_error& e)
95 ARMARX_WARNING <<
"You are trying to access aron data in a ProviderSegment which "
96 "is not available, skipping...";
97 wmProviderSegment.
aronType() =
nullptr;
102 [&wmProviderSegment](
auto& ltmEntity)
105 ltmEntity.loadAllReferences(wmEntity);
112 existingWmEntity.
append(wmEntity);
128 auto& conv =
processors->defaultTypeConverter;
130 if (persistenceStrategy_->containsItem(
134 auto& conv =
processors->defaultTypeConverter;
138 auto filecontent = persistenceStrategy_->retrieveItem(
140 auto aron = conv.convert(filecontent,
"");
143 catch (
const nlohmann::json::type_error& e)
146 <<
"You are trying to access aron data which is not available, skipping...";
147 wmProviderSegment.
aronType() =
nullptr;
152 [&wmProviderSegment, &n](
auto& ltmEntity)
155 ltmEntity.loadLatestNReferences(n, wmEntity);
162 existingWmEntity.
append(wmEntity);
181 std::shared_ptr<persistence::MemoryPersistenceStrategy> entityPersistenceStrategy(
182 persistenceStrategy_);
185 id().withEntityName(wmEntity.id().entityName),
187 entityPersistenceStrategy);
194 bool simulatedVersion)
198 if (
id().providerSegmentName.empty())
201 <<
"During storage of segment '" << wmProviderSegment.
id().
str()
202 <<
"' I noticed that the corresponding LTM has no id set. "
203 <<
"I set the id of the LTM to the same name, however this should not happen!";
211 auto& conv =
processors->defaultTypeConverter;
213 auto type = wmProviderSegment.
aronType();
215 auto [vec, modeSuffix] = conv.convert(type);
221 if (!persistenceStrategy_->containsItem(
id(), key))
223 persistenceStrategy_->storeItem(
id(), key, vec);
231 <<
" does not seem to have an aron type, so aron type "
232 "information connot be exported";
237 [&](
const auto& wmEntity)
239 std::shared_ptr<persistence::MemoryPersistenceStrategy> entityPersistenceStrategy(
240 persistenceStrategy_);
243 id().withEntityName(wmEntity.id().entityName),
245 entityPersistenceStrategy);
247 ltmEntity.
store(wmEntity, simulatedVersion);
#define ARMARX_CHECK_EMPTY(c)
MemoryID getProviderSegmentID() const
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
std::string providerSegmentName
void append(const OtherDerivedT &other)
bool hasEntity(const std::string &name) const
EntityT & getEntity(const std::string &name)
bool forEachEntity(EntityFunctionT &&func)
EntityT & addEntity(const std::string &name)
Add an empty entity with the given name.
aron::type::ObjectPtr & aronType()
A memory storing data in mongodb (needs 'armarx memory start' to start the mongod instance)
ProviderSegment(const std::string &exportName, const MemoryID &memoryId, const std::shared_ptr< Processors > &filters, const std::shared_ptr< persistence::MemoryPersistenceStrategy > &persistenceStrategy)
void _store(const armem::wm::ProviderSegment &wmProviderSegment, bool simulatedVersion) override
std::shared_ptr< Entity > _implFindEntity(const std::string &entityName) const override
void _loadAllReferences(armem::wm::ProviderSegment &wmProviderSegment) override
void _loadLatestNReferences(int n, armem::wm::ProviderSegment &wmProviderSegment) override
bool _implForEachEntity(std::function< void(Entity &)> func) const override
bool _implHasEntity(const std::string &entityName) const override
void _resolve(armem::wm::ProviderSegment &wmProviderSegment) override
void resolve(armem::wm::Entity &e)
convert the references of the input into a wm::Memory
void store(const armem::wm::Entity &e, bool simulatedVersion)
encode the content of a wm::Memory and store
virtual std::string getExportName() const
std::shared_ptr< Processors > processors
static const constexpr char * TYPE_FILENAME
Client-side working memory entity.
Client-side working memory provider segment.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.