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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
// **********************************************************************
//
// Copyright (c) 2003-2017 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_LOCATOR_INFO_H
#define ICE_LOCATOR_INFO_H
#include <IceUtil/Shared.h>
#include <IceUtil/Mutex.h>
#include <IceUtil/Monitor.h>
#include <IceUtil/Time.h>
#include <Ice/LocatorInfoF.h>
#include <Ice/LocatorF.h>
#include <Ice/ReferenceF.h>
#include <Ice/Identity.h>
#include <Ice/EndpointIF.h>
#include <Ice/PropertiesF.h>
#include <Ice/Version.h>
#include <IceUtil/UniquePtr.h>
namespace IceInternal
{
class LocatorManager : public IceUtil::Shared, public IceUtil::Mutex
{
public:
LocatorManager(const Ice::PropertiesPtr&);
void destroy();
//
// Returns locator info for a given locator. Automatically creates
// the locator info if it doesn't exist yet.
//
LocatorInfoPtr get(const Ice::LocatorPrx&);
private:
const bool _background;
std::map<Ice::LocatorPrx, LocatorInfoPtr> _table;
std::map<Ice::LocatorPrx, LocatorInfoPtr>::iterator _tableHint;
std::map<std::pair<Ice::Identity, Ice::EncodingVersion>, LocatorTablePtr> _locatorTables;
};
class LocatorTable : public IceUtil::Shared, public IceUtil::Mutex
{
public:
LocatorTable();
void clear();
bool getAdapterEndpoints(const std::string&, int, ::std::vector<EndpointIPtr>&);
void addAdapterEndpoints(const std::string&, const ::std::vector<EndpointIPtr>&);
::std::vector<EndpointIPtr> removeAdapterEndpoints(const std::string&);
bool getObjectReference(const Ice::Identity&, int, ReferencePtr&);
void addObjectReference(const Ice::Identity&, const ReferencePtr&);
ReferencePtr removeObjectReference(const Ice::Identity&);
private:
bool checkTTL(const IceUtil::Time&, int) const;
std::map<std::string, std::pair<IceUtil::Time, std::vector<EndpointIPtr> > > _adapterEndpointsMap;
std::map<Ice::Identity, std::pair<IceUtil::Time, ReferencePtr> > _objectMap;
};
class LocatorInfo : public IceUtil::Shared, public IceUtil::Mutex
{
public:
class GetEndpointsCallback : virtual public IceUtil::Shared
{
public:
virtual void setEndpoints(const std::vector<EndpointIPtr>&, bool) = 0;
virtual void setException(const Ice::LocalException&) = 0;
};
typedef IceUtil::Handle<GetEndpointsCallback> GetEndpointsCallbackPtr;
class RequestCallback : virtual public IceUtil::Shared
{
public:
RequestCallback(const ReferencePtr&, int, const GetEndpointsCallbackPtr&);
void response(const LocatorInfoPtr&, const Ice::ObjectPrx&);
void exception(const LocatorInfoPtr&, const Ice::Exception&);
private:
const ReferencePtr _ref;
const int _ttl;
const GetEndpointsCallbackPtr _callback;
};
typedef IceUtil::Handle<RequestCallback> RequestCallbackPtr;
class Request : virtual public IceUtil::Shared
{
public:
void addCallback(const ReferencePtr&, const ReferencePtr&, int, const GetEndpointsCallbackPtr&);
std::vector<EndpointIPtr> getEndpoints(const ReferencePtr&, const ReferencePtr&, int, bool&);
void response(const Ice::ObjectPrx&);
void exception(const Ice::Exception&);
protected:
Request(const LocatorInfoPtr&, const ReferencePtr&);
virtual void send() = 0;
const LocatorInfoPtr _locatorInfo;
const ReferencePtr _ref;
private:
IceUtil::Monitor<IceUtil::Mutex> _monitor;
std::vector<RequestCallbackPtr> _callbacks;
std::vector<ReferencePtr> _wellKnownRefs;
bool _sent;
bool _response;
Ice::ObjectPrx _proxy;
IceUtil::UniquePtr<Ice::Exception> _exception;
};
typedef IceUtil::Handle<Request> RequestPtr;
LocatorInfo(const Ice::LocatorPrx&, const LocatorTablePtr&, bool);
void destroy();
bool operator==(const LocatorInfo&) const;
bool operator!=(const LocatorInfo&) const;
bool operator<(const LocatorInfo&) const;
const Ice::LocatorPrx& getLocator() const
{
//
// No mutex lock necessary, _locator is immutable.
//
return _locator;
}
Ice::LocatorRegistryPrx getLocatorRegistry();
std::vector<EndpointIPtr> getEndpoints(const ReferencePtr& ref, int ttl, bool& cached)
{
return getEndpoints(ref, 0, ttl, cached);
}
std::vector<EndpointIPtr> getEndpoints(const ReferencePtr&, const ReferencePtr&, int, bool&);
void getEndpointsWithCallback(const ReferencePtr& ref, int ttl, const GetEndpointsCallbackPtr& cb)
{
getEndpointsWithCallback(ref, 0, ttl, cb);
}
void getEndpointsWithCallback(const ReferencePtr&, const ReferencePtr&, int, const GetEndpointsCallbackPtr&);
void clearCache(const ReferencePtr&);
private:
void getEndpointsException(const ReferencePtr&, const Ice::Exception&);
void getEndpointsTrace(const ReferencePtr&, const std::vector<EndpointIPtr>&, bool);
void trace(const std::string&, const ReferencePtr&, const std::vector<EndpointIPtr>&);
RequestPtr getAdapterRequest(const ReferencePtr&);
RequestPtr getObjectRequest(const ReferencePtr&);
void finishRequest(const ReferencePtr&, const std::vector<ReferencePtr>&, const Ice::ObjectPrx&, bool);
friend class Request;
friend class RequestCallback;
const Ice::LocatorPrx _locator;
Ice::LocatorRegistryPrx _locatorRegistry;
const LocatorTablePtr _table;
const bool _background;
std::map<std::string, RequestPtr> _adapterRequests;
std::map<Ice::Identity, RequestPtr> _objectRequests;
};
}
#endif
|