summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/ReplicaSessionManager.h
blob: 32658fed0bff584acde228b86a4b9244035703c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// **********************************************************************
//
// Copyright (c) 2003-2007 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_REPLICA_SESSION_MANAGER_H
#define ICE_GRID_REPLICA_SESSION_MANAGER_H

#include <IceUtil/Handle.h>
#include <IceUtil/Mutex.h>
#include <IceUtil/Monitor.h>

#include <IceGrid/SessionManager.h>
#include <IceGrid/Internal.h>

namespace IceGrid
{

class Database;
typedef IceUtil::Handle<Database> DatabasePtr;

class WellKnownObjectsManager;
typedef IceUtil::Handle<WellKnownObjectsManager> WellKnownObjectsManagerPtr;

class TraceLevels;
typedef IceUtil::Handle<TraceLevels> TraceLevelsPtr;

class ReplicaSessionManager : public IceUtil::Monitor<IceUtil::Mutex>
{
public:

    class Thread : public SessionKeepAliveThread<ReplicaSessionPrx>
    {
    public:

	Thread(ReplicaSessionManager& manager, const InternalRegistryPrx& master) : 
	    SessionKeepAliveThread<ReplicaSessionPrx>(master),
	    _manager(manager)
        {
	}

	virtual ReplicaSessionPrx 
	createSession(InternalRegistryPrx& master, IceUtil::Time& timeout)
        {
	    return _manager.createSession(master, timeout);
	}

	virtual void 
	destroySession(const ReplicaSessionPrx& session)
        {
	    _manager.destroySession(session);
	}

	virtual bool 
	keepAlive(const ReplicaSessionPrx& session)
        {
	    return _manager.keepAlive(session);
	}

	void registerAllWellKnownObjects();

    private:
	
	ReplicaSessionManager& _manager;
    };
    typedef IceUtil::Handle<Thread> ThreadPtr;

    ReplicaSessionManager();
    
    void create(const std::string&, const InternalReplicaInfoPtr&, const DatabasePtr&, 
		const WellKnownObjectsManagerPtr&, const InternalRegistryPrx&);
    void create(const InternalRegistryPrx&);
    NodePrxSeq getNodes(const NodePrxSeq&) const;
    void destroy();

    void registerAllWellKnownObjects();
    ReplicaSessionPrx getSession() const { return _thread->getSession(); }

private:

    friend class Thread;

    ReplicaSessionPrx createSession(InternalRegistryPrx&, IceUtil::Time&);
    ReplicaSessionPrx createSessionImpl(const InternalRegistryPrx&, IceUtil::Time&);
    void destroySession(const ReplicaSessionPrx&);
    bool keepAlive(const ReplicaSessionPrx&);

    ThreadPtr _thread;
    std::string _name;
    InternalReplicaInfoPtr _info;
    InternalRegistryPrx _master;
    RegistryPrx _registry;
    InternalRegistryPrx _internalRegistry;
    DatabaseObserverPrx _observer;
    DatabasePtr _database;
    WellKnownObjectsManagerPtr _wellKnownObjects;
    TraceLevelsPtr _traceLevels;
    std::vector<QueryPrx> _queryObjects;
};

}

#endif