diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/Ice/CommunicatorI.java | 11 | ||||
-rw-r--r-- | java/src/Ice/ObjectAdapterI.java | 118 | ||||
-rw-r--r-- | java/src/Ice/ObjectPrxHelper.java | 80 | ||||
-rw-r--r-- | java/src/Ice/_ObjectDelM.java | 90 | ||||
-rw-r--r-- | java/src/IceInternal/DefaultsAndOverrides.java | 3 | ||||
-rw-r--r-- | java/src/IceInternal/Instance.java | 39 | ||||
-rw-r--r-- | java/src/IceInternal/LocatorAdapterTable.java | 40 | ||||
-rw-r--r-- | java/src/IceInternal/LocatorInfo.java | 156 | ||||
-rw-r--r-- | java/src/IceInternal/LocatorManager.java | 65 | ||||
-rw-r--r-- | java/src/IceInternal/ProxyFactory.java | 33 | ||||
-rw-r--r-- | java/src/IceInternal/Reference.java | 196 | ||||
-rw-r--r-- | java/src/IceInternal/ReferenceFactory.java | 144 | ||||
-rw-r--r-- | java/src/IceInternal/TraceLevels.java | 4 |
13 files changed, 752 insertions, 227 deletions
diff --git a/java/src/Ice/CommunicatorI.java b/java/src/Ice/CommunicatorI.java index 2df75819d06..ef71e2b0c24 100644 --- a/java/src/Ice/CommunicatorI.java +++ b/java/src/Ice/CommunicatorI.java @@ -84,9 +84,10 @@ class CommunicatorI implements Communicator adapter.addRouter(RouterPrxHelper.uncheckedCast(_instance.proxyFactory().stringToProxy(router))); } - if(_serverThreadPool == null) // Lazy initialization of _serverThreadPool. + String locator = _instance.properties().getProperty("Ice.Adapter." + name + ".Locator"); + if(locator.length() > 0) { - _serverThreadPool = _instance.serverThreadPool(); + adapter.setLocator(LocatorPrxHelper.uncheckedCast(_instance.proxyFactory().stringToProxy(locator))); } return adapter; @@ -115,6 +116,12 @@ class CommunicatorI implements Communicator ObjectAdapter adapter = _instance.objectAdapterFactory().createObjectAdapter(name, endpts); + String locator = _instance.defaultsAndOverrides().defaultLocator; + if(locator.length() > 0) + { + adapter.setLocator(LocatorPrxHelper.uncheckedCast(_instance.proxyFactory().stringToProxy(locator))); + } + if(_serverThreadPool == null) // Lazy initialization of _serverThreadPool. { _serverThreadPool = _instance.serverThreadPool(); diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java index fbb9e43edc2..48f0c234e90 100644 --- a/java/src/Ice/ObjectAdapterI.java +++ b/java/src/Ice/ObjectAdapterI.java @@ -32,6 +32,24 @@ public class ObjectAdapterI implements ObjectAdapter throw new ObjectAdapterDeactivatedException(); } + if(!_printAdapterReadyDone) + { + if(_locatorInfo != null) + { + Identity ident = new Identity(); + ident.category = ""; + ident.name = "dummy"; + + // + // TODO: This might throw if we can't connect to the + // locator. Shall we raise a special exception for the + // activate operation instead of a non obvious network + // exception? + // + _locatorInfo.getLocatorRegistry().addAdapter(_name, newDirectProxy(ident)); + } + } + final int sz = _incomingConnectionFactories.size(); for(int i = 0; i < sz; ++i) { @@ -46,7 +64,7 @@ public class ObjectAdapterI implements ObjectAdapter { System.out.println(_name + " ready"); } - + _printAdapterReadyDone = true; } } @@ -88,9 +106,9 @@ public class ObjectAdapterI implements ObjectAdapter factory.destroy(); } - _instance.outgoingConnectionFactory().removeAdapter(this); + _instance.outgoingConnectionFactory().removeAdapter(this); - _activeServantMap.clear(); + _activeServantMap.clear(); java.util.Iterator p = _locatorMap.values().iterator(); while(p.hasNext()) @@ -231,6 +249,17 @@ public class ObjectAdapterI implements ObjectAdapter } public synchronized ObjectPrx + createDirectProxy(Identity ident) + { + if(_instance == null) + { + throw new ObjectAdapterDeactivatedException(); + } + + return newDirectProxy(ident); + } + + public synchronized ObjectPrx createReverseProxy(Identity ident) { if(_instance == null) @@ -243,8 +272,8 @@ public class ObjectAdapterI implements ObjectAdapter // IceInternal.Endpoint[] endpoints = new IceInternal.Endpoint[0]; IceInternal.Reference ref = - _instance.referenceFactory().create(ident, "", IceInternal.Reference.ModeTwoway, false, false, endpoints, - endpoints, null, this); + _instance.referenceFactory().create(ident, "", IceInternal.Reference.ModeTwoway, false, false, "", + endpoints, null, null, this); return _instance.proxyFactory().referenceToProxy(ref); } @@ -294,9 +323,39 @@ public class ObjectAdapterI implements ObjectAdapter // callbacks. // _instance.outgoingConnectionFactory().setRouter(routerInfo.getRouter()); + + // + // Creates proxies with endpoints instead of the adapter name. + // + _useEndpointsInProxy = true; } } + public synchronized void + setLocator(LocatorPrx locator) + { + if(_instance == null) + { + throw new ObjectAdapterDeactivatedException(); + } + + _locatorInfo = _instance.locatorManager().get(locator); + if(_locatorInfo != null) + { + // + // If a locator is set, we create proxies with adapter names in + // the reference instead of endpoints. If it's not set, we create + // proxies with endpoints if there's at least one incoming + // connection factory or router endpoints. + // + _useEndpointsInProxy = false; + } + else + { + _useEndpointsInProxy = _incomingConnectionFactories.size() > 0 || _routerEndpoints.size() > 0; + } + } + public IceInternal.Connection[] getIncomingConnections() { @@ -330,8 +389,8 @@ public class ObjectAdapterI implements ObjectAdapter _instance = instance; _printAdapterReadyDone = false; _name = name; - - String s = endpts.toLowerCase(); + + String s = endpts.toLowerCase(); int beg = 0; int end; @@ -375,6 +434,14 @@ public class ObjectAdapterI implements ObjectAdapter throw ex; } + // + // Create proxies with the adapter endpoints only if there's + // incoming connection factories. If there's no incoming + // connection factories we will create proxies with the adapter + // name in the reference (to allow collocation to work). + // + _useEndpointsInProxy = _incomingConnectionFactories.size() > 0; + // // Object Adapters without incoming connection factories are // permissible, as such Object Adapters can still be used with a @@ -403,6 +470,28 @@ public class ObjectAdapterI implements ObjectAdapter private ObjectPrx newProxy(Identity ident) { + if(_useEndpointsInProxy) + { + return newDirectProxy(ident); + } + else + { + // + // Create a reference with the adapter id and return a + // proxy for the reference. + // + IceInternal.Endpoint[] endpoints = new IceInternal.Endpoint[0]; + IceInternal.Reference reference = _instance.referenceFactory().create(ident, "", + IceInternal.Reference.ModeTwoway, + false, false, _name, + endpoints, null, null, null); + return _instance.proxyFactory().referenceToProxy(reference); + } + } + + private ObjectPrx + newDirectProxy(Identity ident) + { IceInternal.Endpoint[] endpoints = new IceInternal.Endpoint[_incomingConnectionFactories.size() + _routerEndpoints.size()]; @@ -434,8 +523,8 @@ public class ObjectAdapterI implements ObjectAdapter // IceInternal.Reference reference = _instance.referenceFactory().create(ident, "", IceInternal.Reference.ModeTwoway, - false, false, - endpoints, endpoints, null, null); + false, false, "", + endpoints, null, null, null); return _instance.proxyFactory().referenceToProxy(reference); } @@ -445,6 +534,15 @@ public class ObjectAdapterI implements ObjectAdapter IceInternal.Reference ref = ((ObjectPrxHelper)proxy).__reference(); final IceInternal.Endpoint[] endpoints = ref.endpoints; + if(!ref.adapterId.equals("")) + { + // + // Proxy is local if the reference adapter id matches this + // adapter name. + // + return ref.adapterId.equals(_name); + } + // // Proxies which have at least one endpoint in common with the // endpoints used by this object adapter's incoming connection @@ -494,8 +592,10 @@ public class ObjectAdapterI implements ObjectAdapter private IceInternal.Instance _instance; private boolean _printAdapterReadyDone; private String _name; + private boolean _useEndpointsInProxy; private java.util.HashMap _activeServantMap = new java.util.HashMap(); private java.util.HashMap _locatorMap = new java.util.HashMap(); private java.util.ArrayList _incomingConnectionFactories = new java.util.ArrayList(); private java.util.ArrayList _routerEndpoints = new java.util.ArrayList(); + private IceInternal.LocatorInfo _locatorInfo; } diff --git a/java/src/Ice/ObjectPrxHelper.java b/java/src/Ice/ObjectPrxHelper.java index 1534b0a4e68..0cd4bb14adb 100644 --- a/java/src/Ice/ObjectPrxHelper.java +++ b/java/src/Ice/ObjectPrxHelper.java @@ -241,7 +241,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(_reference.changeIdentity(newIdentity)); + proxy.setup(_reference.changeIdentity(newIdentity), _retryIntervals); return proxy; } } @@ -262,7 +262,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(_reference.changeFacet(newFacet)); + proxy.setup(_reference.changeFacet(newFacet), _retryIntervals); return proxy; } } @@ -278,7 +278,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(ref); + proxy.setup(ref, _retryIntervals); return proxy; } } @@ -294,7 +294,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(ref); + proxy.setup(ref, _retryIntervals); return proxy; } } @@ -310,7 +310,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(ref); + proxy.setup(ref, _retryIntervals); return proxy; } } @@ -326,7 +326,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(ref); + proxy.setup(ref, _retryIntervals); return proxy; } } @@ -342,7 +342,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(ref); + proxy.setup(ref, _retryIntervals); return proxy; } } @@ -358,7 +358,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(ref); + proxy.setup(ref, _retryIntervals); return proxy; } } @@ -374,7 +374,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(ref); + proxy.setup(ref, _retryIntervals); return proxy; } } @@ -390,7 +390,23 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(ref); + proxy.setup(ref, _retryIntervals); + return proxy; + } + } + + public final ObjectPrx + ice_locator(Ice.LocatorPrx locator) + { + IceInternal.Reference ref = _reference.changeLocator(locator); + if(ref.equals(_reference)) + { + return this; + } + else + { + ObjectPrxHelper proxy = new ObjectPrxHelper(); + proxy.setup(ref, _retryIntervals); return proxy; } } @@ -406,7 +422,7 @@ public class ObjectPrxHelper implements ObjectPrx else { ObjectPrxHelper proxy = new ObjectPrxHelper(); - proxy.setup(ref); + proxy.setup(ref, _retryIntervals); return proxy; } } @@ -438,10 +454,12 @@ public class ObjectPrxHelper implements ObjectPrx IceInternal.Reference ref = null; _ObjectDelM delegateM = null; _ObjectDelD delegateD = null; + int[] retryIntervals; synchronized(from) { ref = h._reference; + retryIntervals = h._retryIntervals; try { delegateM = (_ObjectDelM)h._delegate; @@ -464,6 +482,7 @@ public class ObjectPrxHelper implements ObjectPrx // _reference = ref; + _retryIntervals = retryIntervals; if(delegateD != null) { @@ -484,8 +503,6 @@ public class ObjectPrxHelper implements ObjectPrx { _delegate = null; - final int max = 1; // TODO: Make number of retries configurable - try { throw ex; @@ -496,7 +513,6 @@ public class ObjectPrxHelper implements ObjectPrx // We always retry on a close connection exception, as this // indicates graceful server shutdown. // - // TODO: configurable timeout before we try again? } catch(SocketException e) { @@ -514,11 +530,11 @@ public class ObjectPrxHelper implements ObjectPrx IceInternal.TraceLevels traceLevels = _reference.instance.traceLevels(); Logger logger = _reference.instance.logger(); - if(cnt > max) + if(cnt > _retryIntervals.length) { if(traceLevels.retry >= 1) { - String s = "cannot retry operation call because retry limit has been exceeded\n" + ex; + String s = "cannot retry operation call because retry limit has been exceeded\n" + ex.toString(); logger.trace(traceLevels.retryCat, s); } throw ex; @@ -526,16 +542,31 @@ public class ObjectPrxHelper implements ObjectPrx if(traceLevels.retry >= 1) { - String s = "re-trying operation call because of exception\n" + ex; + String s = "re-trying operation call"; + if(cnt > 0 && _retryIntervals[cnt - 1] > 0) + { + s += " in " + _retryIntervals[cnt - 1] + " (ms)"; + } + s += " because of exception\n" + ex; logger.trace(traceLevels.retryCat, s); } - // - // Reset the endpoints to the original endpoints upon retry - // - _reference = _reference.changeEndpoints(_reference.origEndpoints); + if(cnt > 0) + { + // + // Sleep before retrying. TODO: is it safe to sleep here + // with the mutex locked? + // + try + { + Thread.currentThread().sleep(_retryIntervals[cnt - 1]); + } + catch(InterruptedException ex1) + { + } + } - return cnt; + return cnt; } public final synchronized void @@ -557,6 +588,7 @@ public class ObjectPrxHelper implements ObjectPrx throw new LocationForwardIdentityException(); } + _reference = _reference.changeAdapterId(h.__reference().adapterId); _reference = _reference.changeEndpoints(h.__reference().endpoints); /* @@ -621,15 +653,17 @@ public class ObjectPrxHelper implements ObjectPrx // Only for use by IceInternal.ProxyFactory // public final void - setup(IceInternal.Reference ref) + setup(IceInternal.Reference ref, int[] retryIntervals) { // // No need to synchronize, as this operation is only called // upon initial initialization. // _reference = ref; + _retryIntervals = retryIntervals; } private IceInternal.Reference _reference; private _ObjectDel _delegate; + private int[] _retryIntervals; } diff --git a/java/src/Ice/_ObjectDelM.java b/java/src/Ice/_ObjectDelM.java index b32f08ee23e..88fa10771f5 100644 --- a/java/src/Ice/_ObjectDelM.java +++ b/java/src/Ice/_ObjectDelM.java @@ -211,30 +211,72 @@ public class _ObjectDelM implements _ObjectDel } else { - IceInternal.Endpoint[] endpoints = null; - if(__reference.routerInfo != null) - { - // - // If we route, we send everything to the router's client - // proxy endpoints. - // - ObjectPrx proxy = __reference.routerInfo.getClientProxy(); - endpoints = filterEndpoints(((ObjectPrxHelper)proxy).__reference().endpoints); - } - else - { - endpoints = filterEndpoints(__reference.endpoints); - } - - if(endpoints.length == 0) - { - throw new NoEndpointException(); - } - - IceInternal.OutgoingConnectionFactory factory = __reference.instance.outgoingConnectionFactory(); - __connection = factory.create(endpoints); - assert(__connection != null); - __connection.incProxyUsageCount(); + while(true) + { + IceInternal.Endpoint[] endpoints = null; + BooleanHolder cached = new BooleanHolder(); + cached.value = false; + + if(__reference.routerInfo != null) + { + // + // If we route, we send everything to the router's client + // proxy endpoints. + // + ObjectPrx proxy = __reference.routerInfo.getClientProxy(); + endpoints = filterEndpoints(((ObjectPrxHelper)proxy).__reference().endpoints); + } + else if(__reference.endpoints.length > 0) + { + endpoints = filterEndpoints(__reference.endpoints); + } + else if(__reference.locatorInfo != null) + { + endpoints = __reference.locatorInfo.getEndpoints(__reference, cached); + } + + IceInternal.Endpoint[] filteredEndpoints = filterEndpoints(endpoints); + if(filteredEndpoints.length == 0) + { + throw new NoEndpointException(); + } + + try + { + IceInternal.OutgoingConnectionFactory factory = __reference.instance.outgoingConnectionFactory(); + __connection = factory.create(filteredEndpoints); + assert(__connection != null); + __connection.incProxyUsageCount(); + } + catch (LocalException ex) + { + if(cached.value) + { + IceInternal.TraceLevels traceLevels = __reference.instance.traceLevels(); + Logger logger = __reference.instance.logger(); + + if(traceLevels.retry >= 1) + { + String s = "connection to cached endpoint failed, removing endpoint from cache\n" + + "and trying one more time\n" + ex; + logger.trace(traceLevels.retryCat, s); + } + + __reference.locatorInfo.removeEndpoints(__reference); + continue; + } + else + { + throw ex; + } + } + + if(__reference.locatorInfo != null && !cached.value) + { + __reference.locatorInfo.addEndpoints(__reference, endpoints); + } + break; + } // // If we have a router, set the object adapter for this diff --git a/java/src/IceInternal/DefaultsAndOverrides.java b/java/src/IceInternal/DefaultsAndOverrides.java index 64fb4824439..93bbfc43565 100644 --- a/java/src/IceInternal/DefaultsAndOverrides.java +++ b/java/src/IceInternal/DefaultsAndOverrides.java @@ -53,11 +53,14 @@ public final class DefaultsAndOverrides overrideComppress = false; overrideComppressValue = false; } + + defaultLocator = properties.getProperty("Ice.Default.Locator"); } final public String defaultHost; final public String defaultProtocol; final public String defaultRouter; + final public String defaultLocator; final public boolean overrideTimeout; final public int overrideTimeoutValue; diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java index bedd6e17972..4954d351e20 100644 --- a/java/src/IceInternal/Instance.java +++ b/java/src/IceInternal/Instance.java @@ -57,6 +57,12 @@ public class Instance return _routerManager; } + public synchronized LocatorManager + locatorManager() + { + return _locatorManager; + } + public synchronized ReferenceFactory referenceFactory() { @@ -164,6 +170,8 @@ public class Instance _routerManager = new RouterManager(); + _locatorManager = new LocatorManager(); + _referenceFactory = new ReferenceFactory(this); _proxyFactory = new ProxyFactory(this); @@ -176,12 +184,6 @@ public class Instance _pluginManager = new Ice.PluginManagerI(this); - if(_defaultsAndOverrides.defaultRouter.length() > 0) - { - _referenceFactory.setDefaultRouter(Ice.RouterPrxHelper.uncheckedCast( - _proxyFactory.stringToProxy(_defaultsAndOverrides.defaultRouter))); - } - _outgoingConnectionFactory = new OutgoingConnectionFactory(this); _servantFactoryManager = new ObjectFactoryManager(); @@ -213,6 +215,7 @@ public class Instance assert(_clientThreadPool == null); assert(_serverThreadPool == null); assert(_routerManager == null); + assert(_locatorManager == null); assert(_endpointFactoryManager == null); assert(_pluginManager == null); @@ -228,6 +231,23 @@ public class Instance //pluginManagerImpl = (Ice.PluginManagerI)_pluginManager; //pluginManagerImpl.loadPlugins(args); + // + // Get default router and locator proxies. Don't move this + // initialization before the plug-in initialization!!! The proxies + // might depend on endpoint factories to be installed by plug-ins. + // + if(_defaultsAndOverrides.defaultRouter.length() > 0) + { + _referenceFactory.setDefaultRouter(Ice.RouterPrxHelper.uncheckedCast( + _proxyFactory.stringToProxy(_defaultsAndOverrides.defaultRouter))); + } + + if(_defaultsAndOverrides.defaultLocator.length() > 0) + { + _referenceFactory.setDefaultLocator(Ice.LocatorPrxHelper.uncheckedCast( + _proxyFactory.stringToProxy(_defaultsAndOverrides.defaultLocator))); + } + // // Thread pool initialization is now lazy initialization in // clientThreadPool() and serverThreadPool(). @@ -302,6 +322,12 @@ public class Instance _routerManager = null; } + if(_locatorManager != null) + { + _locatorManager.destroy(); + _locatorManager = null; + } + if(_endpointFactoryManager != null) { _endpointFactoryManager.destroy(); @@ -350,6 +376,7 @@ public class Instance private TraceLevels _traceLevels; // Immutable, not reset by destroy(). private DefaultsAndOverrides _defaultsAndOverrides; // Immutable, not reset by destroy(). private RouterManager _routerManager; + private LocatorManager _locatorManager; private ReferenceFactory _referenceFactory; private ProxyFactory _proxyFactory; private OutgoingConnectionFactory _outgoingConnectionFactory; diff --git a/java/src/IceInternal/LocatorAdapterTable.java b/java/src/IceInternal/LocatorAdapterTable.java new file mode 100644 index 00000000000..80367ad089c --- /dev/null +++ b/java/src/IceInternal/LocatorAdapterTable.java @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class LocatorAdapterTable +{ + LocatorAdapterTable() + { + } + + synchronized IceInternal.Endpoint[] + get(String adapter) + { + return (IceInternal.Endpoint[])_table.get(adapter); + } + + synchronized void + add(String adapter, IceInternal.Endpoint[] endpoints) + { + _table.put(adapter, endpoints); + } + + synchronized void + remove(String adapter) + { + Object object = _table.remove(adapter); + assert(object != null); + } + + private java.util.HashMap _table = new java.util.HashMap(); +}; + diff --git a/java/src/IceInternal/LocatorInfo.java b/java/src/IceInternal/LocatorInfo.java new file mode 100644 index 00000000000..a4a87c2a21c --- /dev/null +++ b/java/src/IceInternal/LocatorInfo.java @@ -0,0 +1,156 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class LocatorInfo +{ + LocatorInfo(Ice.LocatorPrx locator, LocatorAdapterTable adapterTable) + { + _locator = locator; + _adapterTable = adapterTable; + } + + public boolean + equals(java.lang.Object obj) + { + LocatorInfo rhs = null; + try + { + rhs = (LocatorInfo)obj; + } + catch (ClassCastException ex) + { + return false; + } + + return _locator.equals(rhs._locator); + } + + public Ice.LocatorPrx + getLocator() + { + // + // No synchronization necessary, _locator is immutable. + // + return _locator; + } + + public synchronized Ice.LocatorRegistryPrx + getLocatorRegistry() + { + if(_locatorRegistry == null) // Lazy initialization + { + _locatorRegistry = _locator.getRegistry(); + } + + return _locatorRegistry; + } + + public IceInternal.Endpoint[] + getEndpoints(Reference ref, Ice.BooleanHolder cached) + { + IceInternal.Endpoint[] endpoints = null; + cached.value = false; + + if(ref.adapterId.length() > 0) + { + endpoints = _adapterTable.get(ref.adapterId); + if(endpoints == null) + { + // + // Search the adapter in the location service if we didn't + // find it in the cache. + // + try + { + Ice.ObjectPrx object = _locator.findAdapterByName(ref.adapterId); + if(object != null) + { + endpoints = ((Ice.ObjectPrxHelper)object).__reference().endpoints; + } + } + catch(Ice.LocalException ex) + { + // + // Ignore. The proxy will most likely get empty + // endpoints and raise a NoEndpointException(). + // + } + } + else + { + cached.value = true; + } + + if(endpoints != null) + { + if(ref.instance.traceLevels().location >= 1) + { + StringBuffer s = new StringBuffer(); + if(cached.value) + s.append("found object in local locator table\n"); + else + s.append("found object in locator\n"); + s.append("identity = " + Ice.Util.identityToString(ref.identity) + "\n"); + s.append("adapter = " + ref.adapterId + "\n"); + s.append("endpoints = "); + final int sz = endpoints.length; + for(int i = 0; i < sz; i++) + { + s.append(endpoints[i].toString()); + if(i + 1 < sz) + s.append(":"); + } + ref.instance.logger().trace(ref.instance.traceLevels().locationCat, s.toString()); + } + } + } + + return endpoints == null ? new IceInternal.Endpoint[0] : endpoints; + } + + public void + addEndpoints(Reference ref, IceInternal.Endpoint[] endpoints) + { + assert(endpoints.length > 0); + + if(ref.adapterId.length() > 0) + { + _adapterTable.add(ref.adapterId, endpoints); + + if(ref.instance.traceLevels().location >= 2) + { + String s = "added adapter to local locator table\nadapter = " + ref.adapterId; + ref.instance.logger().trace(ref.instance.traceLevels().locationCat, s); + } + } + } + + public void + removeEndpoints(Reference ref) + { + if(ref.adapterId.length() > 0) + { + _adapterTable.remove(ref.adapterId); + + if(ref.instance.traceLevels().location >= 2) + { + String s = "removed adapter from local locator table\nadapter = " + ref.adapterId; + ref.instance.logger().trace(ref.instance.traceLevels().locationCat, s); + } + } + } + + private Ice.LocatorPrx _locator; + private Ice.LocatorRegistryPrx _locatorRegistry; + private LocatorAdapterTable _adapterTable; +}; + diff --git a/java/src/IceInternal/LocatorManager.java b/java/src/IceInternal/LocatorManager.java new file mode 100644 index 00000000000..faf7201bd2e --- /dev/null +++ b/java/src/IceInternal/LocatorManager.java @@ -0,0 +1,65 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +package IceInternal; + +public final class LocatorManager +{ + LocatorManager() + { + } + + synchronized void + destroy() + { + _table.clear(); + _adapterTables.clear(); + } + + // + // Returns locator info for a given locator. Automatically creates + // the locator info if it doesn't exist yet. + // + public LocatorInfo + get(Ice.LocatorPrx locator) + { + if(locator == null) + { + return null; + } + + synchronized (this) + { + LocatorInfo info = (LocatorInfo)_table.get(locator); + if(info == null) + { + // + // Rely on locator identity for the adapter table. We want to + // have only one table per locator (not one per locator + // proxy). + // + LocatorAdapterTable adapterTable = (LocatorAdapterTable)_adapterTables.get(locator.ice_getIdentity()); + if(adapterTable == null) + { + adapterTable = new LocatorAdapterTable(); + _adapterTables.put(locator.ice_getIdentity(), adapterTable); + } + + info = new LocatorInfo(locator, adapterTable); + _table.put(locator, info); + } + + return info; + } + } + + private java.util.HashMap _table = new java.util.HashMap(); + private java.util.HashMap _adapterTables = new java.util.HashMap(); +} diff --git a/java/src/IceInternal/ProxyFactory.java b/java/src/IceInternal/ProxyFactory.java index dcf25adeccc..69c28059ba4 100644 --- a/java/src/IceInternal/ProxyFactory.java +++ b/java/src/IceInternal/ProxyFactory.java @@ -61,7 +61,7 @@ public final class ProxyFactory referenceToProxy(Reference reference) { Ice.ObjectPrxHelper proxy = new Ice.ObjectPrxHelper(); - proxy.setup(reference); + proxy.setup(reference, _retryIntervals); return proxy; } @@ -90,7 +90,38 @@ public final class ProxyFactory ProxyFactory(Instance instance) { _instance = instance; + + String str = _instance.properties().getPropertyWithDefault("Ice.RetryIntervals", "0"); + + String[] arr = str.trim().split("[ \t\n\r]+"); + + if(arr.length > 0) + { + _retryIntervals = new int[arr.length]; + + for(int i = 0; i < arr.length; i++) + { + int v = Integer.parseInt(arr[i]); + + // + // If -1 is the first value, no retry and wait intervals. + // + if(i == 0 && v == -1) + { + _retryIntervals = new int[0]; + break; + } + + _retryIntervals[i] = v > 0 ? v : 0; + } + } + else + { + _retryIntervals = new int[1]; + _retryIntervals[0] = 0; + } } private Instance _instance; + private int[] _retryIntervals; } diff --git a/java/src/IceInternal/Reference.java b/java/src/IceInternal/Reference.java index bb300cf5ba2..e2b6ae743d4 100644 --- a/java/src/IceInternal/Reference.java +++ b/java/src/IceInternal/Reference.java @@ -69,24 +69,35 @@ public final class Reference { return false; } + + if(!adapterId.equals(r.adapterId)) + { + return false; + } + + if(!compare(endpoints, r.endpoints)) + { + return false; + } - if(!compare(origEndpoints, r.origEndpoints)) + if(routerInfo != r.routerInfo) { return false; } - if(!compare(endpoints, r.endpoints)) + if(routerInfo != null && r.routerInfo != null && + !routerInfo.equals(r.routerInfo)) { return false; } - if(routerInfo != r.routerInfo) + if(locatorInfo != r.locatorInfo) { return false; } - if(routerInfo != null && r.routerInfo != null && - !routerInfo.equals(r.routerInfo)) + if(locatorInfo != null && r.locatorInfo != null && + !locatorInfo.equals(r.locatorInfo)) { return false; } @@ -118,24 +129,20 @@ public final class Reference s.writeBool(compress); - s.writeSize(origEndpoints.length); - for(int i = 0; i < origEndpoints.length; i++) - { - origEndpoints[i].streamWrite(s); - } + s.writeSize(endpoints.length); - if(endpointsEqual()) - { - s.writeBool(true); - } - else - { - s.writeBool(false); - s.writeSize(endpoints.length); + if(endpoints.length > 0) + { + assert(adapterId.equals("")); + for(int i = 0; i < endpoints.length; i++) { endpoints[i].streamWrite(s); } + } + else + { + s.writeString(adapterId); } } @@ -197,21 +204,20 @@ public final class Reference s.append(" -c"); } - for(int i = 0; i < origEndpoints.length; i++) - { - s.append(':'); - s.append(origEndpoints[i].toString()); - } + if(endpoints.length > 0) + { + assert(adapterId.equals("")); - if(!endpointsEqual()) - { - s.append(':'); - for(int i = 0; i < endpoints.length; i++) - { - s.append(':'); - s.append(endpoints[i].toString()); - } - } + for(int i = 0; i < endpoints.length; i++) + { + s.append(':'); + s.append(endpoints[i].toString()); + } + } + else + { + s.append(" @ " + adapterId); + } return s.toString(); } @@ -225,9 +231,10 @@ public final class Reference final public int mode; final public boolean secure; final public boolean compress; - final public Endpoint[] origEndpoints; // Original endpoints. + final public String adapterId; final public Endpoint[] endpoints; // Actual endpoints, changed by a location forward. final public RouterInfo routerInfo; // Null if no router is used. + final public LocatorInfo locatorInfo; // Null if no locator is used. final public Ice.ObjectAdapter reverseAdapter; // For reverse comm. using the adapter's incoming connections. final public int hashValue; @@ -244,9 +251,8 @@ public final class Reference } else { - return instance.referenceFactory().create(newIdentity, facet, mode, secure, compress, - origEndpoints, endpoints, - routerInfo, reverseAdapter); + return instance.referenceFactory().create(newIdentity, facet, mode, secure, compress, adapterId, + endpoints, routerInfo, locatorInfo, reverseAdapter); } } @@ -259,9 +265,8 @@ public final class Reference } else { - return instance.referenceFactory().create(identity, newFacet, mode, secure, compress, - origEndpoints, endpoints, - routerInfo, reverseAdapter); + return instance.referenceFactory().create(identity, newFacet, mode, secure, compress, adapterId, + endpoints, routerInfo, locatorInfo, reverseAdapter); } } @@ -271,12 +276,6 @@ public final class Reference // // We change the timeout settings in all endpoints. // - Endpoint[] newOrigEndpoints = new Endpoint[origEndpoints.length]; - for(int i = 0; i < origEndpoints.length; i++) - { - newOrigEndpoints[i] = origEndpoints[i].timeout(timeout); - } - Endpoint[] newEndpoints = new Endpoint[endpoints.length]; for(int i = 0; i < endpoints.length; i++) { @@ -304,9 +303,20 @@ public final class Reference } } - return instance.referenceFactory().create(identity, facet, mode, secure, compress, - newOrigEndpoints, newEndpoints, - newRouterInfo, reverseAdapter); + // + // If we have a locator, we also change the timeout settings + // on the locator. + // + LocatorInfo newLocatorInfo = null; + if(locatorInfo != null) + { + Ice.LocatorPrx newLocator = + Ice.LocatorPrxHelper.uncheckedCast(locatorInfo.getLocator().ice_timeout(timeout)); + newLocatorInfo = instance.locatorManager().get(newLocator); + } + + return instance.referenceFactory().create(identity, facet, mode, secure, compress, adapterId, + endpoints, newRouterInfo, newLocatorInfo, reverseAdapter); } public Reference @@ -318,9 +328,8 @@ public final class Reference } else { - return instance.referenceFactory().create(identity, facet, newMode, secure, compress, - origEndpoints, endpoints, - routerInfo, reverseAdapter); + return instance.referenceFactory().create(identity, facet, newMode, secure, compress, adapterId, + endpoints, routerInfo, locatorInfo, reverseAdapter); } } @@ -333,9 +342,8 @@ public final class Reference } else { - return instance.referenceFactory().create(identity, facet, mode, newSecure, compress, - origEndpoints, endpoints, - routerInfo, reverseAdapter); + return instance.referenceFactory().create(identity, facet, mode, newSecure, compress, adapterId, + endpoints, routerInfo, locatorInfo, reverseAdapter); } } @@ -348,13 +356,26 @@ public final class Reference } else { - return instance.referenceFactory().create(identity, facet, mode, secure, newCompress, - origEndpoints, endpoints, - routerInfo, reverseAdapter); + return instance.referenceFactory().create(identity, facet, mode, secure, newCompress, adapterId, + endpoints, routerInfo, locatorInfo, reverseAdapter); } } public Reference + changeAdapterId(String newAdapterId) + { + if(adapterId.equals(newAdapterId)) + { + return this; + } + else + { + return instance.referenceFactory().create(identity, facet, mode, secure, compress, newAdapterId, + endpoints, routerInfo, locatorInfo, reverseAdapter); + } + } + + public Reference changeEndpoints(Endpoint[] newEndpoints) { if(compare(newEndpoints, endpoints)) @@ -363,9 +384,8 @@ public final class Reference } else { - return instance.referenceFactory().create(identity, facet, mode, secure, compress, - origEndpoints, newEndpoints, - routerInfo, reverseAdapter); + return instance.referenceFactory().create(identity, facet, mode, secure, compress, adapterId, + newEndpoints, routerInfo, locatorInfo, reverseAdapter); } } @@ -381,18 +401,33 @@ public final class Reference } else { - return instance.referenceFactory().create(identity, facet, mode, secure, compress, - origEndpoints, endpoints, - newRouterInfo, reverseAdapter); + return instance.referenceFactory().create(identity, facet, mode, secure, compress, adapterId, + endpoints, newRouterInfo, locatorInfo, reverseAdapter); + } + } + + public Reference + changeLocator(Ice.LocatorPrx newLocator) + { + LocatorInfo newLocatorInfo = instance.locatorManager().get(newLocator); + + if((locatorInfo == newLocatorInfo) || + (locatorInfo != null && newLocatorInfo != null && newLocatorInfo.equals(locatorInfo))) + { + return this; + } + else + { + return instance.referenceFactory().create(identity, facet, mode, secure, compress, adapterId, + endpoints, routerInfo, newLocatorInfo, reverseAdapter); } } public Reference changeDefault() { - return instance.referenceFactory().create(identity, "", ModeTwoway, false, false, - origEndpoints, origEndpoints, - null, null); + return instance.referenceFactory().create(identity, "", ModeTwoway, false, false, adapterId, endpoints, + null, null, null); } // @@ -404,20 +439,27 @@ public final class Reference int md, boolean sec, boolean com, - Endpoint[] origEndpts, + String adptId, Endpoint[] endpts, RouterInfo rtrInfo, + LocatorInfo locInfo, Ice.ObjectAdapter rvAdapter) { + // + // It's either adapter id or endpoints, it can't be both. + // + assert(!(!adptId.equals("") && !(endpts.length == 0))); + instance = inst; identity = ident; facet = fac; mode = md; secure = sec; compress = com; - origEndpoints = origEndpts; + adapterId = adptId; endpoints = endpts; routerInfo = rtrInfo; + locatorInfo = locInfo; reverseAdapter = rvAdapter; int h = 0; @@ -455,21 +497,6 @@ public final class Reference hashValue = h; } - // - // Check if origEndpoints == endpoints - // - private boolean - endpointsEqual() - { - if(_checkEndpointsEqual) - { - _endpointsEqual = compare(origEndpoints, endpoints); - _checkEndpointsEqual = false; - } - - return _endpointsEqual; - } - private boolean compare(Endpoint[] arr1, Endpoint[] arr2) { @@ -493,7 +520,4 @@ public final class Reference return false; } - - private boolean _endpointsEqual = false; - private boolean _checkEndpointsEqual = true; } diff --git a/java/src/IceInternal/ReferenceFactory.java b/java/src/IceInternal/ReferenceFactory.java index 0c4ba06f836..2d768b1c756 100644 --- a/java/src/IceInternal/ReferenceFactory.java +++ b/java/src/IceInternal/ReferenceFactory.java @@ -18,9 +18,10 @@ public final class ReferenceFactory int mode, boolean secure, boolean compress, - Endpoint[] origEndpoints, + String adapterId, Endpoint[] endpoints, RouterInfo routerInfo, + LocatorInfo locatorInfo, Ice.ObjectAdapter reverseAdapter) { if(_instance == null) @@ -31,9 +32,8 @@ public final class ReferenceFactory // // Create a new reference // - Reference ref = new Reference(_instance, ident, facet, mode, secure, compress, - origEndpoints, endpoints, - routerInfo, reverseAdapter); + Reference ref = new Reference(_instance, ident, facet, mode, secure, compress, adapterId, + endpoints, routerInfo, locatorInfo, reverseAdapter); // // If we already have an equivalent reference, use such equivalent @@ -77,6 +77,9 @@ public final class ReferenceFactory } int colon = s.indexOf(':'); + if(colon == -1) + colon = s.indexOf('@'); + String init; if(colon == -1) { @@ -93,6 +96,7 @@ public final class ReferenceFactory int mode = Reference.ModeTwoway; boolean secure = false; boolean compress = false; + String adapter = ""; int i = 1; while(i < arr.length) @@ -210,63 +214,43 @@ public final class ReferenceFactory } } - java.util.ArrayList origEndpoints = new java.util.ArrayList(); java.util.ArrayList endpoints = new java.util.ArrayList(); - boolean orig = true; - final int len = s.length(); - int end = colon; - while(end < len && s.charAt(end) == ':') - { - int beg = end + 1; - - end = s.indexOf(':', beg); - if(end == -1) - { - end = len; - } - - if(beg == end) // "::" - { - if(!orig) - { - throw new Ice.ProxyParseException(); - } - - orig = false; - continue; - } - - String es = s.substring(beg, end); - Endpoint endp = _instance.endpointFactoryManager().create(es); - - if(orig) - { - origEndpoints.add(endp); - } - else - { - endpoints.add(endp); - } - } - - if(orig) - { - endpoints = origEndpoints; - } - - if(origEndpoints.size() == 0 || endpoints.size() == 0) - { - throw new Ice.ProxyParseException(); - } + if(colon != -1) + { + if(s.charAt(colon) == ':') + { + final int len = s.length(); + int end = colon; + while(end < len && s.charAt(end) == ':') + { + int beg = end + 1; + + end = s.indexOf(':', beg); + if(end == -1) + { + end = len; + } + + String es = s.substring(beg, end); + Endpoint endp = _instance.endpointFactoryManager().create(es); + endpoints.add(endp); + } + } + else if(s.charAt(colon) == '@') + { + init = s.substring(colon + 1, s.length()).trim(); + arr = init.split("[ \t\n\r]+"); + adapter = arr[0]; + } + } - Endpoint[] origEndp = new Endpoint[origEndpoints.size()]; - origEndpoints.toArray(origEndp); Endpoint[] endp = new Endpoint[endpoints.size()]; endpoints.toArray(endp); RouterInfo routerInfo = _instance.routerManager().get(getDefaultRouter()); - return create(ident, facet, mode, secure, compress, origEndp, endp, routerInfo, null); + LocatorInfo locatorInfo = _instance.locatorManager().get(getDefaultLocator()); + return create(ident, facet, mode, secure, compress, adapter, endp, routerInfo, locatorInfo, null); } public Reference @@ -289,33 +273,27 @@ public final class ReferenceFactory boolean compress = s.readBool(); - Endpoint[] origEndpoints; Endpoint[] endpoints; + String adapterId = ""; int sz = s.readSize(); - origEndpoints = new Endpoint[sz]; - for(int i = 0; i < sz; i++) - { - origEndpoints[i] = _instance.endpointFactoryManager().read(s); - } - - boolean same = s.readBool(); - if(same) // origEndpoints == endpoints - { - endpoints = origEndpoints; - } - else - { - sz = s.readSize(); - endpoints = new Endpoint[sz]; - for(int i = 0; i < sz; i++) - { - endpoints[i] = _instance.endpointFactoryManager().read(s); - } - } + if(sz > 0) + { + endpoints = new Endpoint[sz]; + for(int i = 0; i < sz; i++) + { + endpoints[i] = _instance.endpointFactoryManager().read(s); + } + } + else + { + endpoints = new Endpoint[0]; + adapterId = s.readString(); + } RouterInfo routerInfo = _instance.routerManager().get(getDefaultRouter()); - return create(ident, facet, mode, secure, compress, origEndpoints, endpoints, routerInfo, null); + LocatorInfo locatorInfo = _instance.locatorManager().get(getDefaultLocator()); + return create(ident, facet, mode, secure, compress, adapterId, endpoints, routerInfo, locatorInfo, null); } public synchronized void @@ -330,6 +308,18 @@ public final class ReferenceFactory return _defaultRouter; } + public synchronized void + setDefaultLocator(Ice.LocatorPrx defaultLocator) + { + _defaultLocator = defaultLocator; + } + + public synchronized Ice.LocatorPrx + getDefaultLocator() + { + return _defaultLocator; + } + // // Only for use by Instance // @@ -348,10 +338,12 @@ public final class ReferenceFactory _instance = null; _defaultRouter = null; + _defaultLocator = null; _references.clear(); } private Instance _instance; private Ice.RouterPrx _defaultRouter; + private Ice.LocatorPrx _defaultLocator; private java.util.WeakHashMap _references = new java.util.WeakHashMap(); } diff --git a/java/src/IceInternal/TraceLevels.java b/java/src/IceInternal/TraceLevels.java index 22c6883e8d0..b00e65e7b74 100644 --- a/java/src/IceInternal/TraceLevels.java +++ b/java/src/IceInternal/TraceLevels.java @@ -18,6 +18,7 @@ public final class TraceLevels protocolCat = "Protocol"; retryCat = "Retry"; securityCat = "Security"; + locationCat = "Location"; final String keyBase = "Ice.Trace."; @@ -25,6 +26,7 @@ public final class TraceLevels protocol = properties.getPropertyAsInt(keyBase + protocolCat); retry = properties.getPropertyAsInt(keyBase + retryCat); security = properties.getPropertyAsInt(keyBase + securityCat); + location = properties.getPropertyAsInt(keyBase + locationCat); } final public int network; @@ -35,4 +37,6 @@ public final class TraceLevels final public String retryCat; final public int security; final public String securityCat; + final public int location; + final public String locationCat; } |