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
195
196
197
198
199
200
|
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <Ice/Ice.h>
#include <IcePack/AdapterManagerI.h>
#include <IcePack/ServerManager.h>
using namespace std;
using namespace Ice;
using namespace IcePack;
IcePack::AdapterI::AdapterI(Int waitTime) :
_waitTime(waitTime)
{
}
IcePack::AdapterI::~AdapterI()
{
}
AdapterDescription
IcePack::AdapterI::getAdapterDescription(const Current&)
{
return _description;
}
ObjectPrx
IcePack::AdapterI::getDirectProxy(bool activate, const Current&)
{
::IceUtil::Monitor< ::IceUtil::Mutex>::Lock sync(*this);
if(!activate || !_description.server || _active)
{
return _proxy;
}
//
// If there's a server associated to this adapter, try to start
// the server and wait for the adapter state to change.
//
if(_description.server && _description.server->start())
{
//
// Wait for this adapter to be marked as active or the
// activation timeout.
//
while(!_active)
{
bool notify = timedWait(IceUtil::Time::seconds(_waitTime));
if(!notify)
{
throw AdapterActivationTimeoutException();
}
}
}
return _proxy;
}
void
IcePack::AdapterI::setDirectProxy(const ObjectPrx& proxy, const Current&)
{
::IceUtil::Monitor< ::IceUtil::Mutex>::Lock sync(*this);
_proxy = proxy;
}
void
IcePack::AdapterI::markAsActive(const Current&)
{
::IceUtil::Monitor< ::IceUtil::Mutex>::Lock sync(*this);
_active = true;
notifyAll();
}
void
IcePack::AdapterI::markAsInactive(const Current&)
{
::IceUtil::Monitor< ::IceUtil::Mutex>::Lock sync(*this);
_active = false;
notifyAll();
}
class AdapterNameToAdapter
{
public:
AdapterNameToAdapter(const ObjectAdapterPtr& adapter) :
_adapter(adapter)
{
}
AdapterPrx
operator()(const string& name)
{
Identity ident;
ident.category = "adapter";
ident.name = name;
return AdapterPrx::uncheckedCast(_adapter->createProxy(ident));
}
private:
ObjectAdapterPtr _adapter;
};
IcePack::AdapterManagerI::AdapterManagerI(const ObjectAdapterPtr& adapter) :
_adapter(adapter)
{
Ice::PropertiesPtr properties = adapter->getCommunicator()->getProperties();
_waitTime = properties->getPropertyAsIntWithDefault("IcePack.Activation.WaitTime", 10);
}
AdapterPrx
IcePack::AdapterManagerI::create(const AdapterDescription& description, const Current&)
{
IceUtil::Mutex::Lock sync(*this);
AdapterPrx adapter = AdapterNameToAdapter(_adapter)(description.name);
try
{
adapter->ice_ping();
//
// The adapter already exists.
//
throw AdapterExistsException();
}
catch(const ObjectNotExistException&)
{
}
AdapterPtr adapterI = new AdapterI(_waitTime);
adapterI->_description = description;
adapterI->_active = false;
adapterI->_proxy = 0;
//
// Add this adapter name to our adapter names internal set.
//
_adapterNames.insert(description.name);
return AdapterPrx::uncheckedCast(_adapter->add(adapterI, adapter->ice_getIdentity()));
}
AdapterPrx
IcePack::AdapterManagerI::findByName(const string& name, const Current&)
{
AdapterPrx adapter = AdapterNameToAdapter(_adapter)(name);
try
{
adapter->ice_ping();
return adapter;
}
catch(const ObjectNotExistException&)
{
return 0;
}
}
void
IcePack::AdapterManagerI::remove(const string& name, const Current&)
{
IceUtil::Mutex::Lock sync(*this);
AdapterPrx adapter = AdapterNameToAdapter(_adapter)(name);
try
{
adapter->ice_ping();
}
catch(const ObjectNotExistException&)
{
throw AdapterNotExistException();
}
_adapter->remove(adapter->ice_getIdentity());
//
// Remove the adapter name from our internal name set.
//
_adapterNames.erase(_adapterNames.find(name));
}
AdapterNames
IcePack::AdapterManagerI::getAll(const Current&)
{
IceUtil::Mutex::Lock sync(*this);
AdapterNames names;
names.reserve(_adapterNames.size());
copy(_adapterNames.begin(), _adapterNames.end(), back_inserter(names));
return names;
}
|