PersistentEntitySegment.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package MemoryX::Core
17 * @author Alexey Kozlov ( kozlov at kit dot edu)
18 * @date 2013
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
26 
27 #include <MemoryX/interface/core/MemoryInterface.h>
28 #include <MemoryX/interface/components/CommonStorageInterface.h>
29 
30 #include <mutex>
31 
32 namespace memoryx
33 {
34  class MongoSerializer;
36 
108  public virtual PersistentEntitySegmentBase,
109  public virtual SegmentUtilImplementations
110  {
111  public:
112  PersistentEntitySegment(CollectionInterfacePrx entityCollection, Ice::CommunicatorPtr ic, bool useMongoIds = true);
113  ~PersistentEntitySegment() override;
114 
115  NameList getReadCollectionsNS(const ::Ice::Current& = Ice::emptyCurrent) const override;
116  void clearReadCollections(const ::Ice::Current& = Ice::emptyCurrent) override;
117  void addReadCollection(const CollectionInterfacePrx& coll, const ::Ice::Current& = Ice::emptyCurrent) override;
118  std::string getWriteCollectionNS(const ::Ice::Current& = Ice::emptyCurrent) const override;
119  void setWriteCollection(const CollectionInterfacePrx& coll, const ::Ice::Current& = Ice::emptyCurrent) override;
120  void setSingleRWCollection(const CollectionInterfacePrx& coll, const ::Ice::Current& = Ice::emptyCurrent) override;
121 
122  std::string getObjectTypeId(const ::Ice::Current& = Ice::emptyCurrent) const override;
123 
129  std::string addEntity(const EntityBasePtr& entity, const ::Ice::Current& c = Ice::emptyCurrent) override;
130  virtual std::string addEntityThreadUnsafe(const EntityBasePtr& entity);
131  std::string upsertEntity(const std::string& entityId, const EntityBasePtr& entity, const ::Ice::Current& = Ice::emptyCurrent) override;
132  virtual std::string upsertEntityThreadUnsafe(const std::string& entityId, const EntityBasePtr& entity);
133  std::string upsertEntityByName(const std::string& entityName, const EntityBasePtr& entity, const ::Ice::Current& = Ice::emptyCurrent) override;
134  virtual std::string upsertEntityByNameThreadUnsafe(const std::string& entityName, const EntityBasePtr& entity);
139  EntityIdList addEntityList(const EntityBaseList& entityList, const Ice::Current& = Ice::emptyCurrent) override;
140  virtual EntityIdList addEntityListThreadUnsafe(const EntityBaseList& entityList);
141 
142  EntityIdList upsertEntityList(const EntityBaseList& entityList, const Ice::Current& = Ice::emptyCurrent) override;
143  virtual EntityIdList upsertEntityListThreadUnsafe(const EntityBaseList& entityList);
144 
145  void updateEntity(const ::std::string& entityId, const EntityBasePtr& update, const ::Ice::Current& = Ice::emptyCurrent) override;
146  virtual void updateEntityThreadUnsafe(const ::std::string& entityId, const EntityBasePtr& update);
147 
152  void removeEntity(const ::std::string& entityId, const ::Ice::Current& = Ice::emptyCurrent) override;
153  virtual void removeEntityThreadUnsafe(const ::std::string& entityId);
158  void removeAllEntities(const ::Ice::Current& c = Ice::emptyCurrent) override;
159 
160  bool hasEntityById(const std::string& entityId, const Ice::Current& = Ice::emptyCurrent) const override;
161  bool hasEntityByIdThreadUnsafe(const std::string& entityId) const;
162  bool hasEntityByName(const std::string& entityName, const Ice::Current& = Ice::emptyCurrent) const override;
163  bool hasEntityByNameThreadUnsafe(const std::string& entityName) const;
164 
165  EntityBasePtr getEntityById(const ::std::string& entityId, const ::Ice::Current& = Ice::emptyCurrent) const override;
166  virtual EntityBasePtr getEntityByIdThreadUnsafe(const ::std::string& entityId) const;
167  EntityBasePtr getEntityByName(const ::std::string& name, const ::Ice::Current& = Ice::emptyCurrent) const override;
168  virtual EntityBasePtr getEntityByNameThreadUnsafe(const ::std::string& name) const;
169  EntityBaseList getEntitiesByAttrValue(const ::std::string& attrName, const ::std::string& attrValue, const ::Ice::Current& = Ice::emptyCurrent) const override;
170  EntityBaseList getEntitiesByAttrValueList(const ::std::string& attrName, const NameList& attrValueList, const ::Ice::Current& = Ice::emptyCurrent) const override;
171  EntityIdList getAllEntityIds(const ::Ice::Current& = Ice::emptyCurrent) const override;
172  virtual EntityIdList getAllEntityIdsThreadUnsafe() const;
177  EntityBaseList getAllEntities(const ::Ice::Current& = Ice::emptyCurrent) const override;
178  IdEntityMap getIdEntityMap(const ::Ice::Current& = Ice::emptyCurrent) const override;
179 
184  Ice::Int size(const ::Ice::Current& = Ice::emptyCurrent) const override;
185  void print(const ::Ice::Current& = Ice::emptyCurrent) const override;
189  void clear(const ::Ice::Current& = Ice::emptyCurrent) override;
190 
191  ::Ice::Identity getIceId(const ::Ice::Current& = Ice::emptyCurrent) const override;
192  std::string getSegmentName(const ::Ice::Current& = Ice::emptyCurrent) const override;
193 
194  // EntityMemorySegmentInterface interface
195  public:
196  EntityRefBasePtr getEntityRefById(const std::string& id, const Ice::Current&) const override;
197  EntityRefBasePtr getEntityRefByName(const std::string& name, const Ice::Current& c) const override;
198 
199  void setEntityAttribute(const std::string& entityId, const EntityAttributeBasePtr& attribute, const Ice::Current&) override;
200  void setEntityAttributes(const std::string& entityId, const EntityAttributeList& attributeMap, const Ice::Current&) override;
201 
202  // AbstractMemorySegment interface
203  public:
204  void setParentMemory(const MemoryInterfacePtr& memory, const Ice::Current&) override;
205 
206  // PersistentEntitySegmentBase interface
207  public:
215  EntityRefList findRefsByQuery(const std::string& query, const Ice::Current& c) override;
216 
217  protected:
218  // set segment name
219  void setSegmentName(const std::string& segmentName, const ::Ice::Current& = Ice::emptyCurrent) override;
220 
221  MemoryInterfacePtr parentMemory;
222 
223  CollectionPrxList readCollections;
224  // mutable boost::mutex readCollectionsMutex;
225 
226  CollectionInterfacePrx writeCollection;
228  mutable std::recursive_mutex dbSerializerMutex;
229 
231 
232  EntityBasePtr deserializeEntity(const DBStorableData& dbEntity) const;
233  std::string segmentName;
234 
235 
236  };
237 
238 
240 
241 }
242 
memoryx::PersistentEntitySegment::setSingleRWCollection
void setSingleRWCollection(const CollectionInterfacePrx &coll, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PersistentEntitySegment.cpp:123
memoryx::PersistentEntitySegment::getReadCollectionsNS
NameList getReadCollectionsNS(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:53
memoryx::PersistentEntitySegment::getIdEntityMap
IdEntityMap getIdEntityMap(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:580
memoryx::PersistentEntitySegment::addEntityList
EntityIdList addEntityList(const EntityBaseList &entityList, const Ice::Current &=Ice::emptyCurrent) override
addEntityList adds all entities contained in \entityList to this segment and returns a list of create...
Definition: PersistentEntitySegment.cpp:221
memoryx::PersistentEntitySegment::findRefsByQuery
EntityRefList findRefsByQuery(const std::string &query, const Ice::Current &c) override
retrieves Entity Refs that match the query.
Definition: PersistentEntitySegment.cpp:702
cyberglove_with_calib_22dof.ic
ic
Definition: cyberglove_with_calib_22dof.py:22
memoryx::PersistentEntitySegment::setEntityAttributes
void setEntityAttributes(const std::string &entityId, const EntityAttributeList &attributeMap, const Ice::Current &) override
Definition: PersistentEntitySegment.cpp:674
memoryx::PersistentEntitySegment::updateEntity
void updateEntity(const ::std::string &entityId, const EntityBasePtr &update, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PersistentEntitySegment.cpp:244
memoryx::PersistentEntitySegment::dbSerializerMutex
std::recursive_mutex dbSerializerMutex
Definition: PersistentEntitySegment.h:228
memoryx::PersistentEntitySegment::setWriteCollection
void setWriteCollection(const CollectionInterfacePrx &coll, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PersistentEntitySegment.cpp:115
memoryx::PersistentEntitySegment::parentMemory
MemoryInterfacePtr parentMemory
Definition: PersistentEntitySegment.h:221
memoryx::PersistentEntitySegment::setParentMemory
void setParentMemory(const MemoryInterfacePtr &memory, const Ice::Current &) override
Definition: PersistentEntitySegment.cpp:697
memoryx::PersistentEntitySegment::updateEntityThreadUnsafe
virtual void updateEntityThreadUnsafe(const ::std::string &entityId, const EntityBasePtr &update)
Definition: PersistentEntitySegment.cpp:250
memoryx::PersistentEntitySegment::print
void print(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:507
memoryx::PersistentEntitySegment::addEntity
std::string addEntity(const EntityBasePtr &entity, const ::Ice::Current &c=Ice::emptyCurrent) override
addEntity add new entity and return the newly generated entity ID
Definition: PersistentEntitySegment.cpp:135
memoryx::PersistentEntitySegment::getEntityRefByName
EntityRefBasePtr getEntityRefByName(const std::string &name, const Ice::Current &c) const override
Definition: PersistentEntitySegment.cpp:633
memoryx::SegmentUtilImplementations
Definition: SegmentUtilImplementations.h:54
memoryx::PersistentEntitySegment::removeAllEntities
void removeAllEntities(const ::Ice::Current &c=Ice::emptyCurrent) override
removeAllEntities collects all entities managed by this memory segment and removes them from the segm...
Definition: PersistentEntitySegment.cpp:283
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::PersistentEntitySegment::getObjectTypeId
std::string getObjectTypeId(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:130
memoryx::PersistentEntitySegment::removeEntityThreadUnsafe
virtual void removeEntityThreadUnsafe(const ::std::string &entityId)
Definition: PersistentEntitySegment.cpp:270
memoryx::PersistentEntitySegment::size
Ice::Int size(const ::Ice::Current &=Ice::emptyCurrent) const override
size counts the number of memoryx::Entity instances contained available reachable throuhg memoryx::Pe...
Definition: PersistentEntitySegment.cpp:489
memoryx::PersistentEntitySegment::getSegmentName
std::string getSegmentName(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:525
memoryx::PersistentEntitySegment::addEntityThreadUnsafe
virtual std::string addEntityThreadUnsafe(const EntityBasePtr &entity)
Definition: PersistentEntitySegment.cpp:142
memoryx::PersistentEntitySegment::setSegmentName
void setSegmentName(const std::string &segmentName, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PersistentEntitySegment.cpp:741
memoryx::PersistentEntitySegment::getAllEntities
EntityBaseList getAllEntities(const ::Ice::Current &=Ice::emptyCurrent) const override
getAllEntities returns a list of all entities managed by this memory segment
Definition: PersistentEntitySegment.cpp:554
memoryx::PersistentEntitySegment::~PersistentEntitySegment
~PersistentEntitySegment() override
Definition: PersistentEntitySegment.cpp:49
memoryx::PersistentEntitySegment::getAllEntityIdsThreadUnsafe
virtual EntityIdList getAllEntityIdsThreadUnsafe() const
Definition: PersistentEntitySegment.cpp:536
memoryx::PersistentEntitySegment::writeCollection
CollectionInterfacePrx writeCollection
Definition: PersistentEntitySegment.h:226
IceInternal::Handle< ::Ice::Communicator >
memoryx::PersistentEntitySegment::upsertEntityByNameThreadUnsafe
virtual std::string upsertEntityByNameThreadUnsafe(const std::string &entityName, const EntityBasePtr &entity)
Definition: PersistentEntitySegment.cpp:205
memoryx::PersistentEntitySegment::PersistentEntitySegment
PersistentEntitySegment(CollectionInterfacePrx entityCollection, Ice::CommunicatorPtr ic, bool useMongoIds=true)
Definition: PersistentEntitySegment.cpp:41
memoryx::PersistentEntitySegment::getEntityByNameThreadUnsafe
virtual EntityBasePtr getEntityByNameThreadUnsafe(const ::std::string &name) const
Definition: PersistentEntitySegment.cpp:406
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
memoryx::PersistentEntitySegment::getEntityById
EntityBasePtr getEntityById(const ::std::string &entityId, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:363
memoryx::PersistentEntitySegment::getEntityByName
EntityBasePtr getEntityByName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:399
memoryx::PersistentEntitySegment::getEntityRefById
EntityRefBasePtr getEntityRefById(const std::string &id, const Ice::Current &) const override
Definition: PersistentEntitySegment.cpp:612
memoryx::PersistentEntitySegment::deserializeEntity
EntityBasePtr deserializeEntity(const DBStorableData &dbEntity) const
Definition: PersistentEntitySegment.cpp:592
SegmentUtilImplementations.h
memoryx::PersistentEntitySegment::upsertEntityListThreadUnsafe
virtual EntityIdList upsertEntityListThreadUnsafe(const EntityBaseList &entityList)
Definition: PersistentEntitySegment.cpp:179
memoryx::PersistentEntitySegment::addReadCollection
void addReadCollection(const CollectionInterfacePrx &coll, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PersistentEntitySegment.cpp:78
memoryx::PersistentEntitySegment::getEntityByIdThreadUnsafe
virtual EntityBasePtr getEntityByIdThreadUnsafe(const ::std::string &entityId) const
Definition: PersistentEntitySegment.cpp:371
memoryx::PersistentEntitySegment::upsertEntity
std::string upsertEntity(const std::string &entityId, const EntityBasePtr &entity, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PersistentEntitySegment.cpp:153
memoryx::PersistentEntitySegment::hasEntityByNameThreadUnsafe
bool hasEntityByNameThreadUnsafe(const std::string &entityName) const
Definition: PersistentEntitySegment.cpp:340
memoryx::PersistentEntitySegment::setEntityAttribute
void setEntityAttribute(const std::string &entityId, const EntityAttributeBasePtr &attribute, const Ice::Current &) override
Definition: PersistentEntitySegment.cpp:656
memoryx::PersistentEntitySegment::hasEntityByIdThreadUnsafe
bool hasEntityByIdThreadUnsafe(const std::string &entityId) const
Definition: PersistentEntitySegment.cpp:301
memoryx::PersistentEntitySegment::upsertEntityList
EntityIdList upsertEntityList(const EntityBaseList &entityList, const Ice::Current &=Ice::emptyCurrent) override
Definition: PersistentEntitySegment.cpp:173
memoryx::PersistentEntitySegment::getIceId
::Ice::Identity getIceId(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:518
memoryx::PersistentEntitySegment::addEntityListThreadUnsafe
virtual EntityIdList addEntityListThreadUnsafe(const EntityBaseList &entityList)
Definition: PersistentEntitySegment.cpp:227
memoryx::PersistentEntitySegment::getEntitiesByAttrValue
EntityBaseList getEntitiesByAttrValue(const ::std::string &attrName, const ::std::string &attrValue, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:427
memoryx::PersistentEntitySegment::clear
void clear(const ::Ice::Current &=Ice::emptyCurrent) override
clear removes all elements from the current memoryx::PersistentEntitySegment::writeCollection
Definition: PersistentEntitySegment.cpp:513
memoryx::PersistentEntitySegment::useMongoIds
bool useMongoIds
Definition: PersistentEntitySegment.h:230
memoryx::PersistentEntitySegment::removeEntity
void removeEntity(const ::std::string &entityId, const ::Ice::Current &=Ice::emptyCurrent) override
removeEntity removes an entity with the ID entityId
Definition: PersistentEntitySegment.cpp:263
memoryx::PersistentEntitySegment::hasEntityByName
bool hasEntityByName(const std::string &entityName, const Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:334
memoryx::PersistentEntitySegment::upsertEntityByName
std::string upsertEntityByName(const std::string &entityName, const EntityBasePtr &entity, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PersistentEntitySegment.cpp:199
IceUtil::Handle< MongoSerializer >
memoryx::PersistentEntitySegment::clearReadCollections
void clearReadCollections(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: PersistentEntitySegment.cpp:71
memoryx::PersistentEntitySegment
The PersistentEntitySegment class is the base class for all memory segments containing memoryx::Entit...
Definition: PersistentEntitySegment.h:107
memoryx::MongoSerializerPtr
IceUtil::Handle< MongoSerializer > MongoSerializerPtr
Definition: EntityRef.h:40
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
memoryx::PersistentEntitySegment::getAllEntityIds
EntityIdList getAllEntityIds(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:530
memoryx::PersistentEntitySegment::getEntitiesByAttrValueList
EntityBaseList getEntitiesByAttrValueList(const ::std::string &attrName, const NameList &attrValueList, const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:457
memoryx::PersistentEntitySegment::upsertEntityThreadUnsafe
virtual std::string upsertEntityThreadUnsafe(const std::string &entityId, const EntityBasePtr &entity)
Definition: PersistentEntitySegment.cpp:159
memoryx::PersistentEntitySegment::readCollections
CollectionPrxList readCollections
Definition: PersistentEntitySegment.h:223
memoryx::PersistentEntitySegment::dbSerializer
MongoSerializerPtr dbSerializer
Definition: PersistentEntitySegment.h:227
memoryx::PersistentEntitySegment::hasEntityById
bool hasEntityById(const std::string &entityId, const Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:295
memoryx::PersistentEntitySegment::segmentName
std::string segmentName
Definition: PersistentEntitySegment.h:233
memoryx::PersistentEntitySegment::getWriteCollectionNS
std::string getWriteCollectionNS(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: PersistentEntitySegment.cpp:110