// // Copyright (c) ZeroC, Inc. All rights reserved. // #ifndef ICE_GRID_NODECACHE_H #define ICE_GRID_NODECACHE_H #include #include namespace IceGrid { class NodeCache; class NodeSessionI; class ReplicaCache; class ServerEntry; class SessionI; using ServerEntrySeq = std::vector>; class NodeEntry final { public: NodeEntry(NodeCache&, const std::string&); void addDescriptor(const std::string&, const NodeDescriptor&); void removeDescriptor(const std::string&); void addServer(const std::shared_ptr&); void removeServer(const std::shared_ptr&); void setSession(const std::shared_ptr&); std::shared_ptr getProxy() const; std::shared_ptr getInfo() const; ServerEntrySeq getServers() const; LoadInfo getLoadInfoAndLoadFactor(const std::string&, float&) const; std::shared_ptr getSession() const; std::shared_ptr getAdminProxy() const; bool canRemove(); void loadServer(const std::shared_ptr&, const ServerInfo&, const std::shared_ptr&, std::chrono::seconds, bool); void destroyServer(const std::shared_ptr&, const ServerInfo&, std::chrono::seconds, bool); ServerInfo getServerInfo(const ServerInfo&, const std::shared_ptr&); std::shared_ptr getInternalServerDescriptor(const ServerInfo&, const std::shared_ptr&); void checkSession(std::unique_lock&) const; void setProxy(const std::shared_ptr&); void finishedRegistration(); void finishedRegistration(std::exception_ptr); private: std::shared_ptr selfRemovingPtr() const; std::shared_ptr getServerDescriptor(const ServerInfo&, const std::shared_ptr&); std::shared_ptr getInternalServerDescriptor(const ServerInfo&) const; NodeCache& _cache; const std::string _name; std::shared_ptr _session; std::map> _servers; std::map _descriptors; mutable bool _registering; mutable std::shared_ptr _proxy; mutable std::mutex _mutex; mutable std::condition_variable _condVar; // A self removing shared_ptr of 'this' which removes itself from the NodeCache upon destruction std::weak_ptr _selfRemovingPtr; // The number of self removing shared_ptr deleters left to run. // Always accessed with the cache mutex locked int _selfRemovingRefCount; friend NodeCache; }; class NodeCache : public CacheByString { public: using ValueType = NodeEntry*; NodeCache(const std::shared_ptr&, ReplicaCache&, const std::string&); std::shared_ptr get(const std::string&, bool = false) const; const std::shared_ptr& getCommunicator() const { return _communicator; } const std::string& getReplicaName() const { return _replicaName; } ReplicaCache& getReplicaCache() const { return _replicaCache; } private: const std::shared_ptr _communicator; const std::string _replicaName; ReplicaCache& _replicaCache; }; }; #endif