From a41bb120db0ccdea5eea58e26bd30eddaff40877 Mon Sep 17 00:00:00 2001 From: Marc Laukien Date: Sat, 14 Dec 2002 22:19:03 +0000 Subject: complete shutdown/deactivate re-implementation --- cpp/src/Ice/ObjectAdapterFactory.cpp | 72 +++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 5 deletions(-) (limited to 'cpp/src/Ice/ObjectAdapterFactory.cpp') diff --git a/cpp/src/Ice/ObjectAdapterFactory.cpp b/cpp/src/Ice/ObjectAdapterFactory.cpp index f10d21a3cc9..b4419cf68ce 100644 --- a/cpp/src/Ice/ObjectAdapterFactory.cpp +++ b/cpp/src/Ice/ObjectAdapterFactory.cpp @@ -14,6 +14,7 @@ #include #include +#include #include using namespace std; @@ -26,18 +27,60 @@ void IceInternal::decRef(ObjectAdapterFactory* p) { p->__decRef(); } void IceInternal::ObjectAdapterFactory::shutdown() { - IceUtil::Mutex::Lock sync(*this); + IceUtil::Monitor::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(&ObjectAdapter::deactivate)); + + _instance = 0; + _communicator = 0; + notifyAll(); +} + +void +IceInternal::ObjectAdapterFactory::waitForShutdown() +{ + IceUtil::Monitor::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(&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::Mutex::Lock sync(*this); + IceUtil::Monitor::Lock sync(*this); + + if(!_instance) + { + throw CommunicatorDestroyedException(__FILE__, __LINE__); + } map::iterator p = _adapters.find(name); if(p != _adapters.end()) @@ -53,13 +96,25 @@ IceInternal::ObjectAdapterFactory::createObjectAdapter(const string& name, const ObjectAdapterPtr IceInternal::ObjectAdapterFactory::findObjectAdapter(const ObjectPrx& proxy) { - IceUtil::Mutex::Lock sync(*this); + IceUtil::Monitor::Lock sync(*this); + + if(!_instance) + { + throw CommunicatorDestroyedException(__FILE__, __LINE__); + } for(map::iterator p = _adapters.begin(); p != _adapters.end(); ++p) { - if(p->second->isLocal(proxy)) + try { - return p->second; + if(p->second->isLocal(proxy)) + { + return p->second; + } + } + catch(const ObjectAdapterDeactivatedException&) + { + // Ignore. } } @@ -72,3 +127,10 @@ IceInternal::ObjectAdapterFactory::ObjectAdapterFactory(const InstancePtr& insta _communicator(communicator) { } + +IceInternal::ObjectAdapterFactory::~ObjectAdapterFactory() +{ + assert(!_instance); + assert(!_communicator); + assert(_adapters.empty()); +} -- cgit v1.2.3