diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/Ice/ConnectionI.java | 3 | ||||
-rw-r--r-- | java/src/Ice/ObjectAdapterI.java | 3 | ||||
-rw-r--r-- | java/src/Ice/ObjectPrxHelperBase.java | 2 | ||||
-rw-r--r-- | java/src/IceInternal/DirectReference.java | 31 | ||||
-rw-r--r-- | java/src/IceInternal/FixedReference.java | 73 | ||||
-rw-r--r-- | java/src/IceInternal/IndirectReference.java | 63 | ||||
-rw-r--r-- | java/src/IceInternal/Reference.java | 214 | ||||
-rw-r--r-- | java/src/IceInternal/ReferenceFactory.java | 6 | ||||
-rw-r--r-- | java/src/IceInternal/RoutableReference.java | 41 |
9 files changed, 261 insertions, 175 deletions
diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index 9a7c0126e28..3feca2f4864 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -1072,8 +1072,7 @@ public final class ConnectionI extends IceInternal.EventHandler implements Conne ConnectionI[] connections = new ConnectionI[1]; connections[0] = this; IceInternal.Reference ref = _instance.referenceFactory().create(ident, new java.util.HashMap(), "", - IceInternal.Reference.ModeTwoway, false, - true, connections); + IceInternal.Reference.ModeTwoway, connections); return _instance.proxyFactory().referenceToProxy(ref); } diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java index 1e7aaaf1fb7..f3282074fb5 100644 --- a/java/src/Ice/ObjectAdapterI.java +++ b/java/src/Ice/ObjectAdapterI.java @@ -453,8 +453,7 @@ public final class ObjectAdapterI extends LocalObjectImpl implements ObjectAdapt ConnectionI[] arr = new ConnectionI[connections.size()]; connections.toArray(arr); IceInternal.Reference ref = _instance.referenceFactory().create(ident, new java.util.HashMap(), "", - IceInternal.Reference.ModeTwoway, - false, true, arr); + IceInternal.Reference.ModeTwoway, arr); return _instance.proxyFactory().referenceToProxy(ref); } diff --git a/java/src/Ice/ObjectPrxHelperBase.java b/java/src/Ice/ObjectPrxHelperBase.java index 36e35165dca..d87dbd9913f 100644 --- a/java/src/Ice/ObjectPrxHelperBase.java +++ b/java/src/Ice/ObjectPrxHelperBase.java @@ -220,7 +220,7 @@ public class ObjectPrxHelperBase implements ObjectPrx public final ObjectPrx ice_newContext(java.util.Map newContext) { - if(_reference.hasContext() && newContext.equals(_reference.getContext())) + if(_reference.hasContext() && newContext != null && newContext.equals(_reference.getContext())) { return this; } diff --git a/java/src/IceInternal/DirectReference.java b/java/src/IceInternal/DirectReference.java index 7c7c4f7aa8c..627f39f32d8 100644 --- a/java/src/IceInternal/DirectReference.java +++ b/java/src/IceInternal/DirectReference.java @@ -44,15 +44,38 @@ public class DirectReference extends RoutableReference } public Reference - changeLocator(Ice.LocatorPrx newLocator) + changeDefault() { - return this; + // + // Return an indirect reference if a default locator is set. + // + Ice.LocatorPrx loc = getInstance().referenceFactory().getDefaultLocator(); + if(loc != null) + { + LocatorInfo newLocatorInfo = getInstance().locatorManager().get(loc); + return getInstance().referenceFactory().create(getIdentity(), null, "", ModeTwoway, false, "", null, + newLocatorInfo, false); + } + else + { + return super.changeDefault(); + } } public Reference - changeDefault() + changeLocator(Ice.LocatorPrx newLocator) { - return this; + if(newLocator != null) + { + LocatorInfo newLocatorInfo = getInstance().locatorManager().get(newLocator); + return getInstance().referenceFactory().create(getIdentity(), getContext(), getFacet(), getMode(), + getSecure(), "", null, newLocatorInfo, + getCollocationOptimization()); + } + else + { + return this; + } } public Reference diff --git a/java/src/IceInternal/FixedReference.java b/java/src/IceInternal/FixedReference.java index 2b997df7689..43c1b6c46bd 100644 --- a/java/src/IceInternal/FixedReference.java +++ b/java/src/IceInternal/FixedReference.java @@ -17,10 +17,9 @@ public class FixedReference extends Reference java.util.Map ctx, String fs, int md, - boolean sec, Ice.ConnectionI[] fixedConns) { - super(inst, ident, ctx, fs, md, sec); + super(inst, ident, ctx, fs, md); _fixedConnections = fixedConns; } @@ -30,6 +29,12 @@ public class FixedReference extends Reference return _fixedConnections; } + public boolean + getSecure() + { + return false; + } + public Endpoint[] getEndpoints() { @@ -42,31 +47,10 @@ public class FixedReference extends Reference return false; } - public void - streamWrite(BasicStream s) - throws Ice.MarshalException - { - Ice.MarshalException ex = new Ice.MarshalException(); - ex.reason = "Cannot marshal a fixed reference"; - throw ex; - } - - public Ice.ConnectionI - getConnection(Ice.BooleanHolder compress) + public Reference + changeSecure(boolean sec) { - Ice.ConnectionI[] filteredConns = filterConnections(_fixedConnections); - if(filteredConns.length == 0) - { - Ice.NoEndpointException ex = new Ice.NoEndpointException(); - ex.proxy = toString(); - throw ex; - } - - Ice.ConnectionI connection = filteredConns[0]; - assert(connection != null); - compress.value = connection.endpoint().compress(); - - return connection; + return this; } public Reference @@ -82,12 +66,6 @@ public class FixedReference extends Reference } public Reference - changeDefault() - { - return this; - } - - public Reference changeCollocationOptimization(boolean newCollocationOptimization) { return this; @@ -96,6 +74,10 @@ public class FixedReference extends Reference public Reference changeCompress(boolean newCompress) { + // TODO: FixedReferences should probably have a _compress flag, + // that gets its default from the fixed connection this reference + // refers to. This should be changable with changeCompress(), and + // reset in changeDefault(). return this; } @@ -105,6 +87,33 @@ public class FixedReference extends Reference return this; } + public void + streamWrite(BasicStream s) + throws Ice.MarshalException + { + Ice.MarshalException ex = new Ice.MarshalException(); + ex.reason = "Cannot marshal a fixed reference"; + throw ex; + } + + public Ice.ConnectionI + getConnection(Ice.BooleanHolder compress) + { + Ice.ConnectionI[] filteredConns = filterConnections(_fixedConnections); + if(filteredConns.length == 0) + { + Ice.NoEndpointException ex = new Ice.NoEndpointException(); + ex.proxy = toString(); + throw ex; + } + + Ice.ConnectionI connection = filteredConns[0]; + assert(connection != null); + compress.value = connection.endpoint().compress(); + + return connection; + } + public boolean equals(java.lang.Object obj) { diff --git a/java/src/IceInternal/IndirectReference.java b/java/src/IceInternal/IndirectReference.java index 46c125c5175..5aad271d681 100644 --- a/java/src/IceInternal/IndirectReference.java +++ b/java/src/IceInternal/IndirectReference.java @@ -47,26 +47,49 @@ public class IndirectReference extends RoutableReference } public Reference - changeLocator(Ice.LocatorPrx newLocator) + changeDefault() { - LocatorInfo newLocatorInfo = getInstance().locatorManager().get(newLocator); - - if((newLocatorInfo == _locatorInfo) || - (_locatorInfo != null && newLocatorInfo != null && newLocatorInfo.equals(_locatorInfo))) - { - return this; - } - IndirectReference r = (IndirectReference)getInstance().referenceFactory().copy(this); - r._locatorInfo = newLocatorInfo; - return this; + // + // Return a direct reference if no default locator is defined. + // + Ice.LocatorPrx loc = getInstance().referenceFactory().getDefaultLocator(); + if(loc == null) + { + return getInstance().referenceFactory().create(getIdentity(), null, "", ModeTwoway, false, + new Endpoint[0], getRouterInfo(), false); + } + else + { + IndirectReference r = (IndirectReference)super.changeDefault(); + r._locatorInfo = getInstance().locatorManager().get(loc); + return r; + } } public Reference - changeDefault() + changeLocator(Ice.LocatorPrx newLocator) { - IndirectReference r = (IndirectReference)super.changeDefault(); - r._locatorInfo = getInstance().locatorManager().get(getInstance().referenceFactory().getDefaultLocator()); - return r; + // + // Return a direct reference if a null locator is given. + // + if(newLocator == null) + { + return getInstance().referenceFactory().create(getIdentity(), getContext(), getFacet(), getMode(), + getSecure(), new Endpoint[0], getRouterInfo(), + getCollocationOptimization()); + } + else + { + LocatorInfo newLocatorInfo = getInstance().locatorManager().get(newLocator); + if((newLocatorInfo == _locatorInfo) || + (_locatorInfo != null && newLocatorInfo != null && newLocatorInfo.equals(_locatorInfo))) + { + return this; + } + IndirectReference r = (IndirectReference)getInstance().referenceFactory().copy(this); + r._locatorInfo = newLocatorInfo; + return this; + } } public Reference @@ -146,8 +169,7 @@ public class IndirectReference extends RoutableReference while(true) { Endpoint[] endpts = super.getRoutedEndpoints(); - Ice.BooleanHolder cached = new Ice.BooleanHolder(); - cached.value = false; + Ice.BooleanHolder cached = new Ice.BooleanHolder(false); if(endpts.length == 0 && _locatorInfo != null) { endpts = _locatorInfo.getEndpoints(this, cached); @@ -225,7 +247,12 @@ public class IndirectReference extends RoutableReference { return false; } - return _adapterId.equals(rhs._adapterId) && _locatorInfo.equals(rhs._locatorInfo); + if(!_adapterId.equals(rhs._adapterId)) + { + return false; + } + return (_locatorInfo == rhs._locatorInfo) || + (_locatorInfo != null && rhs._locatorInfo != null && rhs._locatorInfo.equals(_locatorInfo)); } private String _adapterId; diff --git a/java/src/IceInternal/Reference.java b/java/src/IceInternal/Reference.java index 7534f4d1874..7238d167344 100644 --- a/java/src/IceInternal/Reference.java +++ b/java/src/IceInternal/Reference.java @@ -23,70 +23,61 @@ public abstract class Reference implements Cloneable { return _mode; } + public final Ice.Identity getIdentity() { return _identity; } - public final java.util.Map - getContext() - { - if(_hasContext) - { - return _context == null ? _emptyContext : _context; - } - else - { - return _instance.getDefaultContext(); - } - } - public final String getFacet() { return _facet; } - public final boolean - getSecure() - { - return _secure; - } - public final Instance getInstance() { return _instance; } - public final Reference - changeMode(int newMode) + public final java.util.Map + getContext() { - if(newMode == _mode) - { - return this; - } - Reference r = _instance.referenceFactory().copy(this); - r._mode = newMode; - return r; + return _hasContext ? _context : _instance.getDefaultContext(); } public final Reference - changeIdentity(Ice.Identity newIdentity) + defaultContext() { - if(newIdentity.equals(_identity)) + if(!_hasContext) { return this; } Reference r = _instance.referenceFactory().copy(this); - r._identity = newIdentity; + r._hasContext = false; + r._context = _emptyContext; return r; + } + public abstract boolean getSecure(); + public abstract Endpoint[] getEndpoints(); + public abstract boolean getCollocationOptimization(); + + // + // The change* methods (here and in derived classes) create + // a new reference based on the existing one, with the + // corresponding value changed. + // public final Reference changeContext(java.util.Map newContext) { + if(newContext == null) + { + newContext = _emptyContext; + } if(_hasContext && newContext.equals(_context)) { return this; @@ -105,17 +96,34 @@ public abstract class Reference implements Cloneable } public final Reference - defaultContext() + changeMode(int newMode) { - if(!_hasContext) + if(newMode == _mode) { return this; } Reference r = _instance.referenceFactory().copy(this); - r._hasContext = false; - r._context = _emptyContext; + r._mode = newMode; return r; + } + public final Reference + changeIdentity(Ice.Identity newIdentity) + { + if(newIdentity.equals(_identity)) + { + return this; + } + Reference r = _instance.referenceFactory().copy(this); + try + { + r._identity = (Ice.Identity)newIdentity.clone(); + } + catch(CloneNotSupportedException ex) + { + assert(false); + } + return r; } public final boolean @@ -136,18 +144,27 @@ public abstract class Reference implements Cloneable return r; } - public final Reference - changeSecure(boolean newSecure) + // + // Return a reference in the default configuration. + // + public Reference + changeDefault() { - if(newSecure == _secure) - { - return this; - } Reference r = _instance.referenceFactory().copy(this); - r._secure = newSecure; + r._mode = ModeTwoway; + r._hasContext = false; + r._context = _emptyContext; + r._facet = ""; return r; } + public abstract Reference changeSecure(boolean newSecure); + public abstract Reference changeRouter(Ice.RouterPrx newRouter); + public abstract Reference changeLocator(Ice.LocatorPrx newLocator); + public abstract Reference changeCompress(boolean newCompress); + public abstract Reference changeTimeout(int newTimeout); + public abstract Reference changeCollocationOptimization(boolean newCollocationOptimization); + public final synchronized int hashCode() { @@ -181,7 +198,7 @@ public abstract class Reference implements Cloneable h = 5 * h + (int)_facet.charAt(i); } - h = 5 * h + (_secure ? 1 : 0); + h = 5 * h + (getSecure() ? 1 : 0); _hashValue = h; _hashInitialized = true; @@ -189,48 +206,6 @@ public abstract class Reference implements Cloneable return h; } - public boolean - equals(java.lang.Object obj) - { - // - // Note: if(this == obj) and type test are performed by each non-abstract derived class. - // - - Reference r = (Reference)obj; // Guaranteed to succeed. - - if(_mode != r._mode) - { - return false; - } - - if(!_identity.equals(r._identity)) - { - return false; - } - - if(!_hasContext == r._hasContext) - { - return false; - } - - if(!_context.equals(r._context)) - { - return false; - } - - if(!_facet.equals(r._facet)) - { - return false; - } - - if(_secure != r._secure) - { - return false; - } - - return true; - } - // // Marshal the reference. // @@ -257,7 +232,7 @@ public abstract class Reference implements Cloneable s.writeByte((byte)_mode); - s.writeBool(_secure); + s.writeBool(getSecure()); // Derived class writes the remainder of the reference. } @@ -341,7 +316,7 @@ public abstract class Reference implements Cloneable } } - if(_secure) + if(getSecure()) { s.append(" -s"); } @@ -351,8 +326,50 @@ public abstract class Reference implements Cloneable // Derived class writes the remainder of the string. } + public abstract Ice.ConnectionI getConnection(Ice.BooleanHolder comp); + + public boolean + equals(java.lang.Object obj) + { + // + // Note: if(this == obj) and type test are performed by each non-abstract derived class. + // + + Reference r = (Reference)obj; // Guaranteed to succeed. + + if(_mode != r._mode) + { + return false; + } + + if(!_identity.equals(r._identity)) + { + return false; + } + + if(_hasContext != r._hasContext) + { + return false; + } + + if(!_context.equals(r._context)) + { + return false; + } + + if(!_facet.equals(r._facet)) + { + return false; + } + + return true; + } + public Object clone() { + // + // A member-wise copy is safe because the members are immutable. + // Object o = null; try { @@ -372,7 +389,6 @@ public abstract class Reference implements Cloneable private java.util.Map _context; private static java.util.HashMap _emptyContext = new java.util.HashMap(); private String _facet; - private boolean _secure; private int _hashValue; private boolean _hashInitialized; @@ -382,8 +398,7 @@ public abstract class Reference implements Cloneable Ice.Identity ident, java.util.Map ctx, String fac, - int md, - boolean sec) + int md) { // // Validate string arguments. @@ -395,10 +410,9 @@ public abstract class Reference implements Cloneable _instance = inst; _mode = md; _identity = ident; - _hasContext = false; - _context = ctx; + _hasContext = ctx != null && !ctx.isEmpty(); + _context = ctx == null ? _emptyContext : ctx; _facet = fac; - _secure = sec; _hashInitialized = false; } @@ -472,7 +486,7 @@ public abstract class Reference implements Cloneable // secure endpoints by partitioning the endpoint vector, so that // non-secure endpoints come first. // - if(_secure) + if(getSecure()) { java.util.Iterator i = endpoints.iterator(); while(i.hasNext()) @@ -601,7 +615,7 @@ public abstract class Reference implements Cloneable // secure endpoints by partitioning the endpoint vector, so that // non-secure endpoints come first. // - if(_secure) + if(getSecure()) { java.util.Iterator i = connections.iterator(); while(i.hasNext()) @@ -648,14 +662,4 @@ public abstract class Reference implements Cloneable } private static ConnectionComparator _connectionComparator = new ConnectionComparator(); - - public abstract Endpoint[] getEndpoints(); - public abstract boolean getCollocationOptimization(); - public abstract Reference changeRouter(Ice.RouterPrx newRouter); - public abstract Reference changeLocator(Ice.LocatorPrx newLocator); - public abstract Reference changeDefault(); - public abstract Reference changeCompress(boolean newCompress); - public abstract Reference changeTimeout(int newTimeout); - public abstract Reference changeCollocationOptimization(boolean newCollocationOptimization); - public abstract Ice.ConnectionI getConnection(Ice.BooleanHolder comp); } diff --git a/java/src/IceInternal/ReferenceFactory.java b/java/src/IceInternal/ReferenceFactory.java index fb089380d0a..13c97e1732c 100644 --- a/java/src/IceInternal/ReferenceFactory.java +++ b/java/src/IceInternal/ReferenceFactory.java @@ -64,7 +64,7 @@ public final class ReferenceFactory // Create new reference // IndirectReference ref = new IndirectReference(_instance, ident, context, facet, mode, secure, - adapterId, routerInfo, locatorInfo, collocationOptimization); + adapterId, routerInfo, locatorInfo, collocationOptimization); return updateCache(ref); } @@ -73,8 +73,6 @@ public final class ReferenceFactory java.util.Map context, String facet, int mode, - boolean secure, - boolean collocationOptimization, Ice.ConnectionI[] fixedConnections) { if(_instance == null) @@ -90,7 +88,7 @@ public final class ReferenceFactory // // Create new reference // - FixedReference ref = new FixedReference(_instance, ident, context, facet, mode, secure, fixedConnections); + FixedReference ref = new FixedReference(_instance, ident, context, facet, mode, fixedConnections); return updateCache(ref); } diff --git a/java/src/IceInternal/RoutableReference.java b/java/src/IceInternal/RoutableReference.java index bcd79b01591..a98d561e2a3 100644 --- a/java/src/IceInternal/RoutableReference.java +++ b/java/src/IceInternal/RoutableReference.java @@ -33,29 +33,50 @@ public abstract class RoutableReference extends Reference } public final boolean + getSecure() + { + return _secure; + } + + public final boolean getCollocationOptimization() { return _collocationOptimization; } public Reference - changeRouter(Ice.RouterPrx newRouter) + changeDefault() { - RouterInfo newRouterInfo = getInstance().routerManager().get(newRouter); - if(newRouterInfo == _routerInfo) + RoutableReference r = (RoutableReference)super.changeDefault(); + r._secure = false; + r._routerInfo = getInstance().routerManager().get(getInstance().referenceFactory().getDefaultRouter()); + r._collocationOptimization = false; + return r; + } + + public Reference + changeSecure(boolean newSecure) + { + if(newSecure == _secure) { return this; } RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this); - r._routerInfo = newRouterInfo; + r._secure = newSecure; return r; } public Reference - changeDefault() + changeRouter(Ice.RouterPrx newRouter) { + RouterInfo newRouterInfo = getInstance().routerManager().get(newRouter); + if((newRouterInfo == _routerInfo) || + (newRouterInfo != null && _routerInfo != null && newRouterInfo.equals(_routerInfo))) + { + return this; + } RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this); - r._routerInfo = getInstance().routerManager().get(getInstance().referenceFactory().getDefaultRouter()); + r._routerInfo = newRouterInfo; return r; } @@ -83,6 +104,10 @@ public abstract class RoutableReference extends Reference return false; } RoutableReference rhs = (RoutableReference)obj; // Guaranteed to succeed. + if(_secure != rhs._secure) + { + return false; + } if(_collocationOptimization != rhs._collocationOptimization) { return false; @@ -100,11 +125,13 @@ public abstract class RoutableReference extends Reference RouterInfo rtrInfo, boolean collocationOpt) { - super(inst, ident, ctx, fac, md, sec); + super(inst, ident, ctx, fac, md); + _secure = sec; _routerInfo = rtrInfo; _collocationOptimization = collocationOpt; } + private boolean _secure; private RouterInfo _routerInfo; // Null if no router is used. private boolean _collocationOptimization; } |