summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp/src/Ice/ObjectAdapterFactory.cpp40
-rw-r--r--cpp/src/Ice/ObjectAdapterFactory.h1
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp72
-rw-r--r--cpp/src/Ice/ObjectAdapterI.h1
-rw-r--r--java/src/Ice/ObjectAdapterI.java80
-rw-r--r--java/src/IceInternal/ObjectAdapterFactory.java47
6 files changed, 167 insertions, 74 deletions
diff --git a/cpp/src/Ice/ObjectAdapterFactory.cpp b/cpp/src/Ice/ObjectAdapterFactory.cpp
index b4419cf68ce..eb3715dc38a 100644
--- a/cpp/src/Ice/ObjectAdapterFactory.cpp
+++ b/cpp/src/Ice/ObjectAdapterFactory.cpp
@@ -50,14 +50,26 @@ IceInternal::ObjectAdapterFactory::shutdown()
void
IceInternal::ObjectAdapterFactory::waitForShutdown()
{
- IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
-
- //
- // First we wait for the shutdown of the factory itself.
- //
- while(_instance)
{
- wait();
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
+
+ //
+ // First we wait for the shutdown of the factory itself.
+ //
+ while(_instance)
+ {
+ wait();
+ }
+
+ //
+ // If some other thread is currently shutting down, we wait
+ // until this thread is finished.
+ //
+ while(_waitForShutdown)
+ {
+ wait();
+ }
+ _waitForShutdown = true;
}
//
@@ -70,6 +82,16 @@ IceInternal::ObjectAdapterFactory::waitForShutdown()
// We're done, now we can throw away the object adapters.
//
_adapters.clear();
+
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
+
+ //
+ // Signal that waiting is complete.
+ //
+ _waitForShutdown = false;
+ notifyAll();
+ }
}
ObjectAdapterPtr
@@ -124,7 +146,8 @@ IceInternal::ObjectAdapterFactory::findObjectAdapter(const ObjectPrx& proxy)
IceInternal::ObjectAdapterFactory::ObjectAdapterFactory(const InstancePtr& instance,
const CommunicatorPtr& communicator) :
_instance(instance),
- _communicator(communicator)
+ _communicator(communicator),
+ _waitForShutdown(false)
{
}
@@ -133,4 +156,5 @@ IceInternal::ObjectAdapterFactory::~ObjectAdapterFactory()
assert(!_instance);
assert(!_communicator);
assert(_adapters.empty());
+ assert(!_waitForShutdown);
}
diff --git a/cpp/src/Ice/ObjectAdapterFactory.h b/cpp/src/Ice/ObjectAdapterFactory.h
index 5473a990c8a..7af6b0f6abb 100644
--- a/cpp/src/Ice/ObjectAdapterFactory.h
+++ b/cpp/src/Ice/ObjectAdapterFactory.h
@@ -41,6 +41,7 @@ private:
InstancePtr _instance;
::Ice::CommunicatorPtr _communicator;
std::map<std::string, ::Ice::ObjectAdapterIPtr> _adapters;
+ bool _waitForShutdown;
};
}
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index f8a3311173e..09f94d1b1ff 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -164,8 +164,6 @@ Ice::ObjectAdapterI::deactivate()
void
Ice::ObjectAdapterI::waitForDeactivate()
{
- map<string, ServantLocatorPtr> locatorMap;
-
{
IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
@@ -179,38 +177,39 @@ Ice::ObjectAdapterI::waitForDeactivate()
}
//
- // Now we wait for until all incoming connection factories are
- // finished.
- //
- for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(),
- Ice::voidMemFun(&IncomingConnectionFactory::waitUntilFinished));
-
- //
- // We're done, now we can throw away all incoming connection
- // factories.
+ // If some other thread is currently deactivating, we wait
+ // until this thread is finished.
//
- _incomingConnectionFactories.clear();
+ while(_waitForDeactivate)
+ {
+ wait();
+ }
+ _waitForDeactivate = true;
+ }
- //
- // Now it's also time to clean up the active servant map.
- //
- _activeServantMap.clear();
- _activeServantMapHint = _activeServantMap.end();
+ //
+ // Now we wait for until all incoming connection factories are
+ // finished.
+ //
+ for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(),
+ Ice::voidMemFun(&IncomingConnectionFactory::waitUntilFinished));
+
+ //
+ // We're done, now we can throw away all incoming connection
+ // factories.
+ //
+ _incomingConnectionFactories.clear();
- //
- // And the servant locators, too (first we make a copy of the
- // map in order to invoke servant locator deactivate method
- // outside the synchronization block).
- //
- locatorMap = _locatorMap;
- _locatorMap.clear();
- _locatorMapHint = _locatorMap.end();
- }
+ //
+ // Now it's also time to clean up the active servant map.
+ //
+ _activeServantMap.clear();
+ _activeServantMapHint = _activeServantMap.end();
//
- // Deactivate servant locators.
+ // And the servant locators, too.
//
- for(map<string, ServantLocatorPtr>::iterator p = locatorMap.begin(); p != locatorMap.end(); ++p)
+ for(map<string, ServantLocatorPtr>::iterator p = _locatorMap.begin(); p != _locatorMap.end(); ++p)
{
try
{
@@ -232,6 +231,19 @@ Ice::ObjectAdapterI::waitForDeactivate()
<< "locator prefix: `" << p->first << "'";
}
}
+
+ _locatorMap.clear();
+ _locatorMapHint = _locatorMap.end();
+
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
+
+ //
+ // Signal that waiting is complete.
+ //
+ _waitForDeactivate = false;
+ notifyAll();
+ }
}
ObjectPrx
@@ -581,7 +593,8 @@ Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const Communica
_logger(instance->logger()),
_activeServantMapHint(_activeServantMap.end()),
_locatorMapHint(_locatorMap.end()),
- _directCount(0)
+ _directCount(0),
+ _waitForDeactivate(false)
{
string s(endpts);
transform(s.begin(), s.end(), s.begin(), ::tolower);
@@ -649,6 +662,7 @@ Ice::ObjectAdapterI::~ObjectAdapterI()
assert(_activeServantMap.empty());
assert(_locatorMap.empty());
assert(_directCount == 0);
+ assert(!_waitForDeactivate);
}
}
diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h
index de2f08459bf..e76ac920d76 100644
--- a/cpp/src/Ice/ObjectAdapterI.h
+++ b/cpp/src/Ice/ObjectAdapterI.h
@@ -102,6 +102,7 @@ private:
IceUtil::Mutex _routerEndpointsMutex;
::IceInternal::LocatorInfoPtr _locatorInfo;
int _directCount; // The number of direct proxies dispatching on this object adapter.
+ bool _waitForDeactivate;
};
}
diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java
index 097e53c9cb5..bccbf33da4d 100644
--- a/java/src/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/ObjectAdapterI.java
@@ -150,8 +150,6 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
public void
waitForDeactivate()
{
- java.util.HashMap locatorMap;
-
synchronized(this)
{
//
@@ -169,40 +167,52 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
{
}
}
-
+
//
- // Now we wait for until all incoming connection factories are
- // finished.
+ // If some other thread is currently deactivating, we wait
+ // until this thread is finished.
//
- final int sz = _incomingConnectionFactories.size();
- for(int i = 0; i < sz; ++i)
+ while(_waitForDeactivate)
{
- IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
- factory.waitUntilFinished();
+ try
+ {
+ wait();
+ }
+ catch(InterruptedException ex)
+ {
+ }
}
-
- //
- // We're done, now we can throw away all incoming connection
- // factories.
- //
- _incomingConnectionFactories.clear();
+ _waitForDeactivate = true;
+ }
- //
- // Now it's also time to clean up the active servant map.
- //
- _activeServantMap.clear();
- //
- // And the servant locators, too (first we make a copy of
- // the map in order to invoke servant locator deactivate
- // method outside the synchronization block).
- //
- locatorMap = new java.util.HashMap(_locatorMap);
- _locatorMap.clear();
+ //
+ // Now we wait for until all incoming connection factories are
+ // finished.
+ //
+ final int sz = _incomingConnectionFactories.size();
+ for(int i = 0; i < sz; ++i)
+ {
+ IceInternal.IncomingConnectionFactory factory =
+ (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
+ factory.waitUntilFinished();
}
-
- java.util.Iterator p = locatorMap.entrySet().iterator();
+
+ //
+ // We're done, now we can throw away all incoming connection
+ // factories.
+ //
+ _incomingConnectionFactories.clear();
+
+ //
+ // Now it's also time to clean up the active servant map.
+ //
+ _activeServantMap.clear();
+
+ //
+ // And the servant locators, too.
+ //
+ java.util.Iterator p = _locatorMap.entrySet().iterator();
while(p.hasNext())
{
java.util.Map.Entry e = (java.util.Map.Entry)p.next();
@@ -222,6 +232,15 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
_logger.error(s);
}
}
+
+ synchronized(this)
+ {
+ //
+ // Signal that waiting is complete.
+ //
+ _waitForDeactivate = false;
+ notifyAll();
+ }
}
public synchronized ObjectPrx
@@ -503,6 +522,7 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
_id = id;
_logger = instance.logger();
_directCount = 0;
+ _waitForDeactivate = false;
String s = endpts.toLowerCase();
@@ -564,6 +584,7 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
assert(_activeServantMap.size() == 0);
assert(_locatorMap.size() == 0);
assert(_directCount == 0);
+ assert(!_waitForDeactivate);
}
super.finalize();
@@ -743,4 +764,5 @@ public class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapter
private java.util.ArrayList _routerEndpoints = new java.util.ArrayList();
private IceInternal.LocatorInfo _locatorInfo;
private int _directCount;
+ private boolean _waitForDeactivate;
}
diff --git a/java/src/IceInternal/ObjectAdapterFactory.java b/java/src/IceInternal/ObjectAdapterFactory.java
index 518d16932bd..a5bc4dab828 100644
--- a/java/src/IceInternal/ObjectAdapterFactory.java
+++ b/java/src/IceInternal/ObjectAdapterFactory.java
@@ -41,21 +41,40 @@ public final class ObjectAdapterFactory
notifyAll();
}
- public synchronized void
+ public void
waitForShutdown()
{
- //
- // First we wait for the shutdown of the factory itself.
- //
- while(_instance != null)
+ synchronized(this)
{
- try
+ //
+ // First we wait for the shutdown of the factory itself.
+ //
+ while(_instance != null)
{
- wait();
+ try
+ {
+ wait();
+ }
+ catch(InterruptedException ex)
+ {
+ }
}
- catch(InterruptedException ex)
+
+ //
+ // If some other thread is currently shutting down, we wait
+ // until this thread is finished.
+ //
+ while(_waitForShutdown)
{
+ try
+ {
+ wait();
+ }
+ catch(InterruptedException ex)
+ {
+ }
}
+ _waitForShutdown = true;
}
//
@@ -72,6 +91,15 @@ public final class ObjectAdapterFactory
// We're done, now we can throw away the object adapters.
//
_adapters.clear();
+
+ synchronized(this)
+ {
+ //
+ // Signal that waiting is complete.
+ //
+ _waitForShutdown = false;
+ notifyAll();
+ }
}
public synchronized Ice.ObjectAdapter
@@ -128,6 +156,7 @@ public final class ObjectAdapterFactory
{
_instance = instance;
_communicator = communicator;
+ _waitForShutdown = false;
}
protected void
@@ -137,6 +166,7 @@ public final class ObjectAdapterFactory
assert(_instance == null);
assert(_communicator == null);
assert(_adapters.size() == 0);
+ assert(!_waitForShutdown);
super.finalize();
}
@@ -144,4 +174,5 @@ public final class ObjectAdapterFactory
private Instance _instance;
private Ice.Communicator _communicator;
private java.util.HashMap _adapters = new java.util.HashMap();
+ private boolean _waitForShutdown;
}