summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2007-01-05 18:50:12 +0000
committerDwayne Boone <dwayne@zeroc.com>2007-01-05 18:50:12 +0000
commit738623799efdaab619e744919fb7c3821ded703c (patch)
tree8e9a20c99c07f6cab855b1ff246101dfdc4dfc28 /cpp/src
parentAdded ObjectAdapter::destroy (diff)
downloadice-738623799efdaab619e744919fb7c3821ded703c.tar.bz2
ice-738623799efdaab619e744919fb7c3821ded703c.tar.xz
ice-738623799efdaab619e744919fb7c3821ded703c.zip
Added ObejctAdapter::destroy
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Instance.cpp2
-rw-r--r--cpp/src/Ice/ObjectAdapterFactory.cpp29
-rw-r--r--cpp/src/Ice/ObjectAdapterFactory.h1
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp59
-rw-r--r--cpp/src/Ice/ObjectAdapterI.h3
5 files changed, 80 insertions, 14 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index 7ad6fd88321..9cc8aeabac9 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -851,7 +851,7 @@ IceInternal::Instance::destroy()
if(_objectAdapterFactory)
{
- _objectAdapterFactory->waitForShutdown();
+ _objectAdapterFactory->destroy();
}
if(_outgoingConnectionFactory)
diff --git a/cpp/src/Ice/ObjectAdapterFactory.cpp b/cpp/src/Ice/ObjectAdapterFactory.cpp
index 03ca3d518c5..bbd67ffd6eb 100644
--- a/cpp/src/Ice/ObjectAdapterFactory.cpp
+++ b/cpp/src/Ice/ObjectAdapterFactory.cpp
@@ -84,11 +84,6 @@ IceInternal::ObjectAdapterFactory::waitForShutdown()
for_each(_adapters.begin(), _adapters.end(),
IceUtil::secondVoidMemFun<const string, ObjectAdapterI>(&ObjectAdapter::waitForDeactivate));
- //
- // We're done, now we can throw away the object adapters.
- //
- _adapters.clear();
-
{
IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
@@ -100,6 +95,30 @@ IceInternal::ObjectAdapterFactory::waitForShutdown()
}
}
+void
+IceInternal::ObjectAdapterFactory::destroy()
+{
+ //
+ // First wait for shutdown to finish.
+ //
+ waitForShutdown();
+
+ map<string, ObjectAdapterIPtr> adapters;
+
+ {
+ IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+
+ adapters = _adapters;
+ _adapters.clear();
+ }
+
+ //
+ // Now we destroy each object adapter.
+ //
+ for_each(adapters.begin(), adapters.end(),
+ IceUtil::secondVoidMemFun<const string, ObjectAdapterI>(&ObjectAdapter::destroy));
+}
+
ObjectAdapterPtr
IceInternal::ObjectAdapterFactory::createObjectAdapter(const string& name, const string& endpoints,
const RouterPrx& router)
diff --git a/cpp/src/Ice/ObjectAdapterFactory.h b/cpp/src/Ice/ObjectAdapterFactory.h
index a94a5a7339d..5d35df6a568 100644
--- a/cpp/src/Ice/ObjectAdapterFactory.h
+++ b/cpp/src/Ice/ObjectAdapterFactory.h
@@ -23,6 +23,7 @@ public:
void shutdown();
void waitForShutdown();
+ void destroy();
::Ice::ObjectAdapterPtr createObjectAdapter(const std::string&, const std::string&, const Ice::RouterPrx&);
::Ice::ObjectAdapterPtr findObjectAdapter(const ::Ice::ObjectPrx&);
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index 774bb1a45cc..c53b96560a8 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -287,14 +287,54 @@ Ice::ObjectAdapterI::waitForDeactivate()
for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(),
Ice::voidMemFun(&IncomingConnectionFactory::waitUntilFinished));
+ {
+ IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+
+ //
+ // Signal that waiting is complete.
+ //
+ _waitForDeactivate = false;
+ notifyAll();
+ }
+}
+
+void
+Ice::ObjectAdapterI::destroy()
+{
+ {
+ IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+
+ //
+ // Another thread is in the process of destroying the object
+ // adapter. Wait for it to finish.
+ //
+ while(_destroying)
+ {
+ wait();
+ }
+
+ //
+ // Object adpater is already destroyed.
+ //
+ if(_destroyed)
+ {
+ return;
+ }
+
+ _destroying = true;
+ }
+
+ //
+ // Deactivate and wait for completion.
+ //
+ deactivate();
+ waitForDeactivate();
+
//
// Now it's also time to clean up our servants and servant
// locators.
//
- if(_instance) // Don't destroy twice.
- {
- _servantManager->destroy();
- }
+ _servantManager->destroy();
//
// Destroy the thread pool.
@@ -311,9 +351,10 @@ Ice::ObjectAdapterI::waitForDeactivate()
IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
//
- // Signal that waiting is complete.
+ // Signal that destroy is complete.
//
- _waitForDeactivate = false;
+ _destroying = false;
+ _destroyed = true;
notifyAll();
//
@@ -692,6 +733,8 @@ Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const Communica
_directCount(0),
_waitForActivate(false),
_waitForDeactivate(false),
+ _destroying(false),
+ _destroyed(false),
_noConfig(noConfig)
{
if(_noConfig)
@@ -892,10 +935,10 @@ Ice::ObjectAdapterI::~ObjectAdapterI()
Warning out(_instance->initializationData().logger);
out << "object adapter `" << getName() << "' has not been deactivated";
}
- else if(_instance)
+ else if(!_destroyed)
{
Warning out(_instance->initializationData().logger);
- out << "object adapter `" << getName() << "' deactivation had not been waited for";
+ out << "object adapter `" << getName() << "' has not been destroyed";
}
else
{
diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h
index c3f198d91b8..a4634d68931 100644
--- a/cpp/src/Ice/ObjectAdapterI.h
+++ b/cpp/src/Ice/ObjectAdapterI.h
@@ -49,6 +49,7 @@ public:
virtual void waitForHold();
virtual void deactivate();
virtual void waitForDeactivate();
+ virtual void destroy();
virtual ObjectPrx add(const ObjectPtr&, const Identity&);
virtual ObjectPrx addFacet(const ObjectPtr&, const Identity&, const std::string&);
@@ -117,6 +118,8 @@ private:
int _directCount; // The number of direct proxies dispatching on this object adapter.
bool _waitForActivate;
bool _waitForDeactivate;
+ bool _destroying;
+ bool _destroyed;
bool _noConfig;
static std::string _propertyPrefix;