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
|
// **********************************************************************
//
// Copyright (c) 2002
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// **********************************************************************
#include <Ice/ObjectAdapterFactory.h>
#include <Ice/ObjectAdapterI.h>
#include <Ice/LocalException.h>
#include <Ice/Functional.h>
using namespace std;
using namespace Ice;
using namespace IceInternal;
void IceInternal::incRef(ObjectAdapterFactory* p) { p->__incRef(); }
void IceInternal::decRef(ObjectAdapterFactory* p) { p->__decRef(); }
void
IceInternal::ObjectAdapterFactory::shutdown()
{
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
//
// Ignore shutdown requests if the object adapter factory has
// already been shut down.
//
if(!_instance)
{
return;
}
for_each(_adapters.begin(), _adapters.end(),
Ice::secondVoidMemFun<string, ObjectAdapter>(&ObjectAdapter::deactivate));
_instance = 0;
_communicator = 0;
notifyAll();
}
void
IceInternal::ObjectAdapterFactory::waitForShutdown()
{
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
//
// First we wait for the shutdown of the factory itself.
//
while(_instance)
{
wait();
}
//
// Now we wait for deactivation of each object adapter.
//
for_each(_adapters.begin(), _adapters.end(),
Ice::secondVoidMemFun<string, ObjectAdapter>(&ObjectAdapter::waitForDeactivate));
//
// We're done, now we can throw away the object adapters.
//
_adapters.clear();
}
ObjectAdapterPtr
IceInternal::ObjectAdapterFactory::createObjectAdapter(const string& name, const string& endpts, const string& id)
{
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(!_instance)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
map<string, ObjectAdapterIPtr>::iterator p = _adapters.find(name);
if(p != _adapters.end())
{
return p->second;
}
ObjectAdapterIPtr adapter = new ObjectAdapterI(_instance, _communicator, name, endpts, id);
_adapters.insert(make_pair(name, adapter));
return adapter;
}
ObjectAdapterPtr
IceInternal::ObjectAdapterFactory::findObjectAdapter(const ObjectPrx& proxy)
{
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
if(!_instance)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
for(map<string, ObjectAdapterIPtr>::iterator p = _adapters.begin(); p != _adapters.end(); ++p)
{
try
{
if(p->second->isLocal(proxy))
{
return p->second;
}
}
catch(const ObjectAdapterDeactivatedException&)
{
// Ignore.
}
}
return 0;
}
IceInternal::ObjectAdapterFactory::ObjectAdapterFactory(const InstancePtr& instance,
const CommunicatorPtr& communicator) :
_instance(instance),
_communicator(communicator)
{
}
IceInternal::ObjectAdapterFactory::~ObjectAdapterFactory()
{
assert(!_instance);
assert(!_communicator);
assert(_adapters.empty());
}
|