diff options
author | Matthew Newhook <matthew@zeroc.com> | 2005-09-07 05:40:22 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2005-09-07 05:40:22 +0000 |
commit | c943fb0d16b7c9edcfbd20199126544bc65ddf7b (patch) | |
tree | 5017a9c8a031e1999a5b985d9d9d22189cb6de8b | |
parent | Changed version to 3.0.0. Fixed a few places where we could clean up (diff) | |
download | ice-c943fb0d16b7c9edcfbd20199126544bc65ddf7b.tar.bz2 ice-c943fb0d16b7c9edcfbd20199126544bc65ddf7b.tar.xz ice-c943fb0d16b7c9edcfbd20199126544bc65ddf7b.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=448
-rw-r--r-- | cppe/src/IceE/Instance.cpp | 9 | ||||
-rw-r--r-- | cppe/src/IceE/Instance.h | 2 | ||||
-rw-r--r-- | cppe/src/IceE/Reference.cpp | 98 | ||||
-rw-r--r-- | cppe/src/IceE/Reference.h | 22 | ||||
-rw-r--r-- | cppe/src/IceE/ReferenceFactory.cpp | 18 | ||||
-rw-r--r-- | cppe/src/IceE/ReferenceFactory.h | 3 | ||||
-rw-r--r-- | javae/src/Ice/Communicator.java | 132 | ||||
-rw-r--r-- | javae/src/IceInternal/DirectReference.java | 3 | ||||
-rw-r--r-- | javae/src/IceInternal/FixedReference.java | 3 | ||||
-rw-r--r-- | javae/src/IceInternal/IndirectReference.java | 3 | ||||
-rw-r--r-- | javae/src/IceInternal/Instance.java | 76 | ||||
-rw-r--r-- | javae/src/IceInternal/Reference.java | 5 | ||||
-rw-r--r-- | javae/src/IceInternal/ReferenceFactory.java | 14 | ||||
-rw-r--r-- | javae/src/IceInternal/RoutableReference.java | 3 |
14 files changed, 162 insertions, 229 deletions
diff --git a/cppe/src/IceE/Instance.cpp b/cppe/src/IceE/Instance.cpp index 5009ed783af..8b088291025 100644 --- a/cppe/src/IceE/Instance.cpp +++ b/cppe/src/IceE/Instance.cpp @@ -65,12 +65,6 @@ IceInternal::Instance::destroyed() const return _state == StateDestroyed; } -CommunicatorPtr -IceInternal::Instance::communicator() const -{ - return _communicator; -} - PropertiesPtr IceInternal::Instance::properties() const { @@ -294,7 +288,6 @@ IceInternal::Instance::getDefaultContext() const } IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const PropertiesPtr& properties) : - _communicator(communicator.get()), _state(StateActive), _properties(properties), _messageSizeMax(0), @@ -462,7 +455,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope _locatorManager = new LocatorManager; #endif - _referenceFactory = new ReferenceFactory(this); + _referenceFactory = new ReferenceFactory(this, communicator); _proxyFactory = new ProxyFactory(this); diff --git a/cppe/src/IceE/Instance.h b/cppe/src/IceE/Instance.h index e7a68f230c4..16e1bbc1c33 100644 --- a/cppe/src/IceE/Instance.h +++ b/cppe/src/IceE/Instance.h @@ -36,7 +36,6 @@ class Instance : public IceUtil::Shared, public IceUtil::RecMutex public: bool destroyed() const; - Ice::CommunicatorPtr communicator() const; Ice::PropertiesPtr properties() const; Ice::LoggerPtr logger() const; void logger(const Ice::LoggerPtr&); @@ -74,7 +73,6 @@ private: void destroy(); friend class Ice::Communicator; - Ice::Communicator* _communicator; // Not a Ptr, to avoid having Instance and Communicator point at each other. enum State { StateActive, diff --git a/cppe/src/IceE/Reference.cpp b/cppe/src/IceE/Reference.cpp index e470a334fee..f45c1f95dad 100644 --- a/cppe/src/IceE/Reference.cpp +++ b/cppe/src/IceE/Reference.cpp @@ -61,7 +61,7 @@ IceInternal::Reference::defaultContext() const CommunicatorPtr IceInternal::Reference::getCommunicator() const { - return _instance->communicator(); + return _communicator; } ReferencePtr @@ -404,38 +404,40 @@ IceInternal::Reference::operator<(const Reference& r) const return false; } -IceInternal::Reference::Reference(const InstancePtr& inst, const Identity& ident, const Context& ctx, - const string& fs, Mode md, bool sec) - : _instance(inst), - _mode(md), - _secure(sec), - _identity(ident), - _hasContext(!ctx.empty()), - _context(ctx), - _facet(fs), - _hashInitialized(false) +IceInternal::Reference::Reference(const InstancePtr& inst, const CommunicatorPtr& com, const Identity& ident, + const Context& ctx, const string& fs, Mode md, bool sec) : + _instance(inst), + _communicator(com), + _mode(md), + _secure(sec), + _identity(ident), + _hasContext(!ctx.empty()), + _context(ctx), + _facet(fs), + _hashInitialized(false) { } -IceInternal::Reference::Reference(const Reference& r) - : _instance(r._instance), - _mode(r._mode), - _secure(r._secure), - _identity(r._identity), - _hasContext(r._hasContext), - _context(r._context), - _facet(r._facet), - _hashInitialized(false) +IceInternal::Reference::Reference(const Reference& r) : + _instance(r._instance), + _communicator(r._communicator), + _mode(r._mode), + _secure(r._secure), + _identity(r._identity), + _hasContext(r._hasContext), + _context(r._context), + _facet(r._facet), + _hashInitialized(false) { } void IceInternal::incRef(IceInternal::FixedReference* p) { p->__incRef(); } void IceInternal::decRef(IceInternal::FixedReference* p) { p->__decRef(); } -IceInternal::FixedReference::FixedReference(const InstancePtr& inst, const Identity& ident, +IceInternal::FixedReference::FixedReference(const InstancePtr& inst, const CommunicatorPtr& com, const Identity& ident, const Context& ctx, const string& fs, Mode md, const vector<ConnectionPtr>& fixedConns) - : Reference(inst, ident, ctx, fs, md, false), + : Reference(inst, com, ident, ctx, fs, md, false), _fixedConnections(fixedConns) { } @@ -683,10 +685,10 @@ IceInternal::RoutableReference::operator<(const Reference& r) const return false; } -IceInternal::RoutableReference::RoutableReference(const InstancePtr& inst, const Identity& ident, - const Context& ctx, const string& fs, Mode md, - bool sec, const RouterInfoPtr& rtrInfo) - : Reference(inst, ident, ctx, fs, md, sec), _routerInfo(rtrInfo) +IceInternal::RoutableReference::RoutableReference(const InstancePtr& inst, const CommunicatorPtr& com, + const Identity& ident, const Context& ctx, const string& fs, + Mode md, bool sec, const RouterInfoPtr& rtrInfo) + : Reference(inst, com, ident, ctx, fs, md, sec), _routerInfo(rtrInfo) { } @@ -701,19 +703,20 @@ void IceInternal::decRef(IceInternal::DirectReference* p) { p->__decRef(); } #ifdef ICEE_HAS_ROUTER -IceInternal::DirectReference::DirectReference(const InstancePtr& inst, const Identity& ident, - const Context& ctx, const string& fs, Mode md, bool sec, - const vector<EndpointPtr>& endpts, const RouterInfoPtr& rtrInfo) : +IceInternal::DirectReference::DirectReference(const InstancePtr& inst, const CommunicatorPtr& com, + const Identity& ident, const Context& ctx, const string& fs, Mode md, + bool sec, const vector<EndpointPtr>& endpts, + const RouterInfoPtr& rtrInfo) : - RoutableReference(inst, ident, ctx, fs, md, sec, rtrInfo), + RoutableReference(inst, com, ident, ctx, fs, md, sec, rtrInfo), _endpoints(endpts) { } #else -IceInternal::DirectReference::DirectReference(const InstancePtr& inst, const Identity& ident, - const Context& ctx, const string& fs, Mode md, bool sec, - const vector<EndpointPtr>& endpts) : - Reference(inst, ident, ctx, fs, md, sec), +IceInternal::DirectReference::DirectReference(const InstancePtr& inst, const CommunicatorPtr& com, + const Identity& ident, const Context& ctx, const string& fs, Mode md, + bool sec, const vector<EndpointPtr>& endpts) : + Reference(inst, com, ident, ctx, fs, md, sec), _endpoints(endpts) { } @@ -939,22 +942,23 @@ void IceInternal::incRef(IceInternal::IndirectReference* p) { p->__incRef(); } void IceInternal::decRef(IceInternal::IndirectReference* p) { p->__decRef(); } #ifdef ICEE_HAS_ROUTER -IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const Identity& ident, - const Context& ctx, const string& fs, Mode md, bool sec, - const string& adptid, const RouterInfoPtr& rtrInfo, - const LocatorInfoPtr& locInfo) - : RoutableReference(inst, ident, ctx, fs, md, sec, rtrInfo), - _adapterId(adptid), - _locatorInfo(locInfo) +IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const CommunicatorPtr& com, + const Identity& ident, const Context& ctx, const string& fs, + Mode md, bool sec, const string& adptid, + const RouterInfoPtr& rtrInfo, const LocatorInfoPtr& locInfo) : + RoutableReference(inst, com ident, ctx, fs, md, sec, rtrInfo), + _adapterId(adptid), + _locatorInfo(locInfo) { } #else -IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const Identity& ident, - const Context& ctx, const string& fs, Mode md, bool sec, - const string& adptid, const LocatorInfoPtr& locInfo) - : Reference(inst, ident, ctx, fs, md, sec), - _adapterId(adptid), - _locatorInfo(locInfo) +IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const CommunicatorPtr& com, + const Identity& ident, const Context& ctx, const string& fs, + Mode md, bool sec, const string& adptid, + const LocatorInfoPtr& locInfo) : + Reference(inst, com, ident, ctx, fs, md, sec), + _adapterId(adptid), + _locatorInfo(locInfo) { } #endif diff --git a/cppe/src/IceE/Reference.h b/cppe/src/IceE/Reference.h index 74c70073adc..2b4d00393c5 100644 --- a/cppe/src/IceE/Reference.h +++ b/cppe/src/IceE/Reference.h @@ -108,12 +108,14 @@ public: protected: - Reference(const InstancePtr&, const Ice::Identity&, const Ice::Context&, const std::string&, Mode, bool); + Reference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, + const std::string&, Mode, bool); Reference(const Reference&); private: - InstancePtr _instance; + const InstancePtr _instance; + const Ice::CommunicatorPtr _communicator; Mode _mode; bool _secure; @@ -131,8 +133,8 @@ class FixedReference : public Reference { public: - FixedReference(const InstancePtr&, const Ice::Identity&, const Ice::Context&, const std::string&, Mode, - const std::vector<Ice::ConnectionPtr>&); + FixedReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, + const std::string&, Mode, const std::vector<Ice::ConnectionPtr>&); const std::vector<Ice::ConnectionPtr>& getFixedConnections() const; @@ -188,8 +190,8 @@ public: protected: - RoutableReference(const InstancePtr&, const Ice::Identity&, const Ice::Context&, const std::string&, - Mode, bool, const RouterInfoPtr&); + RoutableReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, + const std::string&, Mode, bool, const RouterInfoPtr&); RoutableReference(const RoutableReference&); @@ -208,8 +210,8 @@ class DirectReference : { public: - DirectReference(const InstancePtr&, const Ice::Identity&, const Ice::Context&, const std::string&, Mode, - bool, const std::vector<EndpointPtr>& + DirectReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, + const std::string&, Mode, bool, const std::vector<EndpointPtr>& #ifdef ICEE_HAS_ROUTER , const RouterInfoPtr& #endif @@ -262,8 +264,8 @@ class IndirectReference : { public: - IndirectReference(const InstancePtr&, const Ice::Identity&, const Ice::Context&, const std::string&, - Mode, bool, const std::string& + IndirectReference(const InstancePtr&, const Ice::CommunicatorPtr&, const Ice::Identity&, const Ice::Context&, + const std::string&, Mode, bool, const std::string& #ifdef ICEE_HAS_ROUTER , const RouterInfoPtr& #endif diff --git a/cppe/src/IceE/ReferenceFactory.cpp b/cppe/src/IceE/ReferenceFactory.cpp index 8be846b2f01..36282a05c26 100644 --- a/cppe/src/IceE/ReferenceFactory.cpp +++ b/cppe/src/IceE/ReferenceFactory.cpp @@ -77,9 +77,9 @@ IceInternal::ReferenceFactory::create(const Identity& ident, // Create new reference // #ifdef ICEE_HAS_ROUTER - return new DirectReference(_instance, ident, context, facet, mode, secure, endpoints, routerInfo); + return new DirectReference(_instance, _communicator, ident, context, facet, mode, secure, endpoints, routerInfo); #else - return new DirectReference(_instance, ident, context, facet, mode, secure, endpoints); + return new DirectReference(_instance, _communicator, ident, context, facet, mode, secure, endpoints); #endif } @@ -113,9 +113,10 @@ IceInternal::ReferenceFactory::create(const Identity& ident, // Create new reference // #ifdef ICEE_HAS_ROUTER - return new IndirectReference(_instance, ident, context, facet, mode, secure, adapterId, routerInfo, locatorInfo); + return new IndirectReference(_instance, _communicator, ident, context, facet, mode, secure, adapterId, routerInfo, + locatorInfo); #else - return new IndirectReference(_instance, ident, context, facet, mode, secure, adapterId, locatorInfo); + return new IndirectReference(_instance, _communicator, ident, context, facet, mode, secure, adapterId, locatorInfo); #endif } @@ -143,7 +144,7 @@ IceInternal::ReferenceFactory::create(const Identity& ident, // // Create new reference // - return new FixedReference(_instance, ident, context, facet, mode, fixedConnections); + return new FixedReference(_instance, _communicator, ident, context, facet, mode, fixedConnections); } ReferencePtr @@ -667,8 +668,10 @@ IceInternal::ReferenceFactory::getDefaultLocator() const #endif -IceInternal::ReferenceFactory::ReferenceFactory(const InstancePtr& instance) : - _instance(instance) +IceInternal::ReferenceFactory::ReferenceFactory(const InstancePtr& instance, + const CommunicatorPtr& communicator) : + _instance(instance), + _communicator(communicator) { } @@ -683,6 +686,7 @@ IceInternal::ReferenceFactory::destroy() } _instance = 0; + _communicator = 0; #ifdef ICEE_HAS_ROUTER _defaultRouter = 0; #endif diff --git a/cppe/src/IceE/ReferenceFactory.h b/cppe/src/IceE/ReferenceFactory.h index d2c4c4482ae..f8ea02964f1 100644 --- a/cppe/src/IceE/ReferenceFactory.h +++ b/cppe/src/IceE/ReferenceFactory.h @@ -76,11 +76,12 @@ public: private: - ReferenceFactory(const InstancePtr&); + ReferenceFactory(const InstancePtr&, const Ice::CommunicatorPtr&); void destroy(); friend class Instance; InstancePtr _instance; + Ice::CommunicatorPtr _communicator; #ifdef ICEE_HAS_ROUTER ::Ice::RouterPrx _defaultRouter; #endif diff --git a/javae/src/Ice/Communicator.java b/javae/src/Ice/Communicator.java index bbeabb1e858..faa48147bb3 100644 --- a/javae/src/Ice/Communicator.java +++ b/javae/src/Ice/Communicator.java @@ -14,96 +14,36 @@ public final class 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); } @@ -130,91 +70,54 @@ public final class Communicator 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 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.Hashtable + public java.util.Hashtable getDefaultContext() { - if(_destroyed) - { - throw new CommunicatorDestroyedException(); - } return _instance.getDefaultContext(); } - public synchronized void + public void setDefaultContext(java.util.Hashtable ctx) { - if(_destroyed) - { - throw new CommunicatorDestroyedException(); - } _instance.setDefaultContext(ctx); } @@ -226,19 +129,23 @@ public final class Communicator Communicator(Properties properties) { - _destroyed = false; _instance = new IceInternal.Instance(this, properties); } + /** + * For compatibility with C#, we do not invoke methods on other objects + * from within a finalizer. + * protected synchronized void finalize() throws Throwable { - if(!_destroyed) + if(!_instance.destroyed()) { _instance.logger().warning("Ice::Communicator::destroy() has not been called"); } } + */ // // Certain initialization tasks need to be completed after the @@ -253,7 +160,6 @@ public final class Communicator } catch(RuntimeException ex) { - _destroyed = true; _instance.destroy(); throw ex; } @@ -268,7 +174,5 @@ public final class Communicator return _instance; } - private boolean _destroyed; private IceInternal.Instance _instance; - private java.util.Hashtable _dfltContext; } diff --git a/javae/src/IceInternal/DirectReference.java b/javae/src/IceInternal/DirectReference.java index 5d3d81d19cf..df0cdec375b 100644 --- a/javae/src/IceInternal/DirectReference.java +++ b/javae/src/IceInternal/DirectReference.java @@ -13,6 +13,7 @@ public class DirectReference extends RoutableReference { public DirectReference(Instance inst, + Ice.Communicator com, Ice.Identity ident, java.util.Hashtable ctx, String fs, @@ -21,7 +22,7 @@ public class DirectReference extends RoutableReference Endpoint[] endpts, RouterInfo rtrInfo) { - super(inst, ident, ctx, fs, md, sec, rtrInfo); + super(inst, com, ident, ctx, fs, md, sec, rtrInfo); _endpoints = endpts; } diff --git a/javae/src/IceInternal/FixedReference.java b/javae/src/IceInternal/FixedReference.java index 8a81e63420e..7b7d026c836 100644 --- a/javae/src/IceInternal/FixedReference.java +++ b/javae/src/IceInternal/FixedReference.java @@ -13,13 +13,14 @@ public class FixedReference extends Reference { public FixedReference(Instance inst, + Ice.Communicator com, Ice.Identity ident, java.util.Hashtable ctx, String fs, int md, Ice.Connection[] fixedConns) { - super(inst, ident, ctx, fs, md, false); + super(inst, com, ident, ctx, fs, md, false); _fixedConnections = fixedConns; } diff --git a/javae/src/IceInternal/IndirectReference.java b/javae/src/IceInternal/IndirectReference.java index eb8675afe6b..1dfd540ce4f 100644 --- a/javae/src/IceInternal/IndirectReference.java +++ b/javae/src/IceInternal/IndirectReference.java @@ -13,6 +13,7 @@ public class IndirectReference extends RoutableReference { public IndirectReference(Instance inst, + Ice.Communicator com, Ice.Identity ident, java.util.Hashtable ctx, String fs, @@ -22,7 +23,7 @@ public class IndirectReference extends RoutableReference RouterInfo rtrInfo, LocatorInfo locInfo) { - super(inst, ident, ctx, fs, md, sec, rtrInfo); + super(inst, com, ident, ctx, fs, md, sec, rtrInfo); _adapterId = adptid; _locatorInfo = locInfo; } diff --git a/javae/src/IceInternal/Instance.java b/javae/src/IceInternal/Instance.java index c1612b228c3..2ec8940143b 100644 --- a/javae/src/IceInternal/Instance.java +++ b/javae/src/IceInternal/Instance.java @@ -11,15 +11,15 @@ package IceInternal; public class Instance { - public Ice.Communicator communicator() - { - return _communicator; - } - public Ice.Properties properties() { + // + // No check for destruction. It must be possible to access the + // properties after destruction. + // // No mutex lock, immutable. + // return _properties; } @@ -27,8 +27,8 @@ public class Instance logger() { // - // 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; } @@ -36,11 +36,11 @@ public 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; } @@ -61,7 +61,7 @@ public class Instance public synchronized RouterManager routerManager() { - if(_destroyed) + if(_state == StateDestroyed) { throw new Ice.CommunicatorDestroyedException(); } @@ -72,7 +72,7 @@ public class Instance public synchronized LocatorManager locatorManager() { - if(_destroyed) + if(_state == StateDestroyed) { throw new Ice.CommunicatorDestroyedException(); } @@ -83,7 +83,7 @@ public class Instance public synchronized ReferenceFactory referenceFactory() { - if(_destroyed) + if(_state == StateDestroyed) { throw new Ice.CommunicatorDestroyedException(); } @@ -94,7 +94,7 @@ public class Instance public synchronized ProxyFactory proxyFactory() { - if(_destroyed) + if(_state == StateDestroyed) { throw new Ice.CommunicatorDestroyedException(); } @@ -105,7 +105,7 @@ public class Instance public synchronized OutgoingConnectionFactory outgoingConnectionFactory() { - if(_destroyed) + if(_state == StateDestroyed) { throw new Ice.CommunicatorDestroyedException(); } @@ -116,7 +116,7 @@ public class Instance public synchronized ObjectAdapterFactory objectAdapterFactory() { - if(_destroyed) + if(_state == StateDestroyed) { throw new Ice.CommunicatorDestroyedException(); } @@ -133,7 +133,7 @@ public class Instance public synchronized EndpointFactory endpointFactory() { - if(_destroyed) + if(_state == StateDestroyed) { throw new Ice.CommunicatorDestroyedException(); } @@ -199,8 +199,7 @@ public class Instance synchronized(this) { - - if(_destroyed) + if(_state == StateDestroyed) { throw new Ice.CommunicatorDestroyedException(); } @@ -219,8 +218,7 @@ public class Instance public Instance(Ice.Communicator communicator, Ice.Properties properties) { - _communicator = communicator; - _destroyed = false; + _state = StateActive; _properties = properties; try @@ -264,7 +262,7 @@ public class Instance _locatorManager = new LocatorManager(); - _referenceFactory = new ReferenceFactory(this); + _referenceFactory = new ReferenceFactory(this, communicator); _proxyFactory = new ProxyFactory(this); @@ -287,7 +285,7 @@ public class Instance finalize() throws Throwable { - IceUtil.Debug.FinalizerAssert(_destroyed); + IceUtil.Debug.FinalizerAssert(_state == StateDestroyed); IceUtil.Debug.FinalizerAssert(_referenceFactory == null); IceUtil.Debug.FinalizerAssert(_proxyFactory == null); IceUtil.Debug.FinalizerAssert(_outgoingConnectionFactory == null); @@ -326,9 +324,24 @@ public class Instance public void destroy() { - if(IceUtil.Debug.ASSERT) + synchronized(this) { - IceUtil.Debug.Assert(!_destroyed); + // + // 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) @@ -385,7 +398,7 @@ public class Instance _endpointFactory = null; } - _destroyed = true; + _state = StateDestroyed; } } @@ -416,8 +429,11 @@ public 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 final TraceLevels _traceLevels; // Immutable, not reset by destroy(). diff --git a/javae/src/IceInternal/Reference.java b/javae/src/IceInternal/Reference.java index 066c71fc30f..72b53af24e1 100644 --- a/javae/src/IceInternal/Reference.java +++ b/javae/src/IceInternal/Reference.java @@ -70,7 +70,7 @@ public abstract class Reference public final Ice.Communicator getCommunicator() { - return _instance.communicator(); + return _communicator; } public abstract Endpoint[] getEndpoints(); @@ -411,6 +411,7 @@ public abstract class Reference } private Instance _instance; + private Ice.Communicator _communicator; private int _mode; private boolean _secure; @@ -433,6 +434,7 @@ public abstract class Reference protected Reference(Instance inst, + Ice.Communicator com, Ice.Identity ident, java.util.Hashtable ctx, String fac, @@ -450,6 +452,7 @@ public abstract class Reference } _instance = inst; + _communicator = com; _mode = md; _secure = sec; _identity = ident; diff --git a/javae/src/IceInternal/ReferenceFactory.java b/javae/src/IceInternal/ReferenceFactory.java index 59a5919b0ce..41c6d8cc1f9 100644 --- a/javae/src/IceInternal/ReferenceFactory.java +++ b/javae/src/IceInternal/ReferenceFactory.java @@ -33,7 +33,8 @@ public final class ReferenceFactory // // Create new reference // - return new DirectReference(_instance, ident, context, facet, mode, secure, endpoints, routerInfo); + return new DirectReference(_instance, _communicator, ident, context, facet, mode, secure, endpoints, + routerInfo); } public synchronized Reference @@ -59,8 +60,8 @@ public final class ReferenceFactory // // Create new reference // - return new IndirectReference(_instance, ident, context, facet, mode, secure, adapterId, routerInfo, - locatorInfo); + return new IndirectReference(_instance, _communicator, ident, context, facet, mode, secure, adapterId, + routerInfo, locatorInfo); } public synchronized Reference @@ -83,7 +84,7 @@ public final class ReferenceFactory // // Create new reference // - return new FixedReference(_instance, ident, context, facet, mode, fixedConnections); + return new FixedReference(_instance, _communicator, ident, context, facet, mode, fixedConnections); } public synchronized Reference @@ -571,9 +572,10 @@ public final class ReferenceFactory // // Only for use by Instance // - ReferenceFactory(Instance instance) + ReferenceFactory(Instance instance, Ice.Communicator communicator) { _instance = instance; + _communicator = communicator; } synchronized void @@ -585,11 +587,13 @@ public final class ReferenceFactory } _instance = null; + _communicator = null; _defaultRouter = null; _defaultLocator = null; } private Instance _instance; + private Ice.Communicator _communicator; private Ice.RouterPrx _defaultRouter; private Ice.LocatorPrx _defaultLocator; private int _hashUpdateCounter = 0; diff --git a/javae/src/IceInternal/RoutableReference.java b/javae/src/IceInternal/RoutableReference.java index f4b52622c05..59d11d04a24 100644 --- a/javae/src/IceInternal/RoutableReference.java +++ b/javae/src/IceInternal/RoutableReference.java @@ -86,6 +86,7 @@ public abstract class RoutableReference extends Reference protected RoutableReference(Instance inst, + Ice.Communicator com, Ice.Identity ident, java.util.Hashtable ctx, String fac, @@ -93,7 +94,7 @@ public abstract class RoutableReference extends Reference boolean secure, RouterInfo rtrInfo) { - super(inst, ident, ctx, fac, md, secure); + super(inst, com, ident, ctx, fac, md, secure); _routerInfo = rtrInfo; } |