// // Copyright (c) ZeroC, Inc. All rights reserved. // #ifndef ICE_GRID_ALLOCATABLEOBJECTCACHE_H #define ICE_GRID_ALLOCATABLEOBJECTCACHE_H #include #include #include #include namespace IceGrid { class AllocatableObjectCache; class ServerEntry; class AllocatableObjectEntry : public Allocatable { public: AllocatableObjectEntry(AllocatableObjectCache&, const ObjectInfo&, const std::shared_ptr&); std::shared_ptr getProxy() const; std::string getType() const; bool canRemove(); bool isEnabled() const override; void allocated(const std::shared_ptr&) override; void released(const std::shared_ptr&) override; bool canTryAllocate() override; void destroy(); void checkAllocatable() override; private: AllocatableObjectCache& _cache; const ObjectInfo _info; std::shared_ptr _server; bool _destroyed; }; class ObjectAllocationRequest : public AllocationRequest { public: ObjectAllocationRequest(const std::shared_ptr& session) : AllocationRequest(session) { } virtual void response(const std::shared_ptr&) = 0; virtual void exception(std::exception_ptr) = 0; private: void allocated(const std::shared_ptr& allocatable, const std::shared_ptr&) override { response(std::dynamic_pointer_cast(allocatable)->getProxy()); } void canceled(std::exception_ptr ex) override { exception(ex); } }; class AllocatableObjectCache : public Cache { public: AllocatableObjectCache(const std::shared_ptr&); void add(const ObjectInfo&, const std::shared_ptr&); std::shared_ptr get(const Ice::Identity&) const; void remove(const Ice::Identity&); void allocateByType(const std::string&, const std::shared_ptr&); bool canTryAllocate(const std::shared_ptr&); const std::shared_ptr& getCommunicator() const { return _communicator; } private: class TypeEntry { public: void add(const std::shared_ptr&); bool remove(const std::shared_ptr&); void addAllocationRequest(const std::shared_ptr&); bool canTryAllocate(const std::shared_ptr&, bool); const std::vector>& getObjects() const { return _objects; } private: std::vector> _objects; std::list> _requests; }; const std::shared_ptr _communicator; std::map _types; std::map > _allocatablesByType; }; }; #endif