summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/LocatorInfo.java
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2007-11-27 11:58:35 +0100
committerBenoit Foucher <benoit@zeroc.com>2007-11-27 11:58:35 +0100
commit47f800495093fd7679a315e2d730fea22f6135b7 (patch)
treea7b8d3488f3841367dd03d10cae293f36fd10481 /java/src/IceInternal/LocatorInfo.java
parentFixed SystemException to no longer derive from LocalException (diff)
downloadice-47f800495093fd7679a315e2d730fea22f6135b7.tar.bz2
ice-47f800495093fd7679a315e2d730fea22f6135b7.tar.xz
ice-47f800495093fd7679a315e2d730fea22f6135b7.zip
- Added support for non-blocking AMI/batch requests, connection
creation. - Added support for AMI oneway requests. - Changed collocation optimization to not perform any DNS lookups.
Diffstat (limited to 'java/src/IceInternal/LocatorInfo.java')
-rw-r--r--java/src/IceInternal/LocatorInfo.java373
1 files changed, 306 insertions, 67 deletions
diff --git a/java/src/IceInternal/LocatorInfo.java b/java/src/IceInternal/LocatorInfo.java
index 0d54d87555a..c5b4b1d0060 100644
--- a/java/src/IceInternal/LocatorInfo.java
+++ b/java/src/IceInternal/LocatorInfo.java
@@ -11,6 +11,12 @@ package IceInternal;
public final class LocatorInfo
{
+ interface GetEndpointsCallback
+ {
+ void setEndpoints(EndpointI[] endpoints, boolean cached);
+ void setException(Ice.LocalException ex);
+ }
+
LocatorInfo(Ice.LocatorPrx locator, LocatorTable table)
{
_locator = locator;
@@ -158,94 +164,137 @@ public final class LocatorInfo
cached.value = objectCached || endpointsCached;
}
}
- catch(Ice.AdapterNotFoundException ex)
+ catch(Exception ex)
{
- if(ref.getInstance().traceLevels().location >= 1)
- {
- StringBuffer s = new StringBuffer();
- s.append("adapter not found\n");
- s.append("adapter = " + adapterId);
- ref.getInstance().initializationData().logger.trace(
- ref.getInstance().traceLevels().locationCat, s.toString());
- }
-
- Ice.NotRegisteredException e = new Ice.NotRegisteredException();
- e.kindOfObject = "object adapter";
- e.id = adapterId;
- throw e;
+ getEndpointsException(ref, ex);
}
- catch(Ice.ObjectNotFoundException ex)
- {
- if(ref.getInstance().traceLevels().location >= 1)
- {
- StringBuffer s = new StringBuffer();
- s.append("object not found\n");
- s.append("object = " + ref.getInstance().identityToString(identity));
- ref.getInstance().initializationData().logger.trace(
- ref.getInstance().traceLevels().locationCat, s.toString());
- }
- Ice.NotRegisteredException e = new Ice.NotRegisteredException();
- e.kindOfObject = "object";
- e.id = ref.getInstance().identityToString(identity);
- throw e;
- }
- catch(Ice.NotRegisteredException ex)
+ if(ref.getInstance().traceLevels().location >= 1)
{
- throw ex;
+ getEndpointsTrace(ref, endpoints, cached.value);
}
- catch(Ice.LocalException ex)
+
+ return endpoints == null ? new EndpointI[0] : endpoints;
+ }
+
+ public void
+ getEndpoints(final IndirectReference ref, final int ttl, final GetEndpointsCallback callback)
+ {
+ final String adapterId = ref.getAdapterId();
+ final Ice.Identity identity = ref.getIdentity();
+ final Instance instance = ref.getInstance();
+ if(adapterId.length() > 0)
{
- if(ref.getInstance().traceLevels().location >= 1)
+ EndpointI[] endpoints = _table.getAdapterEndpoints(adapterId, ttl);
+ if(endpoints == null)
{
- StringBuffer s = new StringBuffer();
- s.append("couldn't contact the locator to retrieve adapter endpoints\n");
- if(adapterId.length() > 0)
+ if(instance.traceLevels().location >= 1)
{
- s.append("adapter = " + adapterId + "\n");
+ 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());
}
- else
+
+ //
+ // Search the adapter in the location service if we didn't
+ // find it in the cache.
+ //
+ _locator.findAdapterById_async(new Ice.AMI_Locator_findAdapterById()
+ {
+ public void
+ ice_response(Ice.ObjectPrx object)
+ {
+ EndpointI[] endpoints = null;
+ if(object != null)
+ {
+ endpoints = ((Ice.ObjectPrxHelperBase)object).__reference().getEndpoints();
+ if(endpoints.length > 0)
+ {
+ _table.addAdapterEndpoints(adapterId, endpoints);
+ }
+ }
+
+ if(instance.traceLevels().location >= 1)
+ {
+ getEndpointsTrace(ref, endpoints, false);
+ }
+
+ if(endpoints == null)
+ {
+ callback.setEndpoints(new EndpointI[0], false);
+ }
+ else
+ {
+ callback.setEndpoints(endpoints, false);
+ }
+ }
+
+ public void
+ ice_exception(Ice.UserException ex)
+ {
+ getEndpointsException(ref, ex, callback);
+ }
+
+ public void
+ ice_exception(Ice.LocalException ex)
+ {
+ getEndpointsException(ref, ex, callback);
+ }
+ }, adapterId);
+ return;
+ }
+ else
+ {
+ if(instance.traceLevels().location >= 1)
{
- s.append("object = " + ref.getInstance().identityToString(identity) + "\n");
+ getEndpointsTrace(ref, endpoints, true);
}
- s.append("reason = " + ex);
- ref.getInstance().initializationData().logger.trace(
- ref.getInstance().traceLevels().locationCat, s.toString());
+ callback.setEndpoints(endpoints, true);
+ return;
}
- throw ex;
}
-
- if(ref.getInstance().traceLevels().location >= 1)
+ else
{
- if(endpoints != null && endpoints.length > 0)
+ Ice.ObjectPrx object = _table.getProxy(identity, ttl);
+ if(object == null)
{
- if(cached.value)
- {
- trace("found endpoints in locator table", ref, endpoints);
- }
- else
+ if(instance.traceLevels().location >= 1)
{
- trace("retrieved endpoints from locator, adding to locator table", ref, endpoints);
+ 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());
}
+
+ _locator.findObjectById_async(new Ice.AMI_Locator_findObjectById()
+ {
+ public void
+ ice_response(Ice.ObjectPrx object)
+ {
+ getWellKnownObjectEndpoints(ref, object, ttl, false, callback);
+ }
+
+ public void
+ ice_exception(Ice.UserException ex)
+ {
+ getEndpointsException(ref, ex, callback);
+ }
+
+ public void
+ ice_exception(Ice.LocalException ex)
+ {
+ getEndpointsException(ref, ex, callback);
+ }
+ }, identity);
+ return;
}
else
{
- StringBuffer s = new StringBuffer();
- s.append("no endpoints configured for ");
- if(adapterId.length() > 0)
- {
- s.append("adapter\n");
- s.append("adapter = " + adapterId + "\n");
- }
- else
- {
- s.append("object\n");
- s.append("object = " + ref.getInstance().identityToString(identity) + "\n");
- }
+ getWellKnownObjectEndpoints(ref, object, ttl, true, callback);
+ return;
}
}
-
- return endpoints == null ? new EndpointI[0] : endpoints;
}
public void
@@ -333,14 +382,204 @@ public final class LocatorInfo
{
s.append(endpoints[i].toString());
if(i + 1 < sz)
+ {
s.append(":");
+ }
}
ref.getInstance().initializationData().logger.trace(ref.getInstance().traceLevels().locationCat, s.toString());
}
+ private void
+ getEndpointsException(IndirectReference ref, Exception exc)
+ {
+ try
+ {
+ throw exc;
+ }
+ catch(Ice.AdapterNotFoundException ex)
+ {
+ final Instance instance = ref.getInstance();
+ if(instance.traceLevels().location >= 1)
+ {
+ StringBuffer s = new StringBuffer();
+ s.append("adapter not found\n");
+ s.append("adapter = " + ref.getAdapterId());
+ instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.toString());
+ }
+
+ Ice.NotRegisteredException e = new Ice.NotRegisteredException();
+ e.kindOfObject = "object adapter";
+ e.id = ref.getAdapterId();
+ throw e;
+ }
+ catch(Ice.ObjectNotFoundException ex)
+ {
+ final Instance instance = ref.getInstance();
+ if(instance.traceLevels().location >= 1)
+ {
+ StringBuffer s = new StringBuffer();
+ s.append("object not found\n");
+ s.append("object = " + instance.identityToString(ref.getIdentity()));
+ instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.toString());
+ }
+
+ Ice.NotRegisteredException e = new Ice.NotRegisteredException();
+ e.kindOfObject = "object";
+ e.id = instance.identityToString(ref.getIdentity());
+ throw e;
+ }
+ catch(Ice.NotRegisteredException ex)
+ {
+ throw ex;
+ }
+ catch(Ice.LocalException ex)
+ {
+ final Instance instance = ref.getInstance();
+ if(instance.traceLevels().location >= 1)
+ {
+ StringBuffer s = new StringBuffer();
+ s.append("couldn't contact the locator to retrieve adapter endpoints\n");
+ if(ref.getAdapterId().length() > 0)
+ {
+ s.append("adapter = " + ref.getAdapterId() + "\n");
+ }
+ else
+ {
+ s.append("object = " + instance.identityToString(ref.getIdentity()) + "\n");
+ }
+ s.append("reason = " + ex);
+ instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.toString());
+ }
+ throw ex;
+ }
+ catch(Exception ex)
+ {
+ assert(false);
+ }
+ }
+
+ private void
+ getEndpointsException(IndirectReference 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 IndirectReference 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 instanceof DirectReference)
+ {
+ DirectReference odr = (DirectReference)r;
+ endpoints = odr.getEndpoints();
+ }
+ else
+ {
+ IndirectReference oir = (IndirectReference)r;
+ if(oir.getAdapterId().length() > 0)
+ {
+ getEndpoints(oir, 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(IndirectReference ref, EndpointI[] endpoints, boolean cached)
+ {
+ if(endpoints != null && endpoints.length > 0)
+ {
+ if(cached)
+ {
+ trace("found endpoints in locator table", ref, endpoints);
+ }
+ else
+ {
+ trace("retrieved endpoints from locator, adding to locator table", ref, endpoints);
+ }
+ }
+ else
+ {
+ final Instance instance = ref.getInstance();
+ StringBuffer s = new StringBuffer();
+ s.append("no endpoints configured for ");
+ if(ref.getAdapterId().length() > 0)
+ {
+ s.append("adapter\n");
+ s.append("adapter = " + ref.getAdapterId() + "\n");
+ }
+ else
+ {
+ s.append("object\n");
+ s.append("object = " + instance.identityToString(ref.getIdentity()) + "\n");
+ }
+ instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.toString());
+ }
+ }
+
private final Ice.LocatorPrx _locator;
private Ice.LocatorRegistryPrx _locatorRegistry;
private final LocatorTable _table;
}
-