diff options
author | Matthew Newhook <matthew@zeroc.com> | 2014-10-02 16:45:39 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2014-10-02 16:45:39 -0230 |
commit | 4dbbe4e02d903abb8a7c7e234c36e1ba4c1e2291 (patch) | |
tree | 2d9c1f2761bdfc78526d2cabbca9c9d5f445a3bd /cpp | |
parent | ICE-5585 call callback from ThreadPool if conneciton already closed (diff) | |
download | ice-4dbbe4e02d903abb8a7c7e234c36e1ba4c1e2291.tar.bz2 ice-4dbbe4e02d903abb8a7c7e234c36e1ba4c1e2291.tar.xz ice-4dbbe4e02d903abb8a7c7e234c36e1ba4c1e2291.zip |
Cleanup and simplification of OA in C++/Java/C#.
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/Ice/ObjectAdapterI.cpp | 151 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterI.h | 20 | ||||
-rw-r--r-- | cpp/src/Ice/ServantManager.cpp | 11 | ||||
-rw-r--r-- | cpp/src/Ice/ThreadPool.cpp | 6 |
4 files changed, 68 insertions, 120 deletions
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index a2ffa037994..422cdb8fd01 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -91,18 +91,10 @@ Ice::ObjectAdapterI::activate() checkForDeactivation(); // - // If some threads are waiting on waitForHold(), we set this - // flag to ensure the threads will start again the wait for - // all the incoming connection factories. + // If we've previously been initialized we just need to activate the + // incoming connection factories and we're done. // - _waitForHoldRetry = _waitForHold > 0; - - // - // If the one off initializations of the adapter are already - // done, we just need to activate the incoming connection - // factories and we're done. - // - if(_activateOneOffDone) + if(_state != StateUninitialized) { for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), Ice::voidMemFun(&IncomingConnectionFactory::activate)); @@ -110,12 +102,13 @@ Ice::ObjectAdapterI::activate() } // - // One off initializations of the adapter: update the locator - // registry and print the "adapter ready" message. We set the - // _waitForActivate flag to prevent deactivation from other - // threads while these one off initializations are done. + // One off initializations of the adapter: update the + // locator registry and print the "adapter ready" + // message. We set set state to StateWaitActivate to prevent + // deactivation from other threads while these one off + // initializations are done. // - _waitForActivate = true; + _state = StateWaitActivate; locatorInfo = _locatorInfo; if(!_noConfig) @@ -142,7 +135,7 @@ Ice::ObjectAdapterI::activate() // { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - _waitForActivate = false; + _state = StateUninitialized; notifyAll(); } throw; @@ -155,16 +148,14 @@ Ice::ObjectAdapterI::activate() { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - assert(!_deactivated); // Not possible if _waitForActivate = true; + assert(_state == StateWaitActivate); // // Signal threads waiting for the activation. // - _waitForActivate = false; + _state = StateActive; notifyAll(); - _activateOneOffDone = true; - for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), Ice::voidMemFun(&IncomingConnectionFactory::activate)); } @@ -176,6 +167,7 @@ Ice::ObjectAdapterI::hold() IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); checkForDeactivation(); + _state = StateHeld; for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), Ice::voidMemFun(&IncomingConnectionFactory::hold)); @@ -184,52 +176,17 @@ Ice::ObjectAdapterI::hold() void Ice::ObjectAdapterI::waitForHold() { - while(true) + vector<IncomingConnectionFactoryPtr> incomingConnectionFactories; { - vector<IncomingConnectionFactoryPtr> incomingConnectionFactories; - { - IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - - checkForDeactivation(); - - incomingConnectionFactories = _incomingConnectionFactories; - - ++_waitForHold; - } + IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - for_each(incomingConnectionFactories.begin(), incomingConnectionFactories.end(), - Ice::constVoidMemFun(&IncomingConnectionFactory::waitUntilHolding)); + checkForDeactivation(); - { - IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - if(--_waitForHold == 0) - { - notifyAll(); - } - - // - // If we don't need to retry, we're done. Otherwise, we wait until - // all the waiters finish waiting on the connections and we try - // again waiting on all the conncetions. This is necessary in the - // case activate() is called by another thread while waitForHold() - // waits on the some connection, if we didn't retry, waitForHold() - // could return only after waiting on a subset of the connections. - // - if(!_waitForHoldRetry) - { - return; - } - else - { - while(_waitForHold > 0) - { - checkForDeactivation(); - wait(); - } - _waitForHoldRetry = false; - } - } + incomingConnectionFactories = _incomingConnectionFactories; } + + for_each(incomingConnectionFactories.begin(), incomingConnectionFactories.end(), + Ice::constVoidMemFun(&IncomingConnectionFactory::waitUntilHolding)); } void @@ -245,7 +202,7 @@ Ice::ObjectAdapterI::deactivate() // Ignore deactivation requests if the object adapter has already // been deactivated. // - if(_deactivated) + if(_state >= StateDeactivating) { return; } @@ -254,7 +211,7 @@ Ice::ObjectAdapterI::deactivate() // Wait for activation to complete. This is necessary to not // get out of order locator updates. // - while(_waitForActivate) + while(_state == StateWaitActivate) { wait(); } @@ -276,9 +233,7 @@ Ice::ObjectAdapterI::deactivate() outgoingConnectionFactory = _instance->outgoingConnectionFactory(); locatorInfo = _locatorInfo; - _deactivated = true; - - notifyAll(); + _state = StateDeactivating; } try @@ -307,6 +262,12 @@ Ice::ObjectAdapterI::deactivate() // requests being dispatched. // outgoingConnectionFactory->removeAdapter(this); + + { + IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); + _state = StateDeactivated; + notifyAll(); + } } void @@ -316,7 +277,7 @@ Ice::ObjectAdapterI::waitForDeactivate() { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - if(_destroyed) + if(_state == StateDestroyed) { return; } @@ -325,7 +286,7 @@ Ice::ObjectAdapterI::waitForDeactivate() // Wait for deactivation of the adapter itself, and for // the return of all direct method calls using this adapter. // - while(!_deactivated || _directCount > 0) + while((_state != StateDeactivated) || _directCount > 0) { wait(); } @@ -346,35 +307,12 @@ Ice::ObjectAdapterI::isDeactivated() const { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); - return _deactivated; + return _state >= StateDeactivated; } 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 adapter is already destroyed. - // - if(_destroyed) - { - return; - } - - _destroying = true; - } - // // Deactivate and wait for completion. // @@ -400,12 +338,18 @@ Ice::ObjectAdapterI::destroy() { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this); + // + // If destroy is already complete, we're done. + // + if(_state == StateDestroyed) + { + return; + } // // Signal that destroy is complete. // - _destroying = false; - _destroyed = true; + _state = StateDestroyed; notifyAll(); // @@ -912,19 +856,13 @@ Ice::ObjectAdapterI::getACM() const Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const CommunicatorPtr& communicator, const ObjectAdapterFactoryPtr& objectAdapterFactory, const string& name, /*const RouterPrx& router,*/ bool noConfig) : - _deactivated(false), + _state(StateUninitialized), _instance(instance), _communicator(communicator), _objectAdapterFactory(objectAdapterFactory), _servantManager(new ServantManager(instance, name)), - _activateOneOffDone(false), _name(name), _directCount(0), - _waitForActivate(false), - _waitForHold(0), - _waitForHoldRetry(false), - _destroying(false), - _destroyed(false), _noConfig(noConfig) { } @@ -1096,12 +1034,12 @@ Ice::ObjectAdapterI::initialize(const RouterPrx& router) Ice::ObjectAdapterI::~ObjectAdapterI() { - if(!_deactivated) + if(_state < StateDeactivated) { Warning out(_instance->initializationData().logger); out << "object adapter `" << getName() << "' has not been deactivated"; } - else if(!_destroyed) + else if(_state != StateDestroyed) { Warning out(_instance->initializationData().logger); out << "object adapter `" << getName() << "' has not been destroyed"; @@ -1112,7 +1050,6 @@ Ice::ObjectAdapterI::~ObjectAdapterI() assert(!_threadPool); assert(_incomingConnectionFactories.empty()); assert(_directCount == 0); - assert(!_waitForActivate); } } @@ -1169,7 +1106,7 @@ Ice::ObjectAdapterI::newIndirectProxy(const Identity& ident, const string& facet void Ice::ObjectAdapterI::checkForDeactivation() const { - if(_deactivated) + if(_state >= StateDeactivating) { ObjectAdapterDeactivatedException ex(__FILE__, __LINE__); ex.name = getName(); diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h index 9d2df9ceff9..3897c0ef557 100644 --- a/cpp/src/Ice/ObjectAdapterI.h +++ b/cpp/src/Ice/ObjectAdapterI.h @@ -23,7 +23,6 @@ #include <Ice/ObjectF.h> #include <Ice/RouterInfoF.h> #include <Ice/EndpointIF.h> -#include <Ice/ConnectorF.h> #include <Ice/LocatorInfoF.h> #include <Ice/ThreadPoolF.h> #include <Ice/OutgoingAsyncF.h> @@ -117,30 +116,33 @@ private: void updateLocatorRegistry(const IceInternal::LocatorInfoPtr&, const Ice::ObjectPrx&, bool); bool filterProperties(Ice::StringSeq&); - bool _deactivated; + enum State + { + StateUninitialized, + StateHeld, + StateWaitActivate, + StateActive, + StateDeactivating, + StateDeactivated, + StateDestroyed + }; + State _state; IceInternal::InstancePtr _instance; CommunicatorPtr _communicator; IceInternal::ObjectAdapterFactoryPtr _objectAdapterFactory; IceInternal::ThreadPoolPtr _threadPool; IceInternal::ACMConfig _acm; IceInternal::ServantManagerPtr _servantManager; - bool _activateOneOffDone; const std::string _name; const std::string _id; const std::string _replicaGroupId; IceInternal::ReferencePtr _reference; std::vector<IceInternal::IncomingConnectionFactoryPtr> _incomingConnectionFactories; - std::vector<IceInternal::ConnectorPtr> _connectors; std::vector<IceInternal::EndpointIPtr> _routerEndpoints; IceInternal::RouterInfoPtr _routerInfo; std::vector<IceInternal::EndpointIPtr> _publishedEndpoints; IceInternal::LocatorInfoPtr _locatorInfo; int _directCount; // The number of direct proxies dispatching on this object adapter. - bool _waitForActivate; - int _waitForHold; - bool _waitForHoldRetry; - bool _destroying; - bool _destroyed; bool _noConfig; Identity _processId; }; diff --git a/cpp/src/Ice/ServantManager.cpp b/cpp/src/Ice/ServantManager.cpp index e4e50a7375f..ba96673ab82 100644 --- a/cpp/src/Ice/ServantManager.cpp +++ b/cpp/src/Ice/ServantManager.cpp @@ -444,9 +444,14 @@ IceInternal::ServantManager::destroy() Ice::LoggerPtr logger; { - IceUtil::Mutex::Lock sync(*this); - - assert(_instance); // Must not be called after destruction. + IceUtil::Mutex::Lock sync(*this); + // + // If the ServantManager has already been destroyed, we're done. + // + if(!_instance) + { + return; + } logger = _instance->initializationData().logger; servantMapMap.swap(_servantMapMap); diff --git a/cpp/src/Ice/ThreadPool.cpp b/cpp/src/Ice/ThreadPool.cpp index a1bb3ab424e..1db49555d9e 100644 --- a/cpp/src/Ice/ThreadPool.cpp +++ b/cpp/src/Ice/ThreadPool.cpp @@ -524,7 +524,11 @@ void IceInternal::ThreadPool::destroy() { Lock sync(*this); - assert(!_destroyed); + if(_destroyed) + { + return; + } + _destroyed = true; _workQueue->destroy(); } |