diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/IceInternal/DirectReference.java | 56 | ||||
-rw-r--r-- | java/src/IceInternal/IndirectReference.java | 81 | ||||
-rw-r--r-- | java/src/IceInternal/RoutableReference.java | 87 |
3 files changed, 122 insertions, 102 deletions
diff --git a/java/src/IceInternal/DirectReference.java b/java/src/IceInternal/DirectReference.java index c8a2961adaf..fdc8aa1f315 100644 --- a/java/src/IceInternal/DirectReference.java +++ b/java/src/IceInternal/DirectReference.java @@ -54,39 +54,48 @@ public class DirectReference extends RoutableReference public Reference changeCompress(boolean newCompress) { - DirectReference r = (DirectReference)getInstance().referenceFactory().copy(this); - EndpointI[] newEndpoints = new EndpointI[_endpoints.length]; - for(int i = 0; i < _endpoints.length; i++) - { - newEndpoints[i] = _endpoints[i].compress(newCompress); - } - r._endpoints = newEndpoints; + DirectReference r = (DirectReference)super.changeCompress(newCompress); + if(r != this) // Also override the compress flag on the endpoints if it was updated. + { + EndpointI[] newEndpoints = new EndpointI[_endpoints.length]; + for(int i = 0; i < _endpoints.length; i++) + { + newEndpoints[i] = _endpoints[i].compress(newCompress); + } + r._endpoints = newEndpoints; + } return r; } public Reference changeTimeout(int newTimeout) { - DirectReference r = (DirectReference)getInstance().referenceFactory().copy(this); - EndpointI[] newEndpoints = new EndpointI[_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. + { + EndpointI[] newEndpoints = new EndpointI[_endpoints.length]; + for(int i = 0; i < _endpoints.length; i++) + { + newEndpoints[i] = _endpoints[i].timeout(newTimeout); + } + r._endpoints = newEndpoints; + } return r; } public Reference changeConnectionId(String connectionId) { - DirectReference r = (DirectReference)getInstance().referenceFactory().copy(this); - EndpointI[] newEndpoints = new EndpointI[_endpoints.length]; - for(int i = 0; i < _endpoints.length; i++) - { - newEndpoints[i] = _endpoints[i].connectionId(connectionId); - } - r._endpoints = newEndpoints; + DirectReference r = (DirectReference)super.changeConnectionId(connectionId); + if(r != this) // Also override the connection id on the endpoints if it was updated. + { + EndpointI[] newEndpoints = new EndpointI[_endpoints.length]; + for(int i = 0; i < _endpoints.length; i++) + { + newEndpoints[i] = _endpoints[i].connectionId(connectionId); + } + r._endpoints = newEndpoints; + } return r; } @@ -114,6 +123,7 @@ public class DirectReference extends RoutableReference DirectReference r = (DirectReference)getInstance().referenceFactory().copy(this); r._endpoints = newEndpoints; + r.applyOverrides(r._endpoints); return r; } @@ -172,9 +182,11 @@ public class DirectReference extends RoutableReference getConnection(Ice.BooleanHolder comp) { EndpointI[] endpts = super.getRoutedEndpoints(); + applyOverrides(endpts); + if(endpts.length == 0) { - endpts = _endpoints; + endpts = _endpoints; // Endpoint overrides are already applied on these endpoints. } Ice.ConnectionI connection = createConnection(endpts, comp); diff --git a/java/src/IceInternal/IndirectReference.java b/java/src/IceInternal/IndirectReference.java index edd52236b18..88c1faeb225 100644 --- a/java/src/IceInternal/IndirectReference.java +++ b/java/src/IceInternal/IndirectReference.java @@ -27,8 +27,6 @@ public class IndirectReference extends RoutableReference { super(inst, com, ident, ctx, fs, md, sec, rtrInfo, collocationOpt); _adapterId = adptid; - _overrideTimeout = false; - _timeout = 0; _locatorInfo = locInfo; _locatorCacheTimeout = locatorCacheTimeout; } @@ -71,44 +69,6 @@ public class IndirectReference extends RoutableReference } public Reference - changeCompress(boolean newCompress) - { - if(_overrideCompress && _compress == newCompress) - { - return this; - } - IndirectReference r = (IndirectReference)getInstance().referenceFactory().copy(this); - r._compress = newCompress; - r._overrideCompress = true; - 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 Reference - changeConnectionId(String id) - { - if(_connectionId.equals(id)) - { - return this; - } - IndirectReference r = (IndirectReference)getInstance().referenceFactory().copy(this); - r._connectionId = id; - return r; - } - - public Reference changeAdapterId(String newAdapterId) { if(_adapterId.equals(newAdapterId)) @@ -208,21 +168,7 @@ public class IndirectReference extends RoutableReference endpts = _locatorInfo.getEndpoints(this, _locatorCacheTimeout, cached); } - // - // Apply the endpoint overrides to each endpoint. - // - for(int i = 0; i < endpts.length; ++i) - { - endpts[i] = endpts[i].connectionId(_connectionId); - if(_overrideCompress) - { - endpts[i] = endpts[i].compress(_compress); - } - if(_overrideTimeout) - { - endpts[i] = endpts[i].timeout(_timeout); - } - } + applyOverrides(endpts); try { @@ -311,26 +257,6 @@ public class IndirectReference extends RoutableReference { return false; } - if(!_connectionId.equals(rhs._connectionId)) - { - return false; - } - if(_overrideCompress != rhs._overrideCompress) - { - return false; - } - if(_overrideCompress && _compress != rhs._compress) - { - return false; - } - if(_overrideTimeout != rhs._overrideTimeout) - { - return false; - } - if(_overrideTimeout && _timeout != rhs._timeout) - { - return false; - } if(_locatorInfo == null ? rhs._locatorInfo != null : !_locatorInfo.equals(rhs._locatorInfo)) { return false; @@ -339,11 +265,6 @@ public class IndirectReference extends RoutableReference } private String _adapterId; - private String _connectionId = ""; private LocatorInfo _locatorInfo; - private boolean _overrideCompress; - private boolean _compress; // Only used if _overrideCompress == true - private boolean _overrideTimeout; - private int _timeout; // Only used if _overrideTimeout == true private int _locatorCacheTimeout; } diff --git a/java/src/IceInternal/RoutableReference.java b/java/src/IceInternal/RoutableReference.java index 33f4d51ac48..a41f872775f 100644 --- a/java/src/IceInternal/RoutableReference.java +++ b/java/src/IceInternal/RoutableReference.java @@ -117,6 +117,44 @@ public abstract class RoutableReference extends Reference return r; } + public Reference + changeCompress(boolean newCompress) + { + if(_overrideCompress && _compress == newCompress) + { + return this; + } + RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this); + r._compress = newCompress; + r._overrideCompress = true; + return r; + } + + public Reference + changeTimeout(int newTimeout) + { + if(_overrideTimeout && _timeout == newTimeout) + { + return this; + } + RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this); + r._timeout = newTimeout; + r._overrideTimeout = true; + return r; + } + + public Reference + changeConnectionId(String id) + { + if(_connectionId.equals(id)) + { + return this; + } + RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this); + r._connectionId = id; + return r; + } + public synchronized int hashCode() { @@ -151,6 +189,26 @@ public abstract class RoutableReference extends Reference { return false; } + if(!_connectionId.equals(rhs._connectionId)) + { + return false; + } + if(_overrideCompress != rhs._overrideCompress) + { + return false; + } + if(_overrideCompress && _compress != rhs._compress) + { + return false; + } + if(_overrideTimeout != rhs._overrideTimeout) + { + return false; + } + if(_overrideTimeout && _timeout != rhs._timeout) + { + return false; + } return _routerInfo == null ? rhs._routerInfo == null : _routerInfo.equals(rhs._routerInfo); } @@ -171,6 +229,30 @@ public abstract class RoutableReference extends Reference _collocationOptimization = collocationOpt; _cacheConnection = true; _endpointSelection = Ice.EndpointSelectionType.Random; + _overrideCompress = false; + _compress = false; + _overrideTimeout = false; + _timeout = -1; + } + + protected void + applyOverrides(EndpointI[] endpts) + { + // + // Apply the endpoint overrides to each endpoint. + // + for(int i = 0; i < endpts.length; ++i) + { + endpts[i] = endpts[i].connectionId(_connectionId); + if(_overrideCompress) + { + endpts[i] = endpts[i].compress(_compress); + } + if(_overrideTimeout) + { + endpts[i] = endpts[i].timeout(_timeout); + } + } } protected Ice.ConnectionI @@ -359,4 +441,9 @@ public abstract class RoutableReference extends Reference private boolean _collocationOptimization; private boolean _cacheConnection; private Ice.EndpointSelectionType _endpointSelection; + private String _connectionId = ""; + private boolean _overrideCompress; + private boolean _compress; // Only used if _overrideCompress == true + private boolean _overrideTimeout; + private int _timeout; // Only used if _overrideTimeout == true } |