summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/NodeCache.h
blob: edf7471a5dc3f326870b4da29222da0ce6b469bb (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
108
// **********************************************************************
//
// 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_NODECACHE_H
#define ICE_GRID_NODECACHE_H

#include <IceUtil/Mutex.h>
#include <IceUtil/Shared.h>
#include <IceGrid/Cache.h>
#include <IceGrid/Internal.h>

namespace IceGrid
{

class NodeCache;

class SessionI;
typedef IceUtil::Handle<SessionI> SessionIPtr;

class NodeSessionI;
typedef IceUtil::Handle<NodeSessionI> NodeSessionIPtr;

class ServerEntry;
typedef IceUtil::Handle<ServerEntry> ServerEntryPtr;
typedef std::vector<ServerEntryPtr> ServerEntrySeq;

class ReplicaCache;

class NodeEntry : public IceUtil::Monitor<IceUtil::RecMutex>
{
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 setSavedProxy(const NodePrx&);

    NodePrx getProxy() const;
    InternalNodeInfoPtr getInfo() const;
    ServerEntrySeq getServers() const;
    LoadInfo getLoadInfoAndLoadFactor(const std::string&, float&) const;

    bool canRemove();
    
    void loadServer(const ServerEntryPtr&, const ServerInfo&, const SessionIPtr&, int);
    void destroyServer(const ServerEntryPtr&, const ServerInfo&, int);
    ServerInfo getServerInfo(const ServerInfo&, const SessionIPtr&);

    void __incRef();
    void __decRef();

    void checkSession() const;
    void setProxy(const NodePrx&);
    void finishedRegistration();
    void finishedRegistration(const Ice::Exception&);

private:
    
    ServerDescriptorPtr getServerDescriptor(const ServerInfo&, const SessionIPtr&);
    InternalServerDescriptorPtr getInternalServerDescriptor(const ServerInfo&) const;

    NodeCache& _cache;
    IceUtil::Mutex _refMutex;
    int _ref;
    const std::string _name;
    NodeSessionIPtr _session;
    std::map<std::string, ServerEntryPtr> _servers;
    std::map<std::string, NodeDescriptor> _descriptors;

    mutable bool _registering;
    mutable NodePrx _proxy;
};
typedef IceUtil::Handle<NodeEntry> NodeEntryPtr;

class NodeCache : public CacheByString<NodeEntry>
{
public:

    NodeCache(const Ice::CommunicatorPtr&, ReplicaCache&, const std::string&);

    NodeEntryPtr get(const std::string&, bool = false) const;

    const Ice::CommunicatorPtr& getCommunicator() const { return _communicator; }
    const std::string& getReplicaName() const { return _replicaName; }
    ReplicaCache& getReplicaCache() const { return _replicaCache; }

private:
    
    const Ice::CommunicatorPtr _communicator;
    const std::string _replicaName;
    ReplicaCache& _replicaCache;
};

};

#endif