summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2005-09-06 06:40:06 +0000
committerMatthew Newhook <matthew@zeroc.com>2005-09-06 06:40:06 +0000
commitb08947185374db8a1dc24b5c0c593b844bf8550c (patch)
tree8fe8ef780685d65bd4947c0bb0cbca5479d09d90
parentBug 459. (diff)
downloadice-b08947185374db8a1dc24b5c0c593b844bf8550c.tar.bz2
ice-b08947185374db8a1dc24b5c0c593b844bf8550c.tar.xz
ice-b08947185374db8a1dc24b5c0c593b844bf8550c.zip
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=448
-rw-r--r--cpp/src/Ice/CommunicatorI.cpp159
-rw-r--r--cpp/src/Ice/CommunicatorI.h6
-rw-r--r--cpp/src/Ice/Instance.cpp110
-rw-r--r--cpp/src/Ice/Instance.h11
-rwxr-xr-xcs/src/Ice/Instance.cs93
-rw-r--r--java/src/Ice/CommunicatorI.java159
-rw-r--r--java/src/IceInternal/Instance.java79
7 files changed, 231 insertions, 386 deletions
diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp
index de757ed2cde..47092b0adda 100644
--- a/cpp/src/Ice/CommunicatorI.cpp
+++ b/cpp/src/Ice/CommunicatorI.cpp
@@ -71,19 +71,7 @@ printGCStats(const IceInternal::GCStats& stats)
void
Ice::CommunicatorI::destroy()
{
- InstancePtr instance;
-
- {
- RecMutex::Lock sync(*this);
-
- if(_destroyed) // Don't destroy twice.
- {
- return;
- }
- _destroyed = true;
- instance = _instance;
- }
-
+ if(_instance->destroy())
{
IceUtil::StaticMutex::Lock sync(gcMutex);
@@ -117,91 +105,36 @@ Ice::CommunicatorI::destroy()
theCollector = 0; // Force destruction of the collector.
}
}
-
- if(instance)
- {
- instance->destroy();
- }
}
void
Ice::CommunicatorI::shutdown()
{
- ObjectAdapterFactoryPtr objectAdapterFactory;
-
- {
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
- objectAdapterFactory = _instance->objectAdapterFactory();
- }
-
- //
- // We must call shutdown on the object adapter factory outside the
- // synchronization, otherwise the communicator is blocked during
- // shutdown.
- //
- objectAdapterFactory->shutdown();
+ _instance->objectAdapterFactory()->shutdown();
}
void
Ice::CommunicatorI::waitForShutdown()
{
- ObjectAdapterFactoryPtr objectAdapterFactory;
-
- {
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
- objectAdapterFactory = _instance->objectAdapterFactory();
- }
-
- //
- // We must call waitForShutdown on the object adapter factory
- // outside the synchronization, otherwise the communicator is
- // blocked while we wait for shutdown.
- //
- objectAdapterFactory->waitForShutdown();
+ _instance->objectAdapterFactory()->waitForShutdown();
}
ObjectPrx
Ice::CommunicatorI::stringToProxy(const string& s) const
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
return _instance->proxyFactory()->stringToProxy(s);
}
string
Ice::CommunicatorI::proxyToString(const ObjectPrx& proxy) const
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
return _instance->proxyFactory()->proxyToString(proxy);
}
ObjectAdapterPtr
Ice::CommunicatorI::createObjectAdapter(const string& name)
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
-
- ObjectAdapterPtr adapter = _instance->objectAdapterFactory()->createObjectAdapter(name);
-
- return adapter;
+ return _instance->objectAdapterFactory()->createObjectAdapter(name);
}
ObjectAdapterPtr
@@ -227,163 +160,90 @@ Ice::CommunicatorI::createObjectAdapterWithEndpoints(const string& name, const s
void
Ice::CommunicatorI::addObjectFactory(const ObjectFactoryPtr& factory, const string& id)
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
_instance->servantFactoryManager()->add(factory, id);
}
void
Ice::CommunicatorI::removeObjectFactory(const string& id)
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
_instance->servantFactoryManager()->remove(id);
}
ObjectFactoryPtr
Ice::CommunicatorI::findObjectFactory(const string& id) const
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
return _instance->servantFactoryManager()->find(id);
}
PropertiesPtr
Ice::CommunicatorI::getProperties() const
{
- //
- // No check for destruction. It must be possible to access the
- // properties after destruction.
- //
return _instance->properties();
}
LoggerPtr
Ice::CommunicatorI::getLogger() const
{
- //
- // No check for destruction. It must be possible to access the
- // logger after destruction.
- //
return _instance->logger();
}
void
Ice::CommunicatorI::setLogger(const LoggerPtr& logger)
{
- //
- // No check for destruction. It must be possible to set the logger
- // after destruction (needed by logger plugins for example to
- // unset the logger).
- //
_instance->logger(logger);
}
StatsPtr
Ice::CommunicatorI::getStats() const
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
return _instance->stats();
}
void
Ice::CommunicatorI::setStats(const StatsPtr& stats)
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
_instance->stats(stats);
}
RouterPrx
Ice::CommunicatorI::getDefaultRouter() const
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
return _instance->referenceFactory()->getDefaultRouter();
}
void
Ice::CommunicatorI::setDefaultRouter(const RouterPrx& router)
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
_instance->referenceFactory()->setDefaultRouter(router);
}
LocatorPrx
Ice::CommunicatorI::getDefaultLocator() const
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
return _instance->referenceFactory()->getDefaultLocator();
}
void
Ice::CommunicatorI::setDefaultLocator(const LocatorPrx& locator)
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
_instance->referenceFactory()->setDefaultLocator(locator);
}
void
Ice::CommunicatorI::setDefaultContext(const Context& ctx)
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
_instance->setDefaultContext(ctx);
}
Ice::Context
Ice::CommunicatorI::getDefaultContext() const
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
return _instance->getDefaultContext();
}
PluginManagerPtr
Ice::CommunicatorI::getPluginManager() const
{
- RecMutex::Lock sync(*this);
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
return _instance->pluginManager();
}
@@ -393,20 +253,19 @@ Ice::CommunicatorI::flushBatchRequests()
_instance->flushBatchRequests();
}
-Ice::CommunicatorI::CommunicatorI(const PropertiesPtr& properties) :
- _destroyed(false)
+Ice::CommunicatorI::CommunicatorI(const PropertiesPtr& properties)
{
__setNoDelete(true);
try
{
- _instance = new Instance(this, properties);
+ const_cast<InstancePtr&>(_instance) = new Instance(this, properties);
//
// Keep a reference to the dynamic library list to ensure
// the libraries are not unloaded until this Communicator's
// destructor is invoked.
//
- _dynamicLibraryList = _instance->dynamicLibraryList();
+ const_cast<DynamicLibraryListPtr&>(_dynamicLibraryList) = _instance->dynamicLibraryList();
}
catch(...)
{
@@ -446,8 +305,7 @@ Ice::CommunicatorI::CommunicatorI(const PropertiesPtr& properties) :
Ice::CommunicatorI::~CommunicatorI()
{
- RecMutex::Lock sync(*this);
- if(!_destroyed)
+ if(!_instance->destroyed())
{
Warning out(_instance->logger());
out << "Ice::Communicator::destroy() has not been called";
@@ -476,7 +334,6 @@ Ice::CommunicatorI::finishSetup(int& argc, char* argv[])
}
catch(...)
{
- _destroyed = true;
_instance->destroy();
throw;
}
diff --git a/cpp/src/Ice/CommunicatorI.h b/cpp/src/Ice/CommunicatorI.h
index c74f5ccffa6..483e98ab4fd 100644
--- a/cpp/src/Ice/CommunicatorI.h
+++ b/cpp/src/Ice/CommunicatorI.h
@@ -74,15 +74,13 @@ private:
friend ICE_API CommunicatorPtr initializeWithProperties(int&, char*[], const PropertiesPtr&, Int);
friend ICE_API ::IceInternal::InstancePtr IceInternal::getInstance(const ::Ice::CommunicatorPtr&);
- bool _destroyed;
- ::IceInternal::InstancePtr _instance;
- ::Ice::Context _dfltContext;
+ const ::IceInternal::InstancePtr _instance;
//
// We don't want the dynamic libraries to be unloaded until the
// Communicator's destructor is invoked.
//
- ::IceInternal::DynamicLibraryListPtr _dynamicLibraryList;
+ const ::IceInternal::DynamicLibraryListPtr _dynamicLibraryList;
};
}
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index dd31dc1daf7..4a2c668c51f 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -68,6 +68,13 @@ extern bool ICE_UTIL_API nullHandleAbort;
void IceInternal::incRef(Instance* p) { p->__incRef(); }
void IceInternal::decRef(Instance* p) { p->__decRef(); }
+bool
+IceInternal::Instance::destroyed() const
+{
+ IceUtil::RecMutex::Lock sync(*this);
+ return _state == StateDestroyed;
+}
+
CommunicatorPtr
IceInternal::Instance::communicator() const
{
@@ -77,32 +84,38 @@ IceInternal::Instance::communicator() const
PropertiesPtr
IceInternal::Instance::properties() const
{
+ //
+ // No check for destruction. It must be possible to access the
+ // properties after destruction.
+ //
// No mutex lock, immutable.
+ //
return _properties;
}
LoggerPtr
IceInternal::Instance::logger() const
{
- IceUtil::RecMutex::Lock sync(*this);
//
- // Don't throw CommunicatorDestroyedException if destroyed. We
- // need the logger also after destructions.
+ // No check for destruction. It must be possible to access the
+ // logger after destruction.
//
+
+ IceUtil::RecMutex::Lock sync(*this);
return _logger;
}
void
IceInternal::Instance::logger(const LoggerPtr& logger)
{
- IceUtil::RecMutex::Lock sync(*this);
-
- if(_destroyed)
- {
- throw CommunicatorDestroyedException(__FILE__, __LINE__);
- }
+ //
+ // No check for destruction. It must be possible to set the logger
+ // after destruction (needed by logger plugins for example to
+ // unset the logger).
+ //
+ IceUtil::RecMutex::Lock sync(*this);
_logger = logger;
}
@@ -111,7 +124,7 @@ IceInternal::Instance::stats() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -124,7 +137,7 @@ IceInternal::Instance::stats(const StatsPtr& stats)
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -151,7 +164,7 @@ IceInternal::Instance::routerManager() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -164,7 +177,7 @@ IceInternal::Instance::locatorManager() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -177,7 +190,7 @@ IceInternal::Instance::referenceFactory() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -190,7 +203,7 @@ IceInternal::Instance::proxyFactory() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -203,7 +216,7 @@ IceInternal::Instance::outgoingConnectionFactory() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -216,7 +229,7 @@ IceInternal::Instance::connectionMonitor() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -229,7 +242,7 @@ IceInternal::Instance::servantFactoryManager() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -242,7 +255,7 @@ IceInternal::Instance::objectAdapterFactory() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -255,7 +268,7 @@ IceInternal::Instance::clientThreadPool()
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -273,7 +286,7 @@ IceInternal::Instance::serverThreadPool()
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -306,7 +319,7 @@ IceInternal::Instance::endpointFactoryManager() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -319,7 +332,7 @@ IceInternal::Instance::dynamicLibraryList() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -332,7 +345,7 @@ IceInternal::Instance::pluginManager() const
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -370,7 +383,7 @@ IceInternal::Instance::flushBatchRequests()
{
IceUtil::RecMutex::Lock sync(*this);
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
@@ -386,19 +399,33 @@ IceInternal::Instance::flushBatchRequests()
void
IceInternal::Instance::setDefaultContext(const Context& ctx)
{
+ IceUtil::RecMutex::Lock sync(*this);
+
+ if(_state == StateDestroyed)
+ {
+ throw CommunicatorDestroyedException(__FILE__, __LINE__);
+ }
+
_defaultContext = ctx;
}
const Context&
IceInternal::Instance::getDefaultContext() const
{
+ IceUtil::RecMutex::Lock sync(*this);
+
+ if(_state == StateDestroyed)
+ {
+ throw CommunicatorDestroyedException(__FILE__, __LINE__);
+ }
+
return _defaultContext;
}
IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const PropertiesPtr& properties) :
_communicator(communicator.get()),
- _destroyed(false),
+ _state(StateActive),
_properties(properties),
_messageSizeMax(0),
_clientACM(0),
@@ -406,7 +433,6 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope
_threadPerConnection(false),
_threadPerConnectionStackSize(0)
{
-
try
{
__setNoDelete(true);
@@ -641,7 +667,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope
IceInternal::Instance::~Instance()
{
- assert(_destroyed);
+ assert(_state == StateDestroyed);
assert(!_referenceFactory);
assert(!_proxyFactory);
assert(!_outgoingConnectionFactory);
@@ -761,10 +787,29 @@ IceInternal::Instance::finishSetup(int& argc, char* argv[])
//
}
-void
+bool
IceInternal::Instance::destroy()
{
- assert(!_destroyed);
+ {
+ IceUtil::RecMutex::Lock sync(*this);
+
+ //
+ // If the _state is not StateActive then the instance is
+ // either being destroyed, or has already been destroyed.
+ //
+ if(_state != StateActive)
+ {
+ return false;
+ }
+
+ //
+ // We cannot set state to StateDestroyed otherwise instance
+ // methods called during the destroy process (such as
+ // outgoingConnectionFactory() from
+ // ObjectAdapterI::deactivate() will cause an exception.
+ //
+ _state = StateDestroyInProgress;
+ }
if(_objectAdapterFactory)
{
@@ -857,7 +902,7 @@ IceInternal::Instance::destroy()
// _dynamicLibraryList->destroy();
_dynamicLibraryList = 0;
- _destroyed = true;
+ _state = StateDestroyed;
}
//
@@ -870,5 +915,6 @@ IceInternal::Instance::destroy()
if(serverThreadPool)
{
serverThreadPool->joinWithAllThreads();
- }
+ }
+ return true;
}
diff --git a/cpp/src/Ice/Instance.h b/cpp/src/Ice/Instance.h
index ca0b971282a..d54d838e1d3 100644
--- a/cpp/src/Ice/Instance.h
+++ b/cpp/src/Ice/Instance.h
@@ -48,6 +48,7 @@ class Instance : public IceUtil::Shared, public IceUtil::RecMutex
{
public:
+ bool destroyed() const;
Ice::CommunicatorPtr communicator() const;
Ice::PropertiesPtr properties() const;
Ice::LoggerPtr logger() const;
@@ -83,11 +84,17 @@ private:
Instance(const Ice::CommunicatorPtr&, const Ice::PropertiesPtr&);
virtual ~Instance();
void finishSetup(int&, char*[]);
- void destroy();
+ bool destroy();
friend class Ice::CommunicatorI;
Ice::Communicator* _communicator; // Not a Ptr, to avoid having Instance and CommunicatorI point at each other.
- bool _destroyed;
+ enum State
+ {
+ StateActive,
+ StateDestroyInProgress,
+ StateDestroyed
+ };
+ State _state;
const Ice::PropertiesPtr _properties; // Immutable, not reset by destroy().
Ice::LoggerPtr _logger; // Not reset by destroy().
Ice::StatsPtr _stats; // Not reset by destroy().
diff --git a/cs/src/Ice/Instance.cs b/cs/src/Ice/Instance.cs
index 64ee23a5ecd..01c88838fe8 100755
--- a/cs/src/Ice/Instance.cs
+++ b/cs/src/Ice/Instance.cs
@@ -14,6 +14,11 @@ namespace IceInternal
public sealed class Instance
{
+ public bool destroyed()
+ {
+ return _state == StateDestroyed;
+ }
+
public Ice.Communicator communicator()
{
return _communicator;
@@ -21,7 +26,12 @@ namespace IceInternal
public Ice.Properties properties()
{
- // No mutex lock, immutable.
+ //
+ // No check for destruction. It must be possible to access the
+ // properties after destruction.
+ //
+ // No mutex lock, immutable.
+ //
return _properties;
}
@@ -29,9 +39,9 @@ namespace IceInternal
{
lock(this)
{
- //
- // Don't throw CommunicatorDestroyedException if destroyed. We
- // need the logger also after destructions.
+ //
+ // No check for destruction. It must be possible to access the
+ // logger after destruction.
//
return _logger;
}
@@ -41,11 +51,11 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
- {
- throw new Ice.CommunicatorDestroyedException();
- }
-
+ //
+ // No check for destruction. It must be possible to set the
+ // logger after destruction (needed by logger plugins for
+ // example to unset the logger).
+ //
_logger = logger;
}
}
@@ -54,7 +64,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -67,7 +77,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -92,7 +102,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -105,7 +115,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -118,7 +128,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -131,7 +141,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -144,7 +154,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -157,7 +167,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -170,7 +180,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -183,7 +193,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -196,7 +206,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -214,7 +224,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -234,7 +244,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -247,7 +257,7 @@ namespace IceInternal
{
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -298,7 +308,7 @@ namespace IceInternal
lock(this)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -317,7 +327,7 @@ namespace IceInternal
public Instance(Ice.Communicator communicator, Ice.Properties properties)
{
_communicator = communicator;
- _destroyed = false;
+ _state = StateActive;
_properties = properties;
try
@@ -462,7 +472,7 @@ namespace IceInternal
{
lock(this)
{
- IceUtil.Assert.FinalizerAssert(_destroyed);
+ IceUtil.Assert.FinalizerAssert(_state == StateDestroyed);
IceUtil.Assert.FinalizerAssert(_referenceFactory == null);
IceUtil.Assert.FinalizerAssert(_proxyFactory == null);
IceUtil.Assert.FinalizerAssert(_outgoingConnectionFactory == null);
@@ -554,9 +564,27 @@ namespace IceInternal
//
// Only for use by Ice.CommunicatorI
//
- public void destroy()
+ public bool destroy()
{
- Debug.Assert(!_destroyed);
+ lock(this)
+ {
+ //
+ // If the _state is not StateActive then the instance is
+ // either being destroyed, or has already been destroyed.
+ //
+ if(_state != StateActive)
+ {
+ return false;
+ }
+
+ //
+ // We cannot set state to StateDestroyed otherwise instance
+ // methods called during the destroy process (such as
+ // outgoingConnectionFactory() from
+ // ObjectAdapterI::deactivate() will cause an exception.
+ //
+ _state = StateDestroyInProgress;
+ }
if(_objectAdapterFactory != null)
{
@@ -647,7 +675,7 @@ namespace IceInternal
_pluginManager = null;
}
- _destroyed = true;
+ _state = StateDestroyed;
}
//
@@ -662,10 +690,15 @@ namespace IceInternal
{
serverThreadPool.joinWithAllThreads();
}
+
+ return true;
}
private Ice.Communicator _communicator;
- private bool _destroyed;
+ private const int StateActive = 0;
+ private const int StateDestroyInProgress = 1;
+ private const int StateDestroyed = 2;
+ private int _state;
private Ice.Properties _properties; // Immutable, not reset by destroy().
private Ice.Logger _logger; // Not reset by destroy().
private Ice.Stats _stats; // Not reset by destroy().
diff --git a/java/src/Ice/CommunicatorI.java b/java/src/Ice/CommunicatorI.java
index 19ef3d103e0..d041bddd45e 100644
--- a/java/src/Ice/CommunicatorI.java
+++ b/java/src/Ice/CommunicatorI.java
@@ -14,96 +14,36 @@ public final class CommunicatorI extends LocalObjectImpl implements Communicator
public void
destroy()
{
- IceInternal.Instance instance = null;
-
- synchronized(this)
- {
- if(_destroyed) // Don't destroy twice.
- {
- return;
- }
- _destroyed = true;
- instance = _instance;
- }
-
- if(instance != null)
- {
- instance.destroy();
- }
+ _instance.destroy();
}
public void
shutdown()
{
- IceInternal.ObjectAdapterFactory objectAdapterFactory;
-
- synchronized(this)
- {
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
- objectAdapterFactory = _instance.objectAdapterFactory();
- }
-
- //
- // We must call shutdown on the object adapter factory
- // outside the synchronization, otherwise the communicator is
- // blocked while we wait for shutdown.
- //
- objectAdapterFactory.shutdown();
+ _instance.objectAdapterFactory().shutdown();
}
public void
waitForShutdown()
{
- IceInternal.ObjectAdapterFactory objectAdapterFactory;
-
- synchronized(this)
- {
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
- objectAdapterFactory = _instance.objectAdapterFactory();
- }
-
- //
- // We must call waitForShutdown on the object adapter factory
- // outside the synchronization, otherwise the communicator is
- // blocked while we wait for shutdown.
- //
- objectAdapterFactory.waitForShutdown();
+ _instance.objectAdapterFactory().waitForShutdown();
}
- public synchronized Ice.ObjectPrx
+ public Ice.ObjectPrx
stringToProxy(String s)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
return _instance.proxyFactory().stringToProxy(s);
}
- public synchronized String
+ public String
proxyToString(Ice.ObjectPrx proxy)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
return _instance.proxyFactory().proxyToString(proxy);
}
- public synchronized ObjectAdapter
+ public ObjectAdapter
createObjectAdapter(String name)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
-
return _instance.objectAdapterFactory().createObjectAdapter(name);
}
@@ -119,6 +59,7 @@ public final class CommunicatorI extends LocalObjectImpl implements Communicator
}
catch(AlreadyRegisteredException ex)
{
+ // XXX: Why this?
if(originalValue.length() != 0)
{
getProperties().setProperty(propertyKey, originalValue);
@@ -127,144 +68,87 @@ public final class CommunicatorI extends LocalObjectImpl implements Communicator
}
}
- public synchronized void
+ public void
addObjectFactory(ObjectFactory factory, String id)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
_instance.servantFactoryManager().add(factory, id);
}
- public synchronized void
+ public void
removeObjectFactory(String id)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
_instance.servantFactoryManager().remove(id);
}
- public synchronized ObjectFactory
+ public ObjectFactory
findObjectFactory(String id)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
return _instance.servantFactoryManager().find(id);
}
public Properties
getProperties()
{
- //
- // No check for destruction. It must be possible to access the
- // properties after destruction.
- //
return _instance.properties();
}
public Logger
getLogger()
{
- //
- // No check for destruction. It must be possible to access the
- // logger after destruction.
- //
return _instance.logger();
}
public void
setLogger(Logger logger)
{
- //
- // No check for destruction. It must be possible to set the
- // logger after destruction (needed by logger plugins for
- // example to unset the logger).
- //
_instance.logger(logger);
}
- public synchronized Stats
+ public Stats
getStats()
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
return _instance.stats();
}
- public synchronized void
+ public void
setStats(Stats stats)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
_instance.stats(stats);
}
- public synchronized RouterPrx
+ public RouterPrx
getDefaultRouter()
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
return _instance.referenceFactory().getDefaultRouter();
}
- public synchronized void
+ public void
setDefaultRouter(RouterPrx router)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
_instance.referenceFactory().setDefaultRouter(router);
}
- public synchronized LocatorPrx
+ public LocatorPrx
getDefaultLocator()
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
return _instance.referenceFactory().getDefaultLocator();
}
- public synchronized void
+ public void
setDefaultLocator(LocatorPrx locator)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
_instance.referenceFactory().setDefaultLocator(locator);
}
- public synchronized java.util.Map
+ public java.util.Map
getDefaultContext()
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
return _instance.getDefaultContext();
}
- public synchronized void
+ public void
setDefaultContext(java.util.Map ctx)
{
- if(_destroyed)
- {
- throw new CommunicatorDestroyedException();
- }
_instance.setDefaultContext(ctx);
}
@@ -282,7 +166,6 @@ public final class CommunicatorI extends LocalObjectImpl implements Communicator
CommunicatorI(Properties properties)
{
- _destroyed = false;
_instance = new IceInternal.Instance(this, properties);
}
@@ -317,11 +200,6 @@ public final class CommunicatorI extends LocalObjectImpl implements Communicator
catch(RuntimeException ex)
{
_instance.destroy();
- _instance = null;
- synchronized(this)
- {
- _destroyed = true;
- }
throw ex;
}
}
@@ -335,6 +213,5 @@ public final class CommunicatorI extends LocalObjectImpl implements Communicator
return _instance;
}
- private boolean _destroyed;
private IceInternal.Instance _instance;
}
diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java
index 4646c9123ac..3cfa5dd9718 100644
--- a/java/src/IceInternal/Instance.java
+++ b/java/src/IceInternal/Instance.java
@@ -19,7 +19,12 @@ public final class Instance
public Ice.Properties
properties()
{
+ //
+ // No check for destruction. It must be possible to access the
+ // properties after destruction.
+ //
// No mutex lock, immutable.
+ //
return _properties;
}
@@ -36,18 +41,18 @@ public final class Instance
public synchronized void
logger(Ice.Logger logger)
{
- if(_destroyed)
- {
- throw new Ice.CommunicatorDestroyedException();
- }
-
+ //
+ // No check for destruction. It must be possible to set the
+ // logger after destruction (needed by logger plugins for
+ // example to unset the logger).
+ //
_logger = logger;
}
public synchronized Ice.Stats
stats()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -58,7 +63,7 @@ public final class Instance
public synchronized void
stats(Ice.Stats stats)
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -83,7 +88,7 @@ public final class Instance
public synchronized RouterManager
routerManager()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -94,7 +99,7 @@ public final class Instance
public synchronized LocatorManager
locatorManager()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -105,7 +110,7 @@ public final class Instance
public synchronized ReferenceFactory
referenceFactory()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -116,7 +121,7 @@ public final class Instance
public synchronized ProxyFactory
proxyFactory()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -127,7 +132,7 @@ public final class Instance
public synchronized OutgoingConnectionFactory
outgoingConnectionFactory()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -138,7 +143,7 @@ public final class Instance
public synchronized ConnectionMonitor
connectionMonitor()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -149,7 +154,7 @@ public final class Instance
public synchronized ObjectFactoryManager
servantFactoryManager()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -160,7 +165,7 @@ public final class Instance
public synchronized ObjectAdapterFactory
objectAdapterFactory()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -171,7 +176,7 @@ public final class Instance
public synchronized ThreadPool
clientThreadPool()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -187,7 +192,7 @@ public final class Instance
public synchronized ThreadPool
serverThreadPool()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -216,7 +221,7 @@ public final class Instance
public synchronized EndpointFactoryManager
endpointFactoryManager()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -227,7 +232,7 @@ public final class Instance
public synchronized Ice.PluginManager
pluginManager()
{
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -283,8 +288,7 @@ public final class Instance
synchronized(this)
{
-
- if(_destroyed)
+ if(_state == StateDestroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
@@ -304,7 +308,7 @@ public final class Instance
Instance(Ice.Communicator communicator, Ice.Properties properties)
{
_communicator = communicator;
- _destroyed = false;
+ _state = StateActive;
_properties = properties;
try
@@ -471,7 +475,7 @@ public final class Instance
finalize()
throws Throwable
{
- IceUtil.Assert.FinalizerAssert(_destroyed);
+ IceUtil.Assert.FinalizerAssert(_state == StateDestroyed);
IceUtil.Assert.FinalizerAssert(_referenceFactory == null);
IceUtil.Assert.FinalizerAssert(_proxyFactory == null);
IceUtil.Assert.FinalizerAssert(_outgoingConnectionFactory == null);
@@ -555,7 +559,25 @@ public final class Instance
public void
destroy()
{
- assert(!_destroyed);
+ synchronized(this)
+ {
+ //
+ // If the _state is not StateActive then the instance is
+ // either being destroyed, or has already been destroyed.
+ //
+ if(_state != StateActive)
+ {
+ return;
+ }
+
+ //
+ // We cannot set state to StateDestroyed otherwise instance
+ // methods called during the destroy process (such as
+ // outgoingConnectionFactory() from
+ // ObjectAdapterI::deactivate() will cause an exception.
+ //
+ _state = StateDestroyInProgress;
+ }
if(_objectAdapterFactory != null)
{
@@ -646,7 +668,7 @@ public final class Instance
_pluginManager = null;
}
- _destroyed = true;
+ _state = StateDestroyed;
}
//
@@ -692,7 +714,12 @@ public final class Instance
}
private Ice.Communicator _communicator;
- private boolean _destroyed;
+
+ private static final int StateActive = 0;
+ private static final int StateDestroyInProgress = 1;
+ private static final int StateDestroyed = 2;
+ private int _state;
+
private final Ice.Properties _properties; // Immutable, not reset by destroy().
private Ice.Logger _logger; // Not reset by destroy().
private Ice.Stats _stats; // Not reset by destroy().