// ********************************************************************** // // 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_NODE_SESSION_MANAGER_H #define ICE_GRID_NODE_SESSION_MANAGER_H #include #include #include #include #include #include namespace IceGrid { class NodeI; typedef IceUtil::Handle NodeIPtr; class NodeSessionKeepAliveThread : public SessionKeepAliveThread { public: NodeSessionKeepAliveThread(const InternalRegistryPrx&, const NodeIPtr&); virtual NodeSessionPrx createSession(const InternalRegistryPrx&, IceUtil::Time&); virtual void destroySession(const NodeSessionPrx&); virtual bool keepAlive(const NodeSessionPrx&); private: const NodeIPtr _node; const std::string _name; }; typedef IceUtil::Handle NodeSessionKeepAliveThreadPtr; class NodeSessionManager : public IceUtil::Monitor { public: NodeSessionManager(); void create(const NodeIPtr&); void create(const InternalRegistryPrx&); void waitForCreate(); void destroy(); NodeSessionKeepAliveThreadPtr replicaAdded(const InternalRegistryPrx&); void replicaRemoved(const InternalRegistryPrx&); NodeSessionPrx getMasterNodeSession() const { return _thread->getSession(); } private: void syncReplicas(const InternalRegistryPrxSeq&); class Thread : public SessionKeepAliveThread { public: Thread(NodeSessionManager& manager, const InternalRegistryPrx& master) : SessionKeepAliveThread(master), _manager(manager) { } virtual NodeSessionPrx createSession(const InternalRegistryPrx& master, IceUtil::Time& timeout) { return _manager.createSession(master, timeout); } virtual void destroySession(const NodeSessionPrx& session) { _manager.destroySession(session); } virtual bool keepAlive(const NodeSessionPrx& session) { return _manager.keepAlive(session); } private: NodeSessionManager& _manager; }; typedef IceUtil::Handle ThreadPtr; friend class Thread; NodeSessionPrx createSession(const InternalRegistryPrx&, IceUtil::Time&); void destroySession(const NodeSessionPrx&); bool keepAlive(const NodeSessionPrx&); const NodeIPtr _node; ThreadPtr _thread; QueryPrx _query; InternalRegistryPrx _master; unsigned long _serial; bool _destroyed; typedef std::map NodeSessionMap; NodeSessionMap _sessions; }; } #endif