diff options
author | Joe George <joe@zeroc.com> | 2021-01-28 16:26:44 -0500 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2021-02-01 16:59:30 -0500 |
commit | 92a6531e409f2691d82591e185a92299d415fc0f (patch) | |
tree | 60c79e2a8f327b8f0b6ebc06b06f48a2e8086f6a /cpp/src/IceGrid/NodeCache.h | |
parent | Port Glacier2, IceBox, IceBridge, IceDB, IceXML, icegriddb (diff) | |
download | ice-92a6531e409f2691d82591e185a92299d415fc0f.tar.bz2 ice-92a6531e409f2691d82591e185a92299d415fc0f.tar.xz ice-92a6531e409f2691d82591e185a92299d415fc0f.zip |
IceGrid and IceStorm
Diffstat (limited to 'cpp/src/IceGrid/NodeCache.h')
-rw-r--r-- | cpp/src/IceGrid/NodeCache.h | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/cpp/src/IceGrid/NodeCache.h b/cpp/src/IceGrid/NodeCache.h index 0230b7d05b2..639ff988ce1 100644 --- a/cpp/src/IceGrid/NodeCache.h +++ b/cpp/src/IceGrid/NodeCache.h @@ -5,8 +5,6 @@ #ifndef ICE_GRID_NODECACHE_H #define ICE_GRID_NODECACHE_H -#include <IceUtil/RecMutex.h> -#include <IceUtil/Shared.h> #include <IceGrid/Cache.h> #include <IceGrid/Internal.h> @@ -14,90 +12,94 @@ namespace IceGrid { class NodeCache; - -class SessionI; -typedef IceUtil::Handle<SessionI> SessionIPtr; - class NodeSessionI; -typedef IceUtil::Handle<NodeSessionI> NodeSessionIPtr; - +class ReplicaCache; class ServerEntry; -typedef IceUtil::Handle<ServerEntry> ServerEntryPtr; -typedef std::vector<ServerEntryPtr> ServerEntrySeq; +class SessionI; -class ReplicaCache; +using ServerEntrySeq = std::vector<std::shared_ptr<ServerEntry>>; -class NodeEntry : private IceUtil::Monitor<IceUtil::RecMutex> +class NodeEntry final { public: NodeEntry(NodeCache&, const std::string&); - virtual ~NodeEntry(); void addDescriptor(const std::string&, const NodeDescriptor&); void removeDescriptor(const std::string&); - void addServer(const ServerEntryPtr&); - void removeServer(const ServerEntryPtr&); - void setSession(const NodeSessionIPtr&); + void addServer(const std::shared_ptr<ServerEntry>&); + void removeServer(const std::shared_ptr<ServerEntry>&); + void setSession(const std::shared_ptr<NodeSessionI>&); - NodePrx getProxy() const; - InternalNodeInfoPtr getInfo() const; + std::shared_ptr<NodePrx> getProxy() const; + std::shared_ptr<InternalNodeInfo> getInfo() const; ServerEntrySeq getServers() const; LoadInfo getLoadInfoAndLoadFactor(const std::string&, float&) const; - NodeSessionIPtr getSession() const; + std::shared_ptr<NodeSessionI> getSession() const; - Ice::ObjectPrx getAdminProxy() const; + std::shared_ptr<Ice::ObjectPrx> getAdminProxy() const; bool canRemove(); - void loadServer(const ServerEntryPtr&, const ServerInfo&, const SessionIPtr&, int, bool); - void destroyServer(const ServerEntryPtr&, const ServerInfo&, int, bool); + void loadServer(const std::shared_ptr<ServerEntry>&, const ServerInfo&, const std::shared_ptr<SessionI>&, + std::chrono::seconds, bool); + void destroyServer(const std::shared_ptr<ServerEntry>&, const ServerInfo&, std::chrono::seconds, bool); - ServerInfo getServerInfo(const ServerInfo&, const SessionIPtr&); - InternalServerDescriptorPtr getInternalServerDescriptor(const ServerInfo&, const SessionIPtr&); + ServerInfo getServerInfo(const ServerInfo&, const std::shared_ptr<SessionI>&); + std::shared_ptr<InternalServerDescriptor> getInternalServerDescriptor(const ServerInfo&, const std::shared_ptr<SessionI>&); - void __incRef(); - void __decRef(); - - void checkSession() const; - void setProxy(const NodePrx&); + void checkSession(std::unique_lock<std::mutex>&) const; + void setProxy(const std::shared_ptr<NodePrx>&); void finishedRegistration(); - void finishedRegistration(const Ice::Exception&); + void finishedRegistration(std::exception_ptr); private: - ServerDescriptorPtr getServerDescriptor(const ServerInfo&, const SessionIPtr&); - InternalServerDescriptorPtr getInternalServerDescriptor(const ServerInfo&) const; + std::shared_ptr<NodeEntry> selfRemovingPtr() const; + + std::shared_ptr<ServerDescriptor> getServerDescriptor(const ServerInfo&, const std::shared_ptr<SessionI>&); + std::shared_ptr<InternalServerDescriptor> getInternalServerDescriptor(const ServerInfo&) const; NodeCache& _cache; - IceUtil::Mutex _refMutex; - int _ref; const std::string _name; - NodeSessionIPtr _session; - std::map<std::string, ServerEntryPtr> _servers; + std::shared_ptr<NodeSessionI> _session; + std::map<std::string, std::shared_ptr<ServerEntry>> _servers; std::map<std::string, NodeDescriptor> _descriptors; mutable bool _registering; - mutable NodePrx _proxy; + mutable std::shared_ptr<NodePrx> _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<NodeEntry> _selfRemovingPtr; + + // The number of self removing shared_ptr deleters left to run. + // Always accessed with the cache mutex locked + int _selfRemovingRefCount; + + friend NodeCache; }; -typedef IceUtil::Handle<NodeEntry> NodeEntryPtr; class NodeCache : public CacheByString<NodeEntry> { public: - NodeCache(const Ice::CommunicatorPtr&, ReplicaCache&, const std::string&); + using ValueType = NodeEntry*; + + NodeCache(const std::shared_ptr<Ice::Communicator>&, ReplicaCache&, const std::string&); - NodeEntryPtr get(const std::string&, bool = false) const; + std::shared_ptr<NodeEntry> get(const std::string&, bool = false) const; - const Ice::CommunicatorPtr& getCommunicator() const { return _communicator; } + const std::shared_ptr<Ice::Communicator>& getCommunicator() const { return _communicator; } const std::string& getReplicaName() const { return _replicaName; } ReplicaCache& getReplicaCache() const { return _replicaCache; } private: - const Ice::CommunicatorPtr _communicator; + const std::shared_ptr<Ice::Communicator> _communicator; const std::string _replicaName; ReplicaCache& _replicaCache; }; |