// ********************************************************************** // // Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. // // ********************************************************************** #ifndef ICE_GRID_ADAPTERCACHE_H #define ICE_GRID_ADAPTERCACHE_H #include #include #include #include #include namespace IceGrid { class AdapterCache; class ServerEntry; typedef IceUtil::Handle ServerEntryPtr; typedef std::vector ServerEntrySeq; class AdapterEntry; typedef IceUtil::Handle AdapterEntryPtr; class AdapterEntry : public IceUtil::Shared, public IceUtil::Mutex { public: AdapterEntry(Cache&, const std::string&); virtual std::vector > getProxies(bool, int&) { return std::vector >(); } virtual float getLeastLoadedNodeLoad(LoadSample) const { return 0.0f; } virtual std::string getApplication() const { return ""; } virtual bool canRemove(); protected: AdapterCache& _cache; const std::string _id; }; typedef IceUtil::Handle AdapterEntryPtr; class ServerAdapterEntry : public AdapterEntry { public: ServerAdapterEntry(Cache&, const std::string&); virtual std::vector > getProxies(bool, int&); virtual float getLeastLoadedNodeLoad(LoadSample) const; virtual std::string getApplication() const; void set(const ServerEntryPtr&, const std::string&); void destroy(); AdapterPrx getProxy(const std::string& = std::string()) const; private: ServerEntryPtr getServer() const; ServerEntryPtr _server; std::string _replicaGroupId; }; typedef IceUtil::Handle ServerAdapterEntryPtr; class ReplicaGroupEntry : public AdapterEntry { public: ReplicaGroupEntry(Cache&, const std::string&); virtual std::vector > getProxies(bool, int&); virtual float getLeastLoadedNodeLoad(LoadSample) const; virtual std::string getApplication() const; void set(const std::string&, const LoadBalancingPolicyPtr&); void addReplica(const std::string&, const ServerAdapterEntryPtr&); void removeReplica(const std::string&); private: LoadBalancingPolicyPtr _loadBalancing; int _loadBalancingNReplicas; LoadSample _loadSample; std::string _application; typedef std::vector > ReplicaSeq; ReplicaSeq _replicas; int _lastReplica; }; typedef IceUtil::Handle ReplicaGroupEntryPtr; class AdapterCache : public CacheByString { public: AdapterEntryPtr get(const std::string&) const; ServerAdapterEntryPtr getServerAdapter(const std::string&, bool = false) const; ReplicaGroupEntryPtr getReplicaGroup(const std::string&, bool = false) const; protected: virtual AdapterEntryPtr addImpl(const std::string&, const AdapterEntryPtr&); virtual AdapterEntryPtr removeImpl(const std::string&); }; }; #endif