diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/IceInternal/Instance.java | 2 | ||||
-rw-r--r-- | java/src/IceInternal/LocatorInfo.java | 843 | ||||
-rw-r--r-- | java/src/IceInternal/LocatorManager.java | 7 | ||||
-rw-r--r-- | java/src/IceInternal/LocatorTable.java | 44 | ||||
-rw-r--r-- | java/src/IceInternal/PropertyNames.java | 3 | ||||
-rw-r--r-- | java/src/IceInternal/ProxyFactory.java | 6 |
6 files changed, 409 insertions, 496 deletions
diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java index bf5b9831311..1764476cf1d 100644 --- a/java/src/IceInternal/Instance.java +++ b/java/src/IceInternal/Instance.java @@ -684,7 +684,7 @@ public final class Instance _routerManager = new RouterManager(); - _locatorManager = new LocatorManager(); + _locatorManager = new LocatorManager(_initData.properties); _referenceFactory = new ReferenceFactory(this, communicator); diff --git a/java/src/IceInternal/LocatorInfo.java b/java/src/IceInternal/LocatorInfo.java index 5e7938a3ce2..bcf28e5865d 100644 --- a/java/src/IceInternal/LocatorInfo.java +++ b/java/src/IceInternal/LocatorInfo.java @@ -11,329 +11,324 @@ package IceInternal; public final class LocatorInfo { - private interface RequestCallback + interface GetEndpointsCallback { - public void response(LocatorInfo locatorInfo, Ice.ObjectPrx proxy); - public void exception(LocatorInfo locatorInfo, Exception ex); - }; + void setEndpoints(EndpointI[] endpoints, boolean cached); + void setException(Ice.LocalException ex); + } - private abstract class Request + private class RequestCallback { - synchronized public void - addCallback(RequestCallback callback) + public void + response(LocatorInfo locatorInfo, Ice.ObjectPrx proxy) { - if(_response) + EndpointI[] endpoints = null; + if(proxy != null) { - callback.response(_locatorInfo, _proxy); - return; + Reference r = ((Ice.ObjectPrxHelperBase)proxy).__reference(); + if(!r.isIndirect()) + { + endpoints = r.getEndpoints(); + } + else if(_ref.isWellKnown() && !r.isWellKnown()) + { + // + // We're resolving the endpoints of a well-known object and the proxy returned + // by the locator is an indirect proxy. We now need to resolve the endpoints + // of this indirect proxy. + // + locatorInfo.getEndpoints(r, _ref, _ttl, _callback); + return; + } } - else if(_exception != null) + + if(_ref.getInstance().traceLevels().location >= 1) { - callback.exception(_locatorInfo, _exception); - return; + locatorInfo.getEndpointsTrace(_ref, endpoints, false); } + if(_callback != null) + { + _callback.setEndpoints(endpoints == null ? new EndpointI[0] : endpoints, false); + } + } - _callbacks.add(callback); - - if(!_sent) + public void + exception(LocatorInfo locatorInfo, Exception exc) + { + try { - _sent = true; - try - { - send(); - } - catch(Exception ex) + locatorInfo.getEndpointsException(_ref, exc); // This throws. + } + catch(Ice.LocalException ex) + { + if(_callback != null) { - exception(ex); + _callback.setException(ex); } } } - synchronized public Ice.ObjectPrx - getProxy() - throws Exception + RequestCallback(Reference ref, int ttl, GetEndpointsCallback cb) + { + _ref = ref; + _ttl = ttl; + _callback = cb; + } + + final Reference _ref; + final int _ttl; + final GetEndpointsCallback _callback; + }; + + private abstract class Request + { + synchronized public void + addCallback(Reference ref, Reference wellKnownRef, int ttl, GetEndpointsCallback cb) { + RequestCallback callback = new RequestCallback(ref, ttl, cb); if(_response) { - return _proxy; + callback.response(_locatorInfo, _proxy); } else if(_exception != null) { - throw _exception; + callback.exception(_locatorInfo, _exception); } - - if(!_sent) + else { - _sent = true; - try + _callbacks.add(callback); + if(wellKnownRef != null) // This request is to resolve the endpoints of a cached well-known object ref { - send(); + _wellKnownRefs.add(wellKnownRef); } - catch(Exception ex) + if(!_sent) { - exception(ex); + _sent = true; + send(true); } } - - while(!_response && _exception == null) + } + + synchronized EndpointI[] + getEndpoints(Reference ref, Reference wellKnownRef, int ttl, Ice.BooleanHolder cached) + { + if(!_response || _exception == null) { - try + if(wellKnownRef != null) // This request is to resolve the endpoints of a cached well-known object ref { - wait(); + _wellKnownRefs.add(wellKnownRef); } - catch(java.lang.InterruptedException ex) + if(!_sent) { + _sent = true; + send(true); + } + + while(!_response && _exception == null) + { + try + { + wait(); + } + catch(java.lang.InterruptedException ex) + { + } } } - + if(_exception != null) { - throw _exception; + _locatorInfo.getEndpointsException(ref, _exception); // This throws. } + assert(_response); - return _proxy; + EndpointI[] endpoints = null; + if(_proxy != null) + { + Reference r = ((Ice.ObjectPrxHelperBase)_proxy).__reference(); + if(!r.isIndirect()) + { + endpoints = r.getEndpoints(); + } + else if(ref.isWellKnown() && !r.isWellKnown()) + { + // + // We're resolving the endpoints of a well-known object and the proxy returned + // by the locator is an indirect proxy. We now need to resolve the endpoints + // of this indirect proxy. + // + return _locatorInfo.getEndpoints(r, ref, ttl, cached); + } + } + + cached.value = false; + if(_ref.getInstance().traceLevels().location >= 1) + { + _locatorInfo.getEndpointsTrace(ref, endpoints, false); + } + return endpoints == null ? new EndpointI[0] : endpoints; } - - protected - Request(LocatorInfo locatorInfo) + + Request(LocatorInfo locatorInfo, Reference ref) { _locatorInfo = locatorInfo; - _sent = false; + _ref = ref; + _sent = false; _response = false; } synchronized protected void response(Ice.ObjectPrx proxy) { + _locatorInfo.finishRequest(_ref, _wellKnownRefs, proxy, false); _response = true; _proxy = proxy; - for(RequestCallback c : _callbacks) + for(RequestCallback callback : _callbacks) { - c.response(_locatorInfo, proxy); + callback.response(_locatorInfo, proxy); } notifyAll(); } - synchronized protected void + protected void exception(Exception ex) { - _exception = ex; - for(RequestCallback c : _callbacks) + if(ex instanceof Ice.CollocationOptimizationException) + { + send(false); // Use synchronous collocation optimized locator request instead. + return; + } + + synchronized(this) { - c.exception(_locatorInfo, ex); + _locatorInfo.finishRequest(_ref, _wellKnownRefs, null, ex instanceof Ice.UserException); + _exception = ex; + for(RequestCallback callback : _callbacks) + { + callback.exception(_locatorInfo, ex); + } + notifyAll(); } - notifyAll(); } - protected abstract void send(); + protected abstract void send(boolean async); final protected LocatorInfo _locatorInfo; + final protected Reference _ref; private java.util.List<RequestCallback> _callbacks = new java.util.ArrayList<RequestCallback>(); + private java.util.List<Reference> _wellKnownRefs = new java.util.ArrayList<Reference>(); private boolean _sent; private boolean _response; private Ice.ObjectPrx _proxy; private Exception _exception; }; - interface GetEndpointsCallback - { - void setEndpoints(EndpointI[] endpoints, boolean cached); - void setException(Ice.LocalException ex); - } - private class ObjectRequest extends Request { - public ObjectRequest(LocatorInfo locatorInfo, Ice.Identity id) + public ObjectRequest(LocatorInfo locatorInfo, Reference reference) { - super(locatorInfo); - _id = id; + super(locatorInfo, reference); + assert(reference.isWellKnown()); } protected void - send() + send(boolean async) { - _locatorInfo.getLocator().findObjectById_async( - new Ice.AMI_Locator_findObjectById() - { - public void - ice_response(Ice.ObjectPrx proxy) - { - _locatorInfo.removeObjectRequest(_id); - response(proxy); - } - - public void - ice_exception(Ice.UserException ex) - { - _locatorInfo.removeObjectRequest(_id); - exception(ex); - } - - public void - ice_exception(Ice.LocalException ex) - { - _locatorInfo.removeObjectRequest(_id); - exception(ex); - } - }, - _id); - } - - private final Ice.Identity _id; - }; - - private class AdapterRequest extends Request - { - public AdapterRequest(LocatorInfo locatorInfo, String id) - { - super(locatorInfo); - _id = id; - } - - protected void - send() - { - _locatorInfo.getLocator().findAdapterById_async( - new Ice.AMI_Locator_findAdapterById() - { - public void - ice_response(Ice.ObjectPrx proxy) - { - _locatorInfo.removeAdapterRequest(_id); - response(proxy); - } - - public void - ice_exception(Ice.UserException ex) - { - _locatorInfo.removeAdapterRequest(_id); - exception(ex); - } - - public void - ice_exception(Ice.LocalException ex) - { - _locatorInfo.removeAdapterRequest(_id); - exception(ex); - } - }, - _id); - } - - private final String _id; - }; - - private class ObjectRequestCallback implements RequestCallback - { - public void - response(LocatorInfo locatorInfo, Ice.ObjectPrx object) - { - locatorInfo.getWellKnownObjectEndpoints(_reference, object, _ttl, false, _callback); - } - - public void - exception(LocatorInfo locatorInfo, Exception ex) - { - if(ex instanceof Ice.CollocationOptimizationException) + try { - try + if(async) { - Ice.BooleanHolder cached = new Ice.BooleanHolder(); - _callback.setEndpoints(locatorInfo.getEndpoints(_reference, _ttl, cached), cached.value); + _locatorInfo.getLocator().findObjectById_async( + new Ice.AMI_Locator_findObjectById() + { + public void + ice_response(Ice.ObjectPrx proxy) + { + response(proxy); + } + + public void + ice_exception(Ice.UserException ex) + { + exception(ex); + } + + public void + ice_exception(Ice.LocalException ex) + { + exception(ex); + } + }, + _ref.getIdentity()); } - catch(Ice.LocalException e) + else { - _callback.setException(e); + response(_locatorInfo.getLocator().findObjectById(_ref.getIdentity())); } } - else + catch(Exception ex) { - locatorInfo.getEndpointsException(_reference, ex, _callback); + exception(ex); } } - - public - ObjectRequestCallback(Reference ref, int ttl, GetEndpointsCallback cb) - { - _reference = ref; - _ttl = ttl; - _callback = cb; - } - - private final Reference _reference; - private final int _ttl; - private final GetEndpointsCallback _callback; }; - private class AdapterRequestCallback implements RequestCallback + private class AdapterRequest extends Request { - public void - response(LocatorInfo locatorInfo, Ice.ObjectPrx object) + public AdapterRequest(LocatorInfo locatorInfo, Reference reference) { - EndpointI[] endpoints = null; - if(object != null) - { - endpoints = ((Ice.ObjectPrxHelperBase)object).__reference().getEndpoints(); - if(endpoints.length > 0) - { - locatorInfo.getTable().addAdapterEndpoints(_reference.getAdapterId(), endpoints); - } - } - - if(_reference.getInstance().traceLevels().location >= 1) - { - locatorInfo.getEndpointsTrace(_reference, endpoints, false); - } - - if(endpoints == null) - { - _callback.setEndpoints(new EndpointI[0], false); - } - else - { - _callback.setEndpoints(endpoints, false); - } + super(locatorInfo, reference); + assert(reference.isIndirect()); } - - public void - exception(LocatorInfo locatorInfo, Exception ex) + + protected void + send(boolean async) { - if(ex instanceof Ice.CollocationOptimizationException) + try { - try + if(async) { - Ice.BooleanHolder cached = new Ice.BooleanHolder(); - _callback.setEndpoints(getEndpoints(_reference, _ttl, cached), cached.value); + _locatorInfo.getLocator().findAdapterById_async( + new Ice.AMI_Locator_findAdapterById() + { + public void + ice_response(Ice.ObjectPrx proxy) + { + response(proxy); + } + + public void + ice_exception(Ice.UserException ex) + { + exception(ex); + } + + public void + ice_exception(Ice.LocalException ex) + { + exception(ex); + } + }, + _ref.getAdapterId()); } - catch(Ice.LocalException e) + else { - _callback.setException(e); + response(_locatorInfo.getLocator().findAdapterById(_ref.getAdapterId())); } } - else + catch(Exception ex) { - getEndpointsException(_reference, ex, _callback); + exception(ex); } } - - public - AdapterRequestCallback(Reference ref, int ttl, GetEndpointsCallback callback) - { - _reference = ref; - _ttl = ttl; - _callback = callback; - } - - private final Reference _reference; - private final int _ttl; - private final GetEndpointsCallback _callback; }; - LocatorInfo(Ice.LocatorPrx locator, LocatorTable table) + LocatorInfo(Ice.LocatorPrx locator, LocatorTable table, boolean background) { _locator = locator; _table = table; + _background = background; } synchronized public void @@ -387,195 +382,130 @@ public final class LocatorInfo public EndpointI[] getEndpoints(Reference ref, int ttl, Ice.BooleanHolder cached) { - assert(ref.isIndirect()); + return getEndpoints(ref, null, ttl, cached); + } + public EndpointI[] + getEndpoints(Reference ref, Reference wellKnownRef, int ttl, Ice.BooleanHolder cached) + { + assert(ref.isIndirect()); EndpointI[] endpoints = null; - Ice.ObjectPrx object = null; - cached.value = true; - String adapterId = ref.getAdapterId(); - Ice.Identity identity = ref.getIdentity(); - - try + cached.value = false; + if(!ref.isWellKnown()) { - if(adapterId.length() > 0) + endpoints = _table.getAdapterEndpoints(ref.getAdapterId(), ttl, cached); + if(!cached.value) { - endpoints = _table.getAdapterEndpoints(adapterId, ttl); - if(endpoints == null) + if(_background && endpoints != null) { - cached.value = false; - - if(ref.getInstance().traceLevels().location >= 1) - { - StringBuffer s = new StringBuffer(); - s.append("searching for adapter by id\n"); - s.append("adapter = " + adapterId); - ref.getInstance().initializationData().logger.trace( - ref.getInstance().traceLevels().locationCat, s.toString()); - } - - // - // Search the adapter in the location service if we didn't - // find it in the cache. - // - Request request = getAdapterRequest(adapterId); - object = request.getProxy(); - if(object != null) - { - endpoints = ((Ice.ObjectPrxHelperBase)object).__reference().getEndpoints(); - - if(endpoints.length > 0) - { - _table.addAdapterEndpoints(adapterId, endpoints); - } - } + getAdapterRequest(ref).addCallback(ref, wellKnownRef, ttl, null); } - } - else - { - boolean objectCached = true; - object = _table.getProxy(identity, ttl); - if(object == null) + else { - objectCached = false; - - if(ref.getInstance().traceLevels().location >= 1) - { - StringBuffer s = new StringBuffer(); - s.append("searching for object by id\n"); - s.append("object = " + ref.getInstance().identityToString(identity)); - ref.getInstance().initializationData().logger.trace( - ref.getInstance().traceLevels().locationCat, s.toString()); - } - - Request request = getObjectRequest(identity); - object = request.getProxy(); + return getAdapterRequest(ref).getEndpoints(ref, wellKnownRef, ttl, cached); } - - boolean endpointsCached = true; - if(object != null) + } + } + else + { + Reference r = _table.getObjectReference(ref.getIdentity(), ttl, cached); + if(!cached.value) + { + if(_background && r != null) { - Reference r = ((Ice.ObjectPrxHelperBase)object).__reference(); - if(!r.isIndirect()) - { - endpointsCached = false; - endpoints = r.getEndpoints(); - } - else if(!r.isWellKnown()) - { - Ice.BooleanHolder c = new Ice.BooleanHolder(); - endpoints = getEndpoints(r, ttl, c); - endpointsCached = c.value; - } + getObjectRequest(ref).addCallback(ref, null, ttl, null); } - - if(!objectCached && endpoints != null && endpoints.length > 0) + else { - _table.addProxy(identity, object); + return getObjectRequest(ref).getEndpoints(ref, null, ttl, cached); } - - cached.value = objectCached || endpointsCached; + } + + if(!r.isIndirect()) + { + endpoints = r.getEndpoints(); + } + else if(!r.isWellKnown()) + { + return getEndpoints(r, ref, ttl, cached); } } - catch(Exception ex) - { - getEndpointsException(ref, ex); - } - + + assert(endpoints != null); + cached.value = true; if(ref.getInstance().traceLevels().location >= 1) { - getEndpointsTrace(ref, endpoints, cached.value); + getEndpointsTrace(ref, endpoints, true); } + return endpoints; + } - return endpoints == null ? new EndpointI[0] : endpoints; + public void + getEndpoints(Reference ref, int ttl, GetEndpointsCallback callback) + { + getEndpoints(ref, null, ttl, callback); } public void - getEndpoints(final Reference ref, final int ttl, final GetEndpointsCallback callback) + getEndpoints(Reference ref, Reference wellKnownRef, int ttl, GetEndpointsCallback callback) { - final String adapterId = ref.getAdapterId(); - final Ice.Identity identity = ref.getIdentity(); - final Instance instance = ref.getInstance(); - if(adapterId.length() > 0) + assert(ref.isIndirect()); + EndpointI[] endpoints = null; + Ice.BooleanHolder cached = new Ice.BooleanHolder(); + if(!ref.isWellKnown()) { - EndpointI[] endpoints = _table.getAdapterEndpoints(adapterId, ttl); - if(endpoints == null) + endpoints = _table.getAdapterEndpoints(ref.getAdapterId(), ttl, cached); + if(!cached.value) { - if(instance.traceLevels().location >= 1) + if(_background && endpoints != null) { - StringBuffer s = new StringBuffer(); - s.append("searching for adapter by id\n"); - s.append("adapter = " + adapterId); - instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.toString()); + getAdapterRequest(ref).addCallback(ref, wellKnownRef, ttl, null); } - - // - // Search the adapter in the location service if we didn't - // find it in the cache. - // - Request request = getAdapterRequest(adapterId); - request.addCallback(new AdapterRequestCallback(ref, ttl, callback)); - return; - } - else - { - if(instance.traceLevels().location >= 1) + else { - getEndpointsTrace(ref, endpoints, true); + getAdapterRequest(ref).addCallback(ref, wellKnownRef, ttl, callback); + return; } - callback.setEndpoints(endpoints, true); - return; } } else { - Ice.ObjectPrx object = _table.getProxy(identity, ttl); - if(object == null) + Reference r = _table.getObjectReference(ref.getIdentity(), ttl, cached); + if(!cached.value) { - if(instance.traceLevels().location >= 1) + if(_background && r != null) { - StringBuffer s = new StringBuffer(); - s.append("searching for object by id\n"); - s.append("object = " + instance.identityToString(identity)); - instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.toString()); + getObjectRequest(ref).addCallback(ref, null, ttl, null); } + else + { + getObjectRequest(ref).addCallback(ref, null, ttl, callback); + return; + } + } - Request request = getObjectRequest(identity); - request.addCallback(new ObjectRequestCallback(ref, ttl, callback)); - return; + if(!r.isIndirect()) + { + endpoints = r.getEndpoints(); } - else + else if(!r.isWellKnown()) { - getWellKnownObjectEndpoints(ref, object, ttl, true, callback); + getEndpoints(r, ref, ttl, callback); return; } } - } - public void - clearObjectCache(Reference ref) - { - assert(ref.isIndirect()); - if(ref.isWellKnown()) + assert(endpoints != null); + if(ref.getInstance().traceLevels().location >= 1) { - Ice.ObjectPrx object = _table.removeProxy(ref.getIdentity()); - if(object != null) - { - Reference r = ((Ice.ObjectPrxHelperBase)object).__reference(); - if(!r.isIndirect()) - { - if(ref.getInstance().traceLevels().location >= 2) - { - trace("removed endpoints from locator table", ref, r.getEndpoints()); - } - } - else if(!r.isWellKnown()) - { - clearCache(r); - } - } + getEndpointsTrace(ref, endpoints, true); + } + if(callback != null) + { + callback.setEndpoints(endpoints, true); } } - + public void clearCache(Reference ref) { @@ -592,10 +522,9 @@ public final class LocatorInfo } else { - Ice.ObjectPrx object = _table.removeProxy(ref.getIdentity()); - if(object != null) + Reference r = _table.removeObjectReference(ref.getIdentity()); + if(r != null) { - Reference r = ((Ice.ObjectPrxHelperBase)object).__reference(); if(!r.isIndirect()) { if(ref.getInstance().traceLevels().location >= 2) @@ -713,88 +642,6 @@ public final class LocatorInfo } private void - getEndpointsException(Reference ref, Exception exc, GetEndpointsCallback callback) - { - try - { - getEndpointsException(ref, exc); - } - catch(Ice.LocalException ex) - { - callback.setException(ex); - } - catch(Exception ex) - { - assert(false); - } - } - - private void - getWellKnownObjectEndpoints(final Reference ref, - final Ice.ObjectPrx object, - final int ttl, - final boolean objectCached, - final GetEndpointsCallback callback) - { - EndpointI[] endpoints = null; - if(object != null) - { - Reference r = ((Ice.ObjectPrxHelperBase)object).__reference(); - if(!r.isIndirect()) - { - endpoints = r.getEndpoints(); - } - else if(!r.isWellKnown()) - { - getEndpoints(r, ttl, new GetEndpointsCallback() - { - public void - setEndpoints(EndpointI[] endpoints, boolean endpointsCached) - { - if(!objectCached && endpoints != null && endpoints.length > 0) - { - _table.addProxy(ref.getIdentity(), object); - } - - if(ref.getInstance().traceLevels().location >= 1) - { - getEndpointsTrace(ref, endpoints, objectCached || endpointsCached); - } - - callback.setEndpoints(endpoints, objectCached || endpointsCached); - } - - public void - setException(Ice.LocalException ex) - { - callback.setException(ex); - } - }); - return; - } - } - - if(!objectCached && endpoints != null && endpoints.length > 0) - { - _table.addProxy(ref.getIdentity(), object); - } - - if(ref.getInstance().traceLevels().location >= 1) - { - getEndpointsTrace(ref, endpoints, objectCached); - } - - if(endpoints == null) - { - callback.setEndpoints(new EndpointI[0], false); - } - else - { - callback.setEndpoints(endpoints, objectCached); - } - } - - private void getEndpointsTrace(Reference ref, EndpointI[] endpoints, boolean cached) { if(endpoints != null && endpoints.length > 0) @@ -828,55 +675,107 @@ public final class LocatorInfo } synchronized private Request - getAdapterRequest(String id) + getAdapterRequest(Reference ref) { - Request request = _adapterRequests.get(id); + if(ref.getInstance().traceLevels().location >= 1) + { + Instance instance = ref.getInstance(); + StringBuffer s = new StringBuffer(); + s.append("searching for adapter by id\nadapter="); + s.append(ref.getAdapterId()); + instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.toString()); + } + + Request request = _adapterRequests.get(ref.getAdapterId()); if(request != null) { return request; } - - request = new AdapterRequest(this, id); - _adapterRequests.put(id, request); + request = new AdapterRequest(this, ref); + _adapterRequests.put(ref.getAdapterId(), request); return request; } - synchronized private void - removeAdapterRequest(String id) - { - assert(_adapterRequests.get(id) != null); - _adapterRequests.remove(id); - } - synchronized private Request - getObjectRequest(Ice.Identity id) + getObjectRequest(Reference ref) { - Request request = _objectRequests.get(id); + if(ref.getInstance().traceLevels().location >= 1) + { + Instance instance = ref.getInstance(); + StringBuffer s = new StringBuffer(); + s.append("searching for object by id\nobject = "); + s.append(instance.identityToString(ref.getIdentity())); + instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.toString()); + } + + Request request = _objectRequests.get(ref.getIdentity()); if(request != null) { return request; } - - request = new ObjectRequest(this, id); - _objectRequests.put(id, request); + request = new ObjectRequest(this, ref); + _objectRequests.put(ref.getIdentity(), request); return request; } - synchronized private void - removeObjectRequest(Ice.Identity id) + private void + finishRequest(Reference ref, java.util.List<Reference> wellKnownRefs, Ice.ObjectPrx proxy, boolean notRegistered) { - assert(_objectRequests.get(id) != null); - _objectRequests.remove(id); - } + if(proxy == null || ((Ice.ObjectPrxHelperBase)proxy).__reference().isIndirect()) + { + // + // Remove the cached references of well-known objects for which we tried + // to resolved the endpoints if these endpoints are empty. + // + for(Reference r : wellKnownRefs) + { + _table.removeObjectReference(r.getIdentity()); + } + } + + if(!ref.isWellKnown()) + { + if(proxy != null && !((Ice.ObjectPrxHelperBase)proxy).__reference().isIndirect()) + { + // Cache the adapter endpoints. + _table.addAdapterEndpoints(ref.getAdapterId(), + ((Ice.ObjectPrxHelperBase)proxy).__reference().getEndpoints()); + } + else if(notRegistered) // If the adapter isn't registered anymore, remove it from the cache. + { + _table.removeAdapterEndpoints(ref.getAdapterId()); + } + + synchronized(this) + { + assert(_adapterRequests.get(ref.getAdapterId()) != null); + _adapterRequests.remove(ref.getAdapterId()); + } + } + else + { + if(proxy != null && !((Ice.ObjectPrxHelperBase)proxy).__reference().isWellKnown()) + { + // Cache the well-known object reference. + _table.addObjectReference(ref.getIdentity(), ((Ice.ObjectPrxHelperBase)proxy).__reference()); + } + else if(notRegistered) // If the well-known object isn't registered anymore, remove it from the cache. + { + _table.removeObjectReference(ref.getIdentity()); + } - LocatorTable getTable() - { - return _table; + synchronized(this) + { + assert(_objectRequests.get(ref.getIdentity()) != null); + _objectRequests.remove(ref.getIdentity()); + } + } } - + private final Ice.LocatorPrx _locator; private Ice.LocatorRegistryPrx _locatorRegistry; private final LocatorTable _table; + private final boolean _background; private java.util.Map<String, Request> _adapterRequests = new java.util.HashMap<String, Request>(); private java.util.Map<Ice.Identity, Request> _objectRequests = new java.util.HashMap<Ice.Identity, Request>(); diff --git a/java/src/IceInternal/LocatorManager.java b/java/src/IceInternal/LocatorManager.java index edf188ab173..61e3a4b9512 100644 --- a/java/src/IceInternal/LocatorManager.java +++ b/java/src/IceInternal/LocatorManager.java @@ -11,8 +11,9 @@ package IceInternal; public final class LocatorManager { - LocatorManager() + LocatorManager(Ice.Properties properties) { + _background = properties.getPropertyAsInt("Ice.BackgroundLocatorCacheUpdates") > 0; } synchronized void @@ -66,7 +67,7 @@ public final class LocatorManager _locatorTables.put(locator.ice_getIdentity(), table); } - info = new LocatorInfo(locator, table); + info = new LocatorInfo(locator, table, _background); _table.put(locator, info); } @@ -74,6 +75,8 @@ public final class LocatorManager } } + final private boolean _background; + private java.util.HashMap<Ice.LocatorPrx, LocatorInfo> _table = new java.util.HashMap<Ice.LocatorPrx, LocatorInfo>(); private java.util.HashMap<Ice.Identity, LocatorTable> _locatorTables = diff --git a/java/src/IceInternal/LocatorTable.java b/java/src/IceInternal/LocatorTable.java index db07eabf107..a2fe5a7580c 100644 --- a/java/src/IceInternal/LocatorTable.java +++ b/java/src/IceInternal/LocatorTable.java @@ -23,18 +23,21 @@ final class LocatorTable } synchronized IceInternal.EndpointI[] - getAdapterEndpoints(String adapter, int ttl) + getAdapterEndpoints(String adapter, int ttl, Ice.BooleanHolder cached) { if(ttl == 0) // Locator cache disabled. { + cached.value = false; return null; } EndpointTableEntry entry = _adapterEndpointsTable.get(adapter); - if(entry != null && checkTTL(entry.time, ttl)) + if(entry != null) { + cached.value = checkTTL(entry.time, ttl); return entry.endpoints; } + cached.value = false; return null; } @@ -52,33 +55,36 @@ final class LocatorTable return entry != null ? entry.endpoints : null; } - synchronized Ice.ObjectPrx - getProxy(Ice.Identity id, int ttl) + synchronized Reference + getObjectReference(Ice.Identity id, int ttl, Ice.BooleanHolder cached) { if(ttl == 0) // Locator cache disabled. { + cached.value = false; return null; } - ProxyTableEntry entry = _objectTable.get(id); - if(entry != null && checkTTL(entry.time, ttl)) + ReferenceTableEntry entry = _objectTable.get(id); + if(entry != null) { - return entry.proxy; + cached.value = checkTTL(entry.time, ttl); + return entry.reference; } + cached.value = false; return null; } synchronized void - addProxy(Ice.Identity id, Ice.ObjectPrx proxy) + addObjectReference(Ice.Identity id, Reference ref) { - _objectTable.put(id, new ProxyTableEntry(IceInternal.Time.currentMonotonicTimeMillis(), proxy)); + _objectTable.put(id, new ReferenceTableEntry(IceInternal.Time.currentMonotonicTimeMillis(), ref)); } - synchronized Ice.ObjectPrx - removeProxy(Ice.Identity id) + synchronized Reference + removeObjectReference(Ice.Identity id) { - ProxyTableEntry entry = _objectTable.remove(id); - return entry != null ? entry.proxy : null; + ReferenceTableEntry entry = _objectTable.remove(id); + return entry != null ? entry.reference : null; } private boolean @@ -107,20 +113,20 @@ final class LocatorTable final public IceInternal.EndpointI[] endpoints; } - private static final class ProxyTableEntry + private static final class ReferenceTableEntry { - public ProxyTableEntry(long time, Ice.ObjectPrx proxy) + public ReferenceTableEntry(long time, Reference reference) { this.time = time; - this.proxy = proxy; + this.reference = reference; } final public long time; - final public Ice.ObjectPrx proxy; + final public Reference reference; } private java.util.Map<String, EndpointTableEntry> _adapterEndpointsTable = new java.util.HashMap<String, EndpointTableEntry>(); - private java.util.Map<Ice.Identity, ProxyTableEntry> _objectTable = - new java.util.HashMap<Ice.Identity, ProxyTableEntry>(); + private java.util.Map<Ice.Identity, ReferenceTableEntry> _objectTable = + new java.util.HashMap<Ice.Identity, ReferenceTableEntry>(); } diff --git a/java/src/IceInternal/PropertyNames.java b/java/src/IceInternal/PropertyNames.java index 5c4eadf0ea8..3a7990d01cc 100644 --- a/java/src/IceInternal/PropertyNames.java +++ b/java/src/IceInternal/PropertyNames.java @@ -8,7 +8,7 @@ // ********************************************************************** // -// Generated by makeprops.py from file ./config/PropertyNames.xml, Tue Dec 23 19:01:32 2008 +// Generated by makeprops.py from file ../config/PropertyNames.xml, Tue Jan 20 15:47:00 2009 // IMPORTANT: Do not edit this file -- any edits made here will be lost! @@ -37,6 +37,7 @@ public final class PropertyNames new Property("Ice\\.Admin\\.Facets", false, null), new Property("Ice\\.Admin\\.InstanceName", false, null), new Property("Ice\\.Admin\\.ServerId", false, null), + new Property("Ice\\.BackgroundLocatorCacheUpdates", false, null), new Property("Ice\\.BatchAutoFlush", false, null), new Property("Ice\\.ChangeUser", false, null), new Property("Ice\\.Compression\\.Level", false, null), diff --git a/java/src/IceInternal/ProxyFactory.java b/java/src/IceInternal/ProxyFactory.java index eb0762ecb5a..45d3ea2c557 100644 --- a/java/src/IceInternal/ProxyFactory.java +++ b/java/src/IceInternal/ProxyFactory.java @@ -112,7 +112,11 @@ public final class ProxyFactory // We retry ObjectNotExistException if the reference is // indirect. // - li.clearObjectCache(ref); + + if(ref.isWellKnown()) + { + li.clearCache(ref); + } } else if(ref.getRouterInfo() != null && one.operation.equals("ice_add_proxy")) { |