1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
10 #ifndef ICE_GRID_NODE_SESSION_MANAGER_H
11 #define ICE_GRID_NODE_SESSION_MANAGER_H
13 #include <IceUtil/Handle.h>
14 #include <IceUtil/Mutex.h>
15 #include <IceUtil/Monitor.h>
17 #include <IceGrid/SessionManager.h>
18 #include <IceGrid/Query.h>
19 #include <IceGrid/Internal.h>
26 typedef IceUtil::Handle
<NodeI
> NodeIPtr
;
28 class NodeSessionKeepAliveThread
: public SessionKeepAliveThread
<NodeSessionPrx
>
32 NodeSessionKeepAliveThread(const InternalRegistryPrx
&, const NodeIPtr
&, const std::vector
<QueryPrx
>&);
34 virtual NodeSessionPrx
createSession(InternalRegistryPrx
&, IceUtil::Time
&);
35 virtual void destroySession(const NodeSessionPrx
&);
36 virtual bool keepAlive(const NodeSessionPrx
&);
38 std::string
getName() const { return _name
; }
42 virtual NodeSessionPrx
createSessionImpl(const InternalRegistryPrx
&, IceUtil::Time
&);
45 const std::string _name
;
46 const std::vector
<QueryPrx
> _queryObjects
;
48 typedef IceUtil::Handle
<NodeSessionKeepAliveThread
> NodeSessionKeepAliveThreadPtr
;
50 class NodeSessionManager
: public IceUtil::Monitor
<IceUtil::Mutex
>
56 void create(const NodeIPtr
&);
57 void create(const InternalRegistryPrx
&);
63 void replicaInit(const InternalRegistryPrxSeq
&);
64 void replicaAdded(const InternalRegistryPrx
&);
65 void replicaRemoved(const InternalRegistryPrx
&);
67 NodeSessionPrx
getMasterNodeSession() const { return _thread
->getSession(); }
71 NodeSessionKeepAliveThreadPtr
addReplicaSession(const InternalRegistryPrx
&);
75 void syncServers(const NodeSessionPrx
&);
83 class Thread
: public NodeSessionKeepAliveThread
87 Thread(NodeSessionManager
& manager
) :
88 NodeSessionKeepAliveThread(manager
._master
, manager
._node
, manager
._queryObjects
),
93 virtual NodeSessionPrx
94 createSession(InternalRegistryPrx
& master
, IceUtil::Time
& timeout
)
96 NodeSessionPrx session
= NodeSessionKeepAliveThread::createSession(master
, timeout
);
97 _manager
.createdSession(session
);
98 _manager
.reapReplicas();
103 destroySession(const NodeSessionPrx
& session
)
105 NodeSessionKeepAliveThread::destroySession(session
);
106 _manager
.reapReplicas();
110 keepAlive(const NodeSessionPrx
& session
)
112 bool alive
= NodeSessionKeepAliveThread::keepAlive(session
);
113 _manager
.reapReplicas();
119 NodeSessionManager
& _manager
;
121 typedef IceUtil::Handle
<Thread
> ThreadPtr
;
124 void createdSession(const NodeSessionPrx
&);
126 const NodeIPtr _node
;
128 std::vector
<QueryPrx
> _queryObjects
;
129 InternalRegistryPrx _master
;
130 unsigned long _serial
;
134 typedef std::map
<Ice::Identity
, NodeSessionKeepAliveThreadPtr
> NodeSessionMap
;
135 NodeSessionMap _sessions
;
136 std::set
<Ice::Identity
> _replicas
;