diff options
-rw-r--r-- | cppe/src/IceE/Reference.cpp | 135 | ||||
-rw-r--r-- | cppe/src/IceE/Reference.h | 17 | ||||
-rw-r--r-- | javae/src/IceInternal/DirectReference.java | 22 | ||||
-rw-r--r-- | javae/src/IceInternal/IndirectReference.java | 34 | ||||
-rw-r--r-- | javae/src/IceInternal/Reference.java | 47 |
5 files changed, 147 insertions, 108 deletions
diff --git a/cppe/src/IceE/Reference.cpp b/cppe/src/IceE/Reference.cpp index d8a172d7636..e35e779f09e 100644 --- a/cppe/src/IceE/Reference.cpp +++ b/cppe/src/IceE/Reference.cpp @@ -96,6 +96,19 @@ IceInternal::Reference::changeFacet(const string& newFacet) const return r; } +ReferencePtr +IceInternal::Reference::changeTimeout(int newTimeout) const +{ + if(_overrideTimeout && newTimeout == _timeout) + { + return ReferencePtr(const_cast<Reference*>(this)); + } + ReferencePtr r = getInstance()->referenceFactory()->copy(this); + r->_timeout = newTimeout; + r->_overrideTimeout = true; + return r; +} + Int Reference::hash() const { @@ -300,6 +313,11 @@ IceInternal::Reference::operator==(const Reference& r) const return false; } + if(_overrideTimeout != r._overrideTimeout || _overrideTimeout && _timeout != r._timeout) + { + return false; + } + return true; } @@ -361,6 +379,26 @@ IceInternal::Reference::operator<(const Reference& r) const return false; } + if(!_overrideTimeout && r._overrideTimeout) + { + return true; + } + else if(r._overrideTimeout < _overrideTimeout) + { + return false; + } + else if(_overrideTimeout) + { + if(_timeout < r._timeout) + { + return true; + } + else if(r._timeout < _timeout) + { + return false; + } + } + return false; } @@ -373,7 +411,9 @@ IceInternal::Reference::Reference(const InstancePtr& inst, const CommunicatorPtr _secure(sec), _identity(ident), _context(ctx), - _facet(fs) + _facet(fs), + _overrideTimeout(false), + _timeout(-1) { } @@ -385,8 +425,25 @@ IceInternal::Reference::Reference(const Reference& r) : _secure(r._secure), _identity(r._identity), _context(r._context), - _facet(r._facet) + _facet(r._facet), + _overrideTimeout(r._overrideTimeout), + _timeout(r._timeout) +{ +} + +void +IceInternal::Reference::applyOverrides(vector<EndpointPtr>& endpts) const { + // + // Apply the endpoint overrides to each endpoint. + // + for(vector<EndpointPtr>::iterator p = endpts.begin(); p != endpts.end(); ++p) + { + if(_overrideTimeout) + { + *p = (*p)->timeout(_timeout); + } + } } void IceInternal::incRef(IceInternal::FixedReference* p) { p->__incRef(); } @@ -693,6 +750,7 @@ IceInternal::DirectReference::changeEndpoints(const vector<EndpointPtr>& newEndp } DirectReferencePtr r = DirectReferencePtr::dynamicCast(getInstance()->referenceFactory()->copy(this)); r->_endpoints = newEndpoints; + r->applyOverrides(r->_endpoints); return r; } @@ -709,14 +767,16 @@ IceInternal::DirectReference::changeLocator(const LocatorPrx& newLocator) const ReferencePtr IceInternal::DirectReference::changeTimeout(int newTimeout) const { - DirectReferencePtr r = DirectReferencePtr::dynamicCast(getInstance()->referenceFactory()->copy(this)); - vector<EndpointPtr> newEndpoints; - vector<EndpointPtr>::const_iterator p; - for(p = _endpoints.begin(); p != _endpoints.end(); ++p) + DirectReferencePtr r = DirectReferencePtr::dynamicCast(Parent::changeTimeout(newTimeout)); + if(r.get() != this) // Also override the timeout on the endpoints if it was updated. { - newEndpoints.push_back((*p)->timeout(newTimeout)); + vector<EndpointPtr> newEndpoints; + for(vector<EndpointPtr>::const_iterator p = _endpoints.begin(); p != _endpoints.end(); ++p) + { + newEndpoints.push_back((*p)->timeout(newTimeout)); + } + r->_endpoints = newEndpoints; } - r->_endpoints = newEndpoints; return r; } @@ -763,9 +823,11 @@ IceInternal::DirectReference::getConnection() const { #ifdef ICEE_HAS_ROUTER vector<EndpointPtr> endpts = Parent::getRoutedEndpoints(); + applyOverrides(endpts); + if(endpts.empty()) { - endpts = _endpoints; + endpts = _endpoints; // Endpoint overrides are already applied on these endpoints. } #else vector<EndpointPtr> endpts = _endpoints; @@ -864,8 +926,6 @@ IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const const RouterInfoPtr& rtrInfo, const LocatorInfoPtr& locInfo) : RoutableReference(inst, com, ident, ctx, fs, md, sec, rtrInfo), _adapterId(adptid), - _overrideTimeout(false), - _timeout(0), _locatorInfo(locInfo) { } @@ -876,8 +936,6 @@ IceInternal::IndirectReference::IndirectReference(const InstancePtr& inst, const const LocatorInfoPtr& locInfo) : Reference(inst, com, ident, ctx, fs, md, sec), _adapterId(adptid), - _overrideTimeout(false), - _timeout(0), _locatorInfo(locInfo) { } @@ -902,19 +960,6 @@ IceInternal::IndirectReference::changeLocator(const LocatorPrx& newLocator) cons return r; } -ReferencePtr -IceInternal::IndirectReference::changeTimeout(int newTimeout) const -{ - if(_overrideTimeout && newTimeout == _timeout) - { - return IndirectReferencePtr(const_cast<IndirectReference*>(this)); - } - IndirectReferencePtr r = IndirectReferencePtr::dynamicCast(getInstance()->referenceFactory()->copy(this)); - r->_timeout = newTimeout; - r->_overrideTimeout = true; - return r; -} - void IceInternal::IndirectReference::streamWrite(BasicStream* s) const { @@ -980,16 +1025,7 @@ IceInternal::IndirectReference::getConnection() const endpts = _locatorInfo->getEndpoints(self, cached); } - // - // Apply the endpoint overrides to each endpoint. - // - for(vector<EndpointPtr>::iterator p = endpts.begin(); p != endpts.end(); ++p) - { - if(_overrideTimeout) - { - *p = (*p)->timeout(_timeout); - } - } + applyOverrides(endpts); vector<EndpointPtr> filteredEndpoints = filterEndpoints(endpts, getMode(), getSecure()); if(filteredEndpoints.empty()) @@ -1084,9 +1120,7 @@ IceInternal::IndirectReference::operator==(const Reference& r) const { return false; } - return _adapterId == rhs->_adapterId && - _overrideTimeout == rhs->_overrideTimeout && (!_overrideTimeout || _timeout == rhs->_timeout) && - _locatorInfo == rhs->_locatorInfo; + return _adapterId == rhs->_adapterId && _locatorInfo == rhs->_locatorInfo; } bool @@ -1119,27 +1153,6 @@ IceInternal::IndirectReference::operator<(const Reference& r) const { return false; } - - if(!_overrideTimeout && rhs->_overrideTimeout) - { - return true; - } - else if(rhs->_overrideTimeout < _overrideTimeout) - { - return false; - } - else if(_overrideTimeout) - { - if(_timeout < rhs->_timeout) - { - return true; - } - else if(rhs->_timeout < _timeout) - { - return false; - } - } - return _locatorInfo < rhs->_locatorInfo; } } @@ -1155,8 +1168,6 @@ IceInternal::IndirectReference::clone() const IceInternal::IndirectReference::IndirectReference(const IndirectReference& r) : Parent(r), _adapterId(r._adapterId), - _overrideTimeout(r._overrideTimeout), - _timeout(r._timeout), _locatorInfo(r._locatorInfo) { } diff --git a/cppe/src/IceE/Reference.h b/cppe/src/IceE/Reference.h index da680d2f705..e16d630c44c 100644 --- a/cppe/src/IceE/Reference.h +++ b/cppe/src/IceE/Reference.h @@ -81,7 +81,7 @@ public: #ifdef ICEE_HAS_LOCATOR virtual ReferencePtr changeLocator(const Ice::LocatorPrx&) const = 0; #endif - virtual ReferencePtr changeTimeout(int) const = 0; + virtual ReferencePtr changeTimeout(int) const; int hash() const; // Conceptually const. @@ -112,6 +112,8 @@ protected: const std::string&, Mode, bool); Reference(const Reference&); + void applyOverrides(std::vector<EndpointPtr>&) const; + IceUtil::RecMutex _hashMutex; // For lazy initialization of hash value. mutable Ice::Int _hashValue; mutable bool _hashInitialized; @@ -126,6 +128,16 @@ private: Ice::Identity _identity; Ice::Context _context; std::string _facet; + + // + // NOTE: The override timeout should theoritically be in + // RoutableReference. However, since RoutableReference is only + // defined if the ICEE_HAS_ROUTER macro is defined, it would also + // have to be conditionally defined here. To simplify, we just + // define it here. + // + bool _overrideTimeout; + int _timeout; // Only used if _overrideTimeout == true }; class FixedReference : public Reference @@ -275,7 +287,6 @@ public: virtual std::vector<EndpointPtr> getEndpoints() const; virtual ReferencePtr changeLocator(const Ice::LocatorPrx&) const; - virtual ReferencePtr changeTimeout(int) const; virtual void streamWrite(BasicStream*) const; virtual std::string toString() const; @@ -296,8 +307,6 @@ protected: private: std::string _adapterId; - bool _overrideTimeout; - int _timeout; // Only used if _overrideTimeout == true LocatorInfoPtr _locatorInfo; #ifdef ICEE_HAS_ROUTER typedef RoutableReference Parent; diff --git a/javae/src/IceInternal/DirectReference.java b/javae/src/IceInternal/DirectReference.java index 07d8427a5ea..30204f1e08a 100644 --- a/javae/src/IceInternal/DirectReference.java +++ b/javae/src/IceInternal/DirectReference.java @@ -40,6 +40,7 @@ public class DirectReference extends RoutableReference } DirectReference r = (DirectReference)getInstance().referenceFactory().copy(this); r._endpoints = newEndpoints; + r.applyOverrides(r._endpoints); return r; } @@ -52,13 +53,16 @@ public class DirectReference extends RoutableReference public Reference changeTimeout(int newTimeout) { - DirectReference r = (DirectReference)getInstance().referenceFactory().copy(this); - Endpoint[] newEndpoints = new Endpoint[_endpoints.length]; - for(int i = 0; i < _endpoints.length; i++) - { - newEndpoints[i] = _endpoints[i].timeout(newTimeout); - } - r._endpoints = newEndpoints; + DirectReference r = (DirectReference)super.changeTimeout(newTimeout); + if(r != this) // Also override the timeout on the endpoints if it was updated. + { + Endpoint[] newEndpoints = new Endpoint[_endpoints.length]; + for(int i = 0; i < _endpoints.length; i++) + { + newEndpoints[i] = _endpoints[i].timeout(newTimeout); + } + r._endpoints = newEndpoints; + } return r; } @@ -111,9 +115,11 @@ public class DirectReference extends RoutableReference getConnection() { Endpoint[] endpts = super.getRoutedEndpoints(); + applyOverrides(endpts); + if(endpts.length == 0) { - endpts = _endpoints; + endpts = _endpoints; // Endpoint overrides are already applied on these endpoints. } Endpoint[] filteredEndpoints = filterEndpoints(endpts); if(filteredEndpoints.length == 0) diff --git a/javae/src/IceInternal/IndirectReference.java b/javae/src/IceInternal/IndirectReference.java index 0439e06fd35..777024f4001 100644 --- a/javae/src/IceInternal/IndirectReference.java +++ b/javae/src/IceInternal/IndirectReference.java @@ -59,19 +59,6 @@ public class IndirectReference extends RoutableReference return r; } - public Reference - changeTimeout(int newTimeout) - { - if(_overrideTimeout && _timeout == newTimeout) - { - return this; - } - IndirectReference r = (IndirectReference)getInstance().referenceFactory().copy(this); - r._timeout = newTimeout; - r._overrideTimeout = true; - return r; - } - public void streamWrite(BasicStream s) throws Ice.MarshalException @@ -136,16 +123,7 @@ public class IndirectReference extends RoutableReference endpts = _locatorInfo.getEndpoints(this, cached); } - // - // Apply the endpoint overrides to each endpoint. - // - for(int i = 0; i < endpts.length; ++i) - { - if(_overrideTimeout) - { - endpts[i] = endpts[i].timeout(_timeout); - } - } + applyOverrides(endpts); Endpoint[] filteredEndpoints = filterEndpoints(endpts); if(filteredEndpoints.length == 0) @@ -247,14 +225,6 @@ public class IndirectReference extends RoutableReference { return false; } - if(_overrideTimeout != rhs._overrideTimeout) - { - return false; - } - if(_overrideTimeout && _timeout != rhs._timeout) - { - return false; - } return _locatorInfo == null ? rhs._locatorInfo == null : _locatorInfo.equals(rhs._locatorInfo); } @@ -280,7 +250,5 @@ public class IndirectReference extends RoutableReference } private String _adapterId; - private boolean _overrideTimeout; - private int _timeout; // Only used if _overrideTimeout == true private LocatorInfo _locatorInfo; } diff --git a/javae/src/IceInternal/Reference.java b/javae/src/IceInternal/Reference.java index 74325593a6c..2472721612d 100644 --- a/javae/src/IceInternal/Reference.java +++ b/javae/src/IceInternal/Reference.java @@ -159,9 +159,21 @@ public abstract class Reference return r; } + public Reference + changeTimeout(int newTimeout) + { + if(_overrideTimeout && _timeout == newTimeout) + { + return this; + } + Reference r = getInstance().referenceFactory().copy(this); + r._timeout = newTimeout; + r._overrideTimeout = true; + return r; + } + public abstract Reference changeRouter(Ice.RouterPrx newRouter); public abstract Reference changeLocator(Ice.LocatorPrx newLocator); - public abstract Reference changeTimeout(int newTimeout); public synchronized int hashCode() @@ -362,6 +374,15 @@ public abstract class Reference return false; } + if(_overrideTimeout != r._overrideTimeout) + { + return false; + } + if(_overrideTimeout && _timeout != r._timeout) + { + return false; + } + return true; } @@ -374,6 +395,8 @@ public abstract class Reference dest._context = _context; dest._emptyContext = _emptyContext; dest._facet = _facet; + dest._timeout = _timeout; + dest._overrideTimeout = _overrideTimeout; dest._hashInitialized = false; } @@ -397,6 +420,14 @@ public abstract class Reference private static java.util.Hashtable _emptyContext = new java.util.Hashtable(); private String _facet; + // + // NOTE: The override timeout should theoritically be in + // RoutableReference. But for consistency with the C++ version we + // keep it here (see also comment in src/IceE/Reference.h) + // + private boolean _overrideTimeout; + private int _timeout; // Only used if _overrideTimeout == true + protected int _hashValue; protected boolean _hashInitialized; @@ -434,9 +465,23 @@ public abstract class Reference _identity = ident; _context = ctx == null ? _emptyContext : ctx; _facet = fac; + _overrideTimeout = false; + _timeout = -1; _hashInitialized = false; } + protected void + applyOverrides(Endpoint[] endpts) + { + for(int i = 0; i < endpts.length; ++i) + { + if(_overrideTimeout) + { + endpts[i] = endpts[i].timeout(_timeout); + } + } + } + // // Filter endpoints based on criteria from this reference. // |