summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2008-01-21 13:20:59 +0100
committerBenoit Foucher <benoit@zeroc.com>2008-01-21 13:20:59 +0100
commit52bd621c7d3fa7b144d8fad7941ac8d43e942be8 (patch)
treebdd7565282d503251d82205ce7fe3e57102a96d2 /java/src
parentasync I/O in C# (diff)
downloadice-52bd621c7d3fa7b144d8fad7941ac8d43e942be8.tar.bz2
ice-52bd621c7d3fa7b144d8fad7941ac8d43e942be8.tar.xz
ice-52bd621c7d3fa7b144d8fad7941ac8d43e942be8.zip
- Removed OA createReverseProxy method.
- Fixed bug 2141, 2645, 2632, 1547. - It's now possible to call ice_secure on a fixed proxy to require a secure connetion.
Diffstat (limited to 'java/src')
-rw-r--r--java/src/Ice/CommunicatorI.java4
-rw-r--r--java/src/Ice/ConnectionI.java6
-rw-r--r--java/src/Ice/ObjectAdapterI.java215
-rw-r--r--java/src/Ice/ObjectPrxHelperBase.java8
-rw-r--r--java/src/IceInternal/DirectReference.java264
-rw-r--r--java/src/IceInternal/FixedReference.java259
-rw-r--r--java/src/IceInternal/IndirectReference.java379
-rw-r--r--java/src/IceInternal/Instance.java44
-rw-r--r--java/src/IceInternal/LocatorInfo.java129
-rw-r--r--java/src/IceInternal/PropertyNames.java16
-rw-r--r--java/src/IceInternal/ProxyFactory.java9
-rw-r--r--java/src/IceInternal/Reference.java118
-rw-r--r--java/src/IceInternal/ReferenceFactory.java392
-rw-r--r--java/src/IceInternal/RoutableReference.java545
14 files changed, 1017 insertions, 1371 deletions
diff --git a/java/src/Ice/CommunicatorI.java b/java/src/Ice/CommunicatorI.java
index 1cb1bce68bd..86537b3079f 100644
--- a/java/src/Ice/CommunicatorI.java
+++ b/java/src/Ice/CommunicatorI.java
@@ -122,7 +122,7 @@ public final class CommunicatorI implements Communicator
public void
setDefaultRouter(RouterPrx router)
{
- _instance.referenceFactory().setDefaultRouter(router);
+ _instance.setDefaultRouter(router);
}
public LocatorPrx
@@ -134,7 +134,7 @@ public final class CommunicatorI implements Communicator
public void
setDefaultLocator(LocatorPrx locator)
{
- _instance.referenceFactory().setDefaultLocator(locator);
+ _instance.setDefaultLocator(locator);
}
/**
diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java
index fbacaf96d79..52a7580c46b 100644
--- a/java/src/Ice/ConnectionI.java
+++ b/java/src/Ice/ConnectionI.java
@@ -1009,11 +1009,7 @@ public final class ConnectionI extends IceInternal.EventHandler
// Create a reference and return a reverse proxy for this
// reference.
//
- ConnectionI[] connections = new ConnectionI[1];
- connections[0] = this;
- IceInternal.Reference ref = _instance.referenceFactory().create(ident, _instance.getDefaultContext(), "",
- IceInternal.Reference.ModeTwoway, connections);
- return _instance.proxyFactory().referenceToProxy(ref);
+ return _instance.proxyFactory().referenceToProxy(_instance.referenceFactory().create(ident, this));
}
//
diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java
index 7e63f990248..a334406ee35 100644
--- a/java/src/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/ObjectAdapterI.java
@@ -370,6 +370,7 @@ public final class ObjectAdapterI implements ObjectAdapter
_routerInfo = null;
_publishedEndpoints = null;
_locatorInfo = null;
+ _reference = null;
objectAdapterFactory = _objectAdapterFactory;
_objectAdapterFactory = null;
@@ -522,36 +523,6 @@ public final class ObjectAdapterI implements ObjectAdapter
return newIndirectProxy(ident, "", _id);
}
- public synchronized ObjectPrx
- createReverseProxy(Identity ident)
- {
- checkForDeactivation();
- checkIdentity(ident);
-
- //
- // Get all incoming connections for this object adapter.
- //
- java.util.LinkedList connections = new java.util.LinkedList();
- final int sz = _incomingConnectionFactories.size();
- for(int i = 0; i < sz; ++i)
- {
- IceInternal.IncomingConnectionFactory factory =
- (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i);
- connections.addAll(factory.connections());
- }
-
- //
- // Create a reference and return a reverse proxy for this
- // reference.
- //
- ConnectionI[] arr = new ConnectionI[connections.size()];
- connections.toArray(arr);
- IceInternal.Reference ref =
- _instance.referenceFactory().create(ident, _instance.getDefaultContext(), "",
- IceInternal.Reference.ModeTwoway, arr);
- return _instance.proxyFactory().referenceToProxy(ref);
- }
-
public synchronized void
setLocator(LocatorPrx locator)
{
@@ -604,96 +575,87 @@ public final class ObjectAdapterI implements ObjectAdapter
public boolean
isLocal(ObjectPrx proxy)
{
+ //
+ // NOTE: it's important that isLocal() doesn't perform any blocking operations as
+ // it can be called for AMI invocations if the proxy has no delegate set yet.
+ //
+
IceInternal.Reference ref = ((ObjectPrxHelperBase)proxy).__reference();
- IceInternal.EndpointI[] endpoints;
-
- try
+ if(ref.isWellKnown())
{
- IceInternal.IndirectReference ir = (IceInternal.IndirectReference)ref;
- if(ir.getAdapterId().length() != 0)
- {
- //
- // Proxy is local if the reference adapter id matches this
- // adapter id or replica group id.
- //
- return ir.getAdapterId().equals(_id) || ir.getAdapterId().equals(_replicaGroupId);
- }
- IceInternal.LocatorInfo info = ir.getLocatorInfo();
- if(info != null)
- {
- try
- {
- endpoints = info.getEndpoints(ir, ir.getLocatorCacheTimeout(), new Ice.BooleanHolder());
- }
- catch(Ice.LocalException ex)
- {
- return false;
- }
- }
- else
- {
- return false;
- }
+ //
+ // Check the active servant map to see if the well-known
+ // proxy is for a local object.
+ //
+ return _servantManager.hasServant(ref.getIdentity());
}
- catch(ClassCastException e)
+ else if(ref.isIndirect())
{
- endpoints = ref.getEndpoints();
+ //
+ // Proxy is local if the reference adapter id matches this
+ // adapter id or replica group id.
+ //
+ return ref.getAdapterId().equals(_id) || ref.getAdapterId().equals(_replicaGroupId);
}
-
- synchronized(this)
+ else
{
- checkForDeactivation();
+ IceInternal.EndpointI[] endpoints = ref.getEndpoints();
- //
- // Proxies which have at least one endpoint in common with the
- // endpoints used by this object adapter's incoming connection
- // factories are considered local.
- //
- for(int i = 0; i < endpoints.length; ++i)
+ synchronized(this)
{
- java.util.Iterator p;
- p = _publishedEndpoints.iterator();
- while(p.hasNext())
+ checkForDeactivation();
+
+ //
+ // Proxies which have at least one endpoint in common with the
+ // endpoints used by this object adapter's incoming connection
+ // factories are considered local.
+ //
+ for(int i = 0; i < endpoints.length; ++i)
{
- if(endpoints[i].equivalent((IceInternal.EndpointI)p.next()))
+ java.util.Iterator p;
+ p = _publishedEndpoints.iterator();
+ while(p.hasNext())
{
- return true;
+ if(endpoints[i].equivalent((IceInternal.EndpointI)p.next()))
+ {
+ return true;
+ }
}
- }
- p = _incomingConnectionFactories.iterator();
- while(p.hasNext())
- {
- if(endpoints[i].equivalent(((IceInternal.IncomingConnectionFactory)p.next()).endpoint()))
+ p = _incomingConnectionFactories.iterator();
+ while(p.hasNext())
{
- return true;
+ if(endpoints[i].equivalent(((IceInternal.IncomingConnectionFactory)p.next()).endpoint()))
+ {
+ return true;
+ }
}
+
}
-
- }
-
- //
- // Proxies which have at least one endpoint in common with the
- // router's server proxy endpoints (if any), are also considered
- // local.
- //
- if(_routerInfo != null && _routerInfo.getRouter().equals(proxy.ice_getRouter()))
- {
- for(int i = 0; i < endpoints.length; ++i)
+
+ //
+ // Proxies which have at least one endpoint in common with the
+ // router's server proxy endpoints (if any), are also considered
+ // local.
+ //
+ if(_routerInfo != null && _routerInfo.getRouter().equals(proxy.ice_getRouter()))
{
- java.util.Iterator p;
- p = _routerEndpoints.iterator();
- while(p.hasNext())
+ for(int i = 0; i < endpoints.length; ++i)
{
- if(endpoints[i].equivalent((IceInternal.EndpointI)p.next()))
+ java.util.Iterator p;
+ p = _routerEndpoints.iterator();
+ while(p.hasNext())
{
- return true;
+ if(endpoints[i].equivalent((IceInternal.EndpointI)p.next()))
+ {
+ return true;
+ }
}
}
}
}
-
- return false;
}
+
+ return false;
}
public void
@@ -798,6 +760,7 @@ public final class ObjectAdapterI implements ObjectAdapter
{
_id = "";
_replicaGroupId = "";
+ _reference = _instance.referenceFactory().create("dummy -t", "");
return;
}
@@ -810,7 +773,7 @@ public final class ObjectAdapterI implements ObjectAdapter
//
if(unknownProps.size() != 0 && properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0)
{
- String message = "found unknown properties for object adapter '" + _name + "':";
+ String message = "found unknown properties for object adapter `" + _name + "':";
java.util.Iterator p = unknownProps.iterator();
while(p.hasNext())
{
@@ -834,13 +797,29 @@ public final class ObjectAdapterI implements ObjectAdapter
_incomingConnectionFactories = null;
InitializationException ex = new InitializationException();
- ex.reason = "object adapter \"" + _name + "\" requires configuration.";
+ ex.reason = "object adapter `" + _name + "' requires configuration";
throw ex;
}
_id = properties.getProperty(_name + ".AdapterId");
_replicaGroupId = properties.getProperty(_name + ".ReplicaGroupId");
+ //
+ // Setup a reference to be used to get the default proxy options
+ // when creating new proxies. By default, create twoway proxies.
+ //
+ String proxyOptions = properties.getPropertyWithDefault(_name + ".ProxyOptions", "-t");
+ try
+ {
+ _reference = _instance.referenceFactory().create("dummy " + proxyOptions, "");
+ }
+ catch(ProxyParseException e)
+ {
+ InitializationException ex = new InitializationException();
+ ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'";
+ throw ex;
+ }
+
try
{
_threadPerConnection = properties.getPropertyAsInt(_name + ".ThreadPerConnection") > 0;
@@ -850,7 +829,7 @@ public final class ObjectAdapterI implements ObjectAdapter
if(_threadPerConnection && (threadPoolSize > 0 || threadPoolSizeMax > 0))
{
InitializationException ex = new InitializationException();
- ex.reason = "object adapter \"" + _name + "\" cannot be configured for both\n" +
+ ex.reason = "object adapter `" + _name + "' cannot be configured for both\n" +
"thread pool and thread per connection";
throw ex;
}
@@ -1047,15 +1026,8 @@ public final class ObjectAdapterI implements ObjectAdapter
//
// Create a reference and return a proxy for this reference.
//
- ConnectionI[] connections = new ConnectionI[0];
- IceInternal.Reference reference =
- _instance.referenceFactory().create(ident, new java.util.HashMap(), facet,
- IceInternal.Reference.ModeTwoway, false,
- _instance.defaultsAndOverrides().defaultPreferSecure, endpoints, null,
- _instance.defaultsAndOverrides().defaultCollocationOptimization, true,
- _instance.defaultsAndOverrides().defaultEndpointSelection,
- _instance.threadPerConnection());
- return _instance.proxyFactory().referenceToProxy(reference);
+ IceInternal.Reference ref = _instance.referenceFactory().create(ident, facet, _reference, endpoints);
+ return _instance.proxyFactory().referenceToProxy(ref);
}
private ObjectPrx
@@ -1065,18 +1037,8 @@ public final class ObjectAdapterI implements ObjectAdapter
// Create a reference with the adapter id and return a proxy
// for the reference.
//
- IceInternal.EndpointI[] endpoints = new IceInternal.EndpointI[0];
- ConnectionI[] connections = new ConnectionI[0];
- IceInternal.Reference reference =
- _instance.referenceFactory().create(ident, new java.util.HashMap(), facet,
- IceInternal.Reference.ModeTwoway, false,
- _instance.defaultsAndOverrides().defaultPreferSecure, id, null,
- _locatorInfo,
- _instance.defaultsAndOverrides().defaultCollocationOptimization, true,
- _instance.defaultsAndOverrides().defaultEndpointSelection,
- _instance.threadPerConnection(),
- _instance.defaultsAndOverrides().defaultLocatorCacheTimeout);
- return _instance.proxyFactory().referenceToProxy(reference);
+ IceInternal.Reference ref = _instance.referenceFactory().create(ident, facet, _reference, id);
+ return _instance.proxyFactory().referenceToProxy(ref);
}
private void
@@ -1235,11 +1197,8 @@ public final class ObjectAdapterI implements ObjectAdapter
}
//
- // We must get and call on the locator registry outside the
- // thread synchronization to avoid deadlocks. (we can't make
- // remote calls within the OA synchronization because the
- // remote call will indirectly call isLocal() on this OA with
- // the OA factory locked).
+ // Call on the locator registry outside the synchronization to
+ // blocking other threads that need to lock this OA.
//
LocatorRegistryPrx locatorRegistry = locatorInfo != null ? locatorInfo.getLocatorRegistry() : null;
String serverId = "";
@@ -1414,6 +1373,7 @@ public final class ObjectAdapterI implements ObjectAdapter
"RegisterProcess",
"ReplicaGroupId",
"Router",
+ "ProxyOptions",
"ThreadPerConnection",
"ThreadPerConnection.StackSize",
"ThreadPool.Size",
@@ -1477,6 +1437,7 @@ public final class ObjectAdapterI implements ObjectAdapter
final private String _name;
final private String _id;
final private String _replicaGroupId;
+ private IceInternal.Reference _reference;
private java.util.ArrayList _incomingConnectionFactories = new java.util.ArrayList();
private java.util.ArrayList _routerEndpoints = new java.util.ArrayList();
private IceInternal.RouterInfo _routerInfo = null;
diff --git a/java/src/Ice/ObjectPrxHelperBase.java b/java/src/Ice/ObjectPrxHelperBase.java
index 4269def1407..0c51ec2db84 100644
--- a/java/src/Ice/ObjectPrxHelperBase.java
+++ b/java/src/Ice/ObjectPrxHelperBase.java
@@ -589,7 +589,7 @@ public class ObjectPrxHelperBase implements ObjectPrx
public final boolean
ice_isCollocationOptimized()
{
- return _reference.getCollocationOptimization();
+ return _reference.getCollocationOptimized();
}
/**
@@ -604,13 +604,13 @@ public class ObjectPrxHelperBase implements ObjectPrx
public final ObjectPrx
ice_collocationOptimized(boolean b)
{
- if(b == _reference.getCollocationOptimization())
+ if(b == _reference.getCollocationOptimized())
{
return this;
}
else
{
- return newInstance(_reference.changeCollocationOptimization(b));
+ return newInstance(_reference.changeCollocationOptimized(b));
}
}
@@ -1030,7 +1030,7 @@ public class ObjectPrxHelperBase implements ObjectPrx
}
_ObjectDel delegate = null;
- if(_reference.getCollocationOptimization())
+ if(_reference.getCollocationOptimized())
{
ObjectAdapter adapter = _reference.getInstance().objectAdapterFactory().findObjectAdapter(this);
if(adapter != null)
diff --git a/java/src/IceInternal/DirectReference.java b/java/src/IceInternal/DirectReference.java
deleted file mode 100644
index 2a60fda7e7a..00000000000
--- a/java/src/IceInternal/DirectReference.java
+++ /dev/null
@@ -1,264 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-package IceInternal;
-
-public class DirectReference extends RoutableReference
-{
- public
- DirectReference(Instance inst,
- Ice.Communicator com,
- Ice.Identity ident,
- java.util.Map ctx,
- String fs,
- int md,
- boolean sec,
- boolean prefSec,
- EndpointI[] endpts,
- RouterInfo rtrInfo,
- boolean collocationOpt,
- boolean cacheConnection,
- Ice.EndpointSelectionType endpointSelection,
- boolean threadPerConnection)
- {
- super(inst, com, ident, ctx, fs, md, sec, prefSec, rtrInfo, collocationOpt, cacheConnection, endpointSelection,
- threadPerConnection);
- _endpoints = endpts;
- }
-
- public String
- getAdapterId()
- {
- return "";
- }
-
- public EndpointI[]
- getEndpoints()
- {
- return _endpoints;
- }
-
- public int
- getLocatorCacheTimeout()
- {
- return 0;
- }
-
- public Reference
- changeLocator(Ice.LocatorPrx newLocator)
- {
- return this;
- }
-
- public Reference
- changeCompress(boolean newCompress)
- {
- DirectReference r = (DirectReference)super.changeCompress(newCompress);
- if(r != this) // Also override the compress flag on the endpoints if it was updated.
- {
- EndpointI[] newEndpoints = new EndpointI[_endpoints.length];
- for(int i = 0; i < _endpoints.length; i++)
- {
- newEndpoints[i] = _endpoints[i].compress(newCompress);
- }
- r._endpoints = newEndpoints;
- }
- return r;
- }
-
- public Reference
- changeTimeout(int newTimeout)
- {
- DirectReference r = (DirectReference)super.changeTimeout(newTimeout);
- if(r != this) // Also override the timeout on the endpoints if it was updated.
- {
- EndpointI[] newEndpoints = new EndpointI[_endpoints.length];
- for(int i = 0; i < _endpoints.length; i++)
- {
- newEndpoints[i] = _endpoints[i].timeout(newTimeout);
- }
- r._endpoints = newEndpoints;
- }
- return r;
- }
-
- public Reference
- changeConnectionId(String connectionId)
- {
- DirectReference r = (DirectReference)super.changeConnectionId(connectionId);
- if(r != this) // Also override the connection id on the endpoints if it was updated.
- {
- EndpointI[] newEndpoints = new EndpointI[_endpoints.length];
- for(int i = 0; i < _endpoints.length; i++)
- {
- newEndpoints[i] = _endpoints[i].connectionId(connectionId);
- }
- r._endpoints = newEndpoints;
- }
- return r;
- }
-
- public Reference
- changeAdapterId(String newAdapterId)
- {
- if(newAdapterId == null || newAdapterId.length() == 0)
- {
- return this;
- }
- LocatorInfo locatorInfo =
- getInstance().locatorManager().get(getInstance().referenceFactory().getDefaultLocator());
- return getInstance().referenceFactory().create(getIdentity(), getContext(), getFacet(), getMode(),
- getSecure(), getPreferSecure(), newAdapterId, getRouterInfo(),
- locatorInfo, getCollocationOptimization(), getCacheConnection(),
- getEndpointSelection(), getThreadPerConnection(),
- getLocatorCacheTimeout());
- }
-
- public Reference
- changeEndpoints(EndpointI[] newEndpoints)
- {
- if(java.util.Arrays.equals(newEndpoints, _endpoints))
- {
- return this;
- }
-
- DirectReference r = (DirectReference)getInstance().referenceFactory().copy(this);
- r._endpoints = newEndpoints;
- r.applyOverrides(r._endpoints);
- return r;
- }
-
- public Reference
- changeLocatorCacheTimeout(int newTimeout)
- {
- return this;
- }
-
- public void
- streamWrite(BasicStream s)
- throws Ice.MarshalException
- {
- super.streamWrite(s);
-
- s.writeSize(_endpoints.length);
- if(_endpoints.length > 0)
- {
- for(int i = 0; i < _endpoints.length; i++)
- {
- _endpoints[i].streamWrite(s);
- }
- }
- else
- {
- s.writeString(""); // Adapter id.
- }
- }
-
- public String
- toString()
- {
- //
- // WARNING: Certain features, such as proxy validation in Glacier2,
- // depend on the format of proxy strings. Changes to toString() and
- // methods called to generate parts of the reference string could break
- // these features. Please review for all features that depend on the
- // format of proxyToString() before changing this and related code.
- //
- StringBuffer s = new StringBuffer();
- s.append(super.toString());
-
- for(int i = 0; i < _endpoints.length; i++)
- {
- String endp = _endpoints[i].toString();
- if(endp != null && endp.length() > 0)
- {
- s.append(':');
- s.append(endp);
- }
- }
- return s.toString();
- }
-
- public Ice.ConnectionI
- getConnection(Ice.BooleanHolder comp)
- {
- if(getRouterInfo() != null)
- {
- //
- // If we route, we send everything to the router's client
- // proxy endpoints.
- //
- EndpointI[] endpts = getRouterInfo().getClientEndpoints();
- if(endpts.length > 0)
- {
- applyOverrides(endpts);
- return createConnection(endpts, comp);
- }
- }
-
- return createConnection(_endpoints, comp);
- }
-
- public void
- getConnection(final GetConnectionCallback callback)
- {
- if(getRouterInfo() != null)
- {
- //
- // If we route, we send everything to the router's client
- // proxy endpoints.
- //
- getRouterInfo().getClientEndpoints(new RouterInfo.GetClientEndpointsCallback()
- {
- public void
- setEndpoints(EndpointI[] endpts)
- {
- if(endpts.length > 0)
- {
- applyOverrides(endpts);
- createConnection(endpts, callback);
- return;
- }
-
- createConnection(_endpoints, callback);
- }
-
- public void
- setException(Ice.LocalException ex)
- {
- callback.setException(ex);
- }
- });
- return;
- }
-
- createConnection(_endpoints, callback);
- }
-
- public boolean
- equals(java.lang.Object obj)
- {
- if(this == obj)
- {
- return true;
- }
- if(!(obj instanceof DirectReference))
- {
- return false;
- }
- DirectReference rhs = (DirectReference)obj;
- if(!super.equals(rhs))
- {
- return false;
- }
- return java.util.Arrays.equals(_endpoints, rhs._endpoints);
- }
-
- private EndpointI[] _endpoints;
-}
diff --git a/java/src/IceInternal/FixedReference.java b/java/src/IceInternal/FixedReference.java
index bc43460b555..835cb3f3f97 100644
--- a/java/src/IceInternal/FixedReference.java
+++ b/java/src/IceInternal/FixedReference.java
@@ -12,28 +12,23 @@ package IceInternal;
public class FixedReference extends Reference
{
public
- FixedReference(Instance inst,
- Ice.Communicator com,
- Ice.Identity ident,
- java.util.Map ctx,
- String fs,
- int md,
- Ice.ConnectionI[] fixedConns)
+ FixedReference(Instance instance,
+ Ice.Communicator communicator,
+ Ice.Identity identity,
+ java.util.Map context,
+ String facet,
+ int mode,
+ boolean secure,
+ Ice.ConnectionI connection)
{
- super(inst, com, ident, ctx, fs, md);
- _fixedConnections = fixedConns;
+ super(instance, communicator, identity, context, facet, mode, secure);
+ _fixedConnection = connection;
}
- public boolean
- getSecure()
- {
- return false;
- }
-
- public boolean
- getPreferSecure()
+ public EndpointI[]
+ getEndpoints()
{
- return false;
+ return new EndpointI[0];
}
public String
@@ -42,26 +37,32 @@ public class FixedReference extends Reference
return "";
}
- public EndpointI[]
- getEndpoints()
+ public LocatorInfo
+ getLocatorInfo()
{
- return new EndpointI[0];
+ return null;
+ }
+
+ public RouterInfo
+ getRouterInfo()
+ {
+ return null;
}
public boolean
- getCollocationOptimization()
+ getCollocationOptimized()
{
return false;
}
- public int
- getLocatorCacheTimeout()
+ public final boolean
+ getCacheConnection()
{
- return 0;
+ return false;
}
- public final boolean
- getCacheConnection()
+ public boolean
+ getPreferSecure()
{
return false;
}
@@ -78,20 +79,20 @@ public class FixedReference extends Reference
return false;
}
- public Reference
- changeSecure(boolean sec)
+ public int
+ getLocatorCacheTimeout()
{
- throw new Ice.FixedProxyException();
+ return 0;
}
public Reference
- changePreferSecure(boolean prefSec)
+ changeEndpoints(EndpointI[] newEndpoints)
{
throw new Ice.FixedProxyException();
}
public Reference
- changeRouter(Ice.RouterPrx newRouter)
+ changeAdapterId(String newAdapterId)
{
throw new Ice.FixedProxyException();
}
@@ -103,43 +104,43 @@ public class FixedReference extends Reference
}
public Reference
- changeCollocationOptimization(boolean newCollocationOptimization)
+ changeRouter(Ice.RouterPrx newRouter)
{
throw new Ice.FixedProxyException();
}
public Reference
- changeAdapterId(String newAdapterId)
+ changeCollocationOptimized(boolean newCollocationOptimized)
{
throw new Ice.FixedProxyException();
}
- public Reference
- changeEndpoints(EndpointI[] newEndpoints)
+ public final Reference
+ changeCacheConnection(boolean newCache)
{
throw new Ice.FixedProxyException();
}
public Reference
- changeLocatorCacheTimeout(int newTimeout)
+ changePreferSecure(boolean prefSec)
{
throw new Ice.FixedProxyException();
}
public final Reference
- changeCacheConnection(boolean newCache)
+ changeEndpointSelection(Ice.EndpointSelectionType newType)
{
throw new Ice.FixedProxyException();
}
public final Reference
- changeEndpointSelection(Ice.EndpointSelectionType newType)
+ changeThreadPerConnection(boolean newTpc)
{
throw new Ice.FixedProxyException();
}
- public final Reference
- changeThreadPerConnection(boolean newTpc)
+ public Reference
+ changeLocatorCacheTimeout(int newTimeout)
{
throw new Ice.FixedProxyException();
}
@@ -156,6 +157,18 @@ public class FixedReference extends Reference
throw new Ice.FixedProxyException();
}
+ public boolean
+ isIndirect()
+ {
+ return false;
+ }
+
+ public boolean
+ isWellKnown()
+ {
+ return false;
+ }
+
public void
streamWrite(BasicStream s)
throws Ice.MarshalException
@@ -173,19 +186,51 @@ public class FixedReference extends Reference
public Ice.ConnectionI
getConnection(Ice.BooleanHolder compress)
{
- Ice.ConnectionI[] filteredConns = filterConnections(_fixedConnections);
- if(filteredConns.length == 0)
+ switch(getMode())
{
- Ice.NoEndpointException ex = new Ice.NoEndpointException();
- ex.proxy = ""; // No stringified representation for fixed proxies.
- throw ex;
- }
+ case Reference.ModeTwoway:
+ case Reference.ModeOneway:
+ case Reference.ModeBatchOneway:
+ {
+ if(_fixedConnection.endpoint().datagram())
+ {
+ throw new Ice.NoEndpointException("");
+ }
+ break;
+ }
- Ice.ConnectionI connection = filteredConns[0];
- assert(connection != null);
- connection.throwException(); // Throw in case our connection is already destroyed.
+ case Reference.ModeDatagram:
+ case Reference.ModeBatchDatagram:
+ {
+ if(!_fixedConnection.endpoint().datagram())
+ {
+ throw new Ice.NoEndpointException("");
+ }
+ break;
+ }
+ }
+ //
+ // If a secure connection is requested or secure overrides is set,
+ // check if the connection is secure.
+ //
+ boolean secure;
DefaultsAndOverrides defaultsAndOverrides = getInstance().defaultsAndOverrides();
+ if(defaultsAndOverrides.overrideSecure)
+ {
+ secure = defaultsAndOverrides.overrideSecureValue;
+ }
+ else
+ {
+ secure = getSecure();
+ }
+ if(secure && !_fixedConnection.endpoint().secure())
+ {
+ throw new Ice.NoEndpointException("");
+ }
+
+ _fixedConnection.throwException(); // Throw in case our connection is already destroyed.
+
if(defaultsAndOverrides.overrideCompress)
{
compress.value = defaultsAndOverrides.overrideCompressValue;
@@ -196,9 +241,9 @@ public class FixedReference extends Reference
}
else
{
- compress.value = connection.endpoint().compress();
+ compress.value = _fixedConnection.endpoint().compress();
}
- return connection;
+ return _fixedConnection;
}
public void
@@ -232,114 +277,8 @@ public class FixedReference extends Reference
{
return false;
}
- return java.util.Arrays.equals(_fixedConnections, rhs._fixedConnections);
+ return _fixedConnection.equals(rhs._fixedConnection);
}
- //
- // Filter connections based on criteria from this reference.
- //
- private Ice.ConnectionI[]
- filterConnections(Ice.ConnectionI[] allConnections)
- {
- java.util.ArrayList connections = new java.util.ArrayList(allConnections.length);
-
- switch(getMode())
- {
- case Reference.ModeTwoway:
- case Reference.ModeOneway:
- case Reference.ModeBatchOneway:
- {
- //
- // Filter out datagram connections.
- //
- for(int i = 0; i < allConnections.length; ++i)
- {
- if(!allConnections[i].endpoint().datagram())
- {
- connections.add(allConnections[i]);
- }
- }
-
- break;
- }
-
- case Reference.ModeDatagram:
- case Reference.ModeBatchDatagram:
- {
- //
- // Filter out non-datagram connections.
- //
- for(int i = 0; i < allConnections.length; i++)
- {
- if(allConnections[i].endpoint().datagram())
- {
- connections.add(allConnections[i]);
- }
- }
-
- break;
- }
- }
-
- //
- // Randomize the order of connections.
- //
- java.util.Collections.shuffle(connections);
-
- //
- // If a secure connection is requested or secure overrides is
- // set, remove all non-secure endpoints. Otherwise make
- // non-secure endpoints preferred over secure endpoints by
- // partitioning the endpoint vector, so that non-secure
- // endpoints come first.
- //
- DefaultsAndOverrides overrides = getInstance().defaultsAndOverrides();
- if(overrides.overrideSecure ? overrides.overrideSecureValue : getSecure())
- {
- java.util.Iterator i = connections.iterator();
- while(i.hasNext())
- {
- Ice.ConnectionI connection = (Ice.ConnectionI)i.next();
- if(!connection.endpoint().secure())
- {
- i.remove();
- }
- }
- }
- else
- {
- java.util.Collections.sort(connections, _connectionComparator);
- }
-
- Ice.ConnectionI[] arr = new Ice.ConnectionI[connections.size()];
- connections.toArray(arr);
- return arr;
- }
-
- static class ConnectionComparator implements java.util.Comparator
- {
- public int
- compare(java.lang.Object l, java.lang.Object r)
- {
- Ice.ConnectionI lc = (Ice.ConnectionI)l;
- Ice.ConnectionI rc = (Ice.ConnectionI)r;
- boolean ls = lc.endpoint().secure();
- boolean rs = rc.endpoint().secure();
- if((ls && rs) || (!ls && !rs))
- {
- return 0;
- }
- else if(!ls && rs)
- {
- return -1;
- }
- else
- {
- return 1;
- }
- }
- }
-
- private static ConnectionComparator _connectionComparator = new ConnectionComparator();
- private Ice.ConnectionI _fixedConnections[];
+ private Ice.ConnectionI _fixedConnection;
}
diff --git a/java/src/IceInternal/IndirectReference.java b/java/src/IceInternal/IndirectReference.java
deleted file mode 100644
index 2879e4325bf..00000000000
--- a/java/src/IceInternal/IndirectReference.java
+++ /dev/null
@@ -1,379 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-package IceInternal;
-
-public class IndirectReference extends RoutableReference
-{
- public
- IndirectReference(Instance inst,
- Ice.Communicator com,
- Ice.Identity ident,
- java.util.Map ctx,
- String fs,
- int md,
- boolean sec,
- boolean prefSec,
- String adptid,
- RouterInfo rtrInfo,
- LocatorInfo locInfo,
- boolean collocationOpt,
- boolean cacheConnection,
- Ice.EndpointSelectionType endpointSelection,
- boolean threadPerConnection,
- int locatorCacheTimeout)
- {
- super(inst, com, ident, ctx, fs, md, sec, prefSec, rtrInfo, collocationOpt, cacheConnection, endpointSelection,
- threadPerConnection);
- _adapterId = adptid;
- _locatorInfo = locInfo;
- _locatorCacheTimeout = locatorCacheTimeout;
- }
-
- public final LocatorInfo
- getLocatorInfo()
- {
- return _locatorInfo;
- }
-
- public final String
- getAdapterId()
- {
- return _adapterId;
- }
-
- public EndpointI[]
- getEndpoints()
- {
- return new EndpointI[0];
- }
-
- public int
- getLocatorCacheTimeout()
- {
- return _locatorCacheTimeout;
- }
-
- public Reference
- changeLocator(Ice.LocatorPrx newLocator)
- {
- LocatorInfo newLocatorInfo = getInstance().locatorManager().get(newLocator);
- if(_locatorInfo != null && newLocatorInfo != null && newLocatorInfo.equals(_locatorInfo))
- {
- return this;
- }
- IndirectReference r = (IndirectReference)getInstance().referenceFactory().copy(this);
- r._locatorInfo = newLocatorInfo;
- return r;
- }
-
- public Reference
- changeAdapterId(String newAdapterId)
- {
- if(_adapterId.equals(newAdapterId))
- {
- return this;
- }
- IndirectReference r = (IndirectReference)getInstance().referenceFactory().copy(this);
- r._adapterId = newAdapterId;
- return r;
- }
-
- public Reference
- changeEndpoints(EndpointI[] newEndpoints)
- {
- if(newEndpoints == null || newEndpoints.length == 0)
- {
- return this;
- }
- return getInstance().referenceFactory().create(getIdentity(), getContext(), getFacet(), getMode(),
- getSecure(), getPreferSecure(), newEndpoints, getRouterInfo(),
- getCollocationOptimization(), getCacheConnection(),
- getEndpointSelection(), getThreadPerConnection());
- }
-
- public Reference
- changeLocatorCacheTimeout(int newTimeout)
- {
- if(_locatorCacheTimeout == newTimeout)
- {
- return this;
- }
- IndirectReference r = (IndirectReference)getInstance().referenceFactory().copy(this);
- r._locatorCacheTimeout = newTimeout;
- return r;
- }
-
- public void
- streamWrite(BasicStream s)
- throws Ice.MarshalException
- {
- super.streamWrite(s);
-
- s.writeSize(0);
- s.writeString(_adapterId);
- }
-
- public String
- toString()
- {
- //
- // WARNING: Certain features, such as proxy validation in Glacier2,
- // depend on the format of proxy strings. Changes to toString() and
- // methods called to generate parts of the reference string could break
- // these features. Please review for all features that depend on the
- // format of proxyToString() before changing this and related code.
- //
- String result = super.toString();
-
- if(_adapterId.length() == 0)
- {
- return result;
- }
-
- StringBuffer s = new StringBuffer();
- s.append(result);
- s.append(" @ ");
-
- //
- // If the encoded adapter id string contains characters which
- // the reference parser uses as separators, then we enclose
- // the adapter id string in quotes.
- //
- String a = IceUtilInternal.StringUtil.escapeString(_adapterId, null);
- if(IceUtilInternal.StringUtil.findFirstOf(a, " \t\n\r") != -1)
- {
- s.append('"');
- s.append(a);
- s.append('"');
- }
- else
- {
- s.append(a);
- }
- return s.toString();
- }
-
- public Ice.ConnectionI
- getConnection(Ice.BooleanHolder comp)
- {
- if(getRouterInfo() != null)
- {
- //
- // If we route, we send everything to the router's client
- // proxy endpoints.
- //
- EndpointI[] endpts = getRouterInfo().getClientEndpoints();
- if(endpts.length > 0)
- {
- applyOverrides(endpts);
- return createConnection(endpts, comp);
- }
- }
-
- while(true)
- {
- Ice.BooleanHolder cached = new Ice.BooleanHolder(false);
- EndpointI[] endpts = null;
- if(_locatorInfo != null)
- {
- endpts = _locatorInfo.getEndpoints(this, _locatorCacheTimeout, cached);
- applyOverrides(endpts);
- }
-
- if(endpts == null || endpts.length == 0)
- {
- throw new Ice.NoEndpointException(toString());
- }
-
- try
- {
- return createConnection(endpts, comp);
- }
- catch(Ice.NoEndpointException ex)
- {
- throw ex; // No need to retry if there's no endpoints.
- }
- catch(Ice.LocalException ex)
- {
- assert(_locatorInfo != null);
- _locatorInfo.clearCache(this);
- if(cached.value)
- {
- TraceLevels traceLevels = getInstance().traceLevels();
- if(traceLevels.retry >= 2)
- {
- String s = "connection to cached endpoints failed\n" +
- "removing endpoints from cache and trying one more time\n" + ex;
- getInstance().initializationData().logger.trace(traceLevels.retryCat, s);
- }
- continue; // Try again if the endpoints were cached.
- }
- throw ex;
- }
- }
- }
-
- public void
- getConnection(final GetConnectionCallback callback)
- {
- if(getRouterInfo() != null)
- {
- //
- // If we route, we send everything to the router's client
- // proxy endpoints.
- //
- getRouterInfo().getClientEndpoints(new RouterInfo.GetClientEndpointsCallback()
- {
- public void
- setEndpoints(EndpointI[] endpts)
- {
- if(endpts.length > 0)
- {
- applyOverrides(endpts);
- createConnection(endpts, callback);
- }
- else
- {
- getConnectionNoRouterInfo(callback);
- }
- }
-
- public void
- setException(Ice.LocalException ex)
- {
- callback.setException(ex);
- }
- });
- }
- else
- {
- getConnectionNoRouterInfo(callback);
- }
- }
-
- private void
- getConnectionNoRouterInfo(final GetConnectionCallback callback)
- {
- final IndirectReference self = this;
- if(_locatorInfo != null)
- {
- _locatorInfo.getEndpoints(this, _locatorCacheTimeout, new LocatorInfo.GetEndpointsCallback()
- {
- public void
- setEndpoints(EndpointI[] endpoints, final boolean cached)
- {
- if(endpoints.length == 0)
- {
- callback.setException(new Ice.NoEndpointException(self.toString()));
- return;
- }
-
- applyOverrides(endpoints);
- createConnection(endpoints, new GetConnectionCallback()
- {
- public void
- setConnection(Ice.ConnectionI connection, boolean compress)
- {
- callback.setConnection(connection, compress);
- }
-
- public void
- setException(Ice.LocalException exc)
- {
- try
- {
- throw exc;
- }
- catch(Ice.NoEndpointException ex)
- {
- callback.setException(ex); // No need to retry if there's no endpoints.
- }
- catch(Ice.LocalException ex)
- {
- assert(_locatorInfo != null);
- _locatorInfo.clearCache(self);
- if(cached)
- {
- TraceLevels traceLvls = getInstance().traceLevels();
- if(traceLvls.retry >= 2)
- {
- String s = "connection to cached endpoints failed\n" +
- "removing endpoints from cache and trying one more time\n" + ex;
- getInstance().initializationData().logger.trace(traceLvls.retryCat, s);
- }
- getConnectionNoRouterInfo(callback); // Retry.
- return;
- }
- callback.setException(ex);
- }
- }
- });
- }
-
- public void
- setException(Ice.LocalException ex)
- {
- callback.setException(ex);
- }
- });
- }
- else
- {
- callback.setException(new Ice.NoEndpointException(toString()));
- }
- }
-
- public synchronized int
- hashCode()
- {
- if(_hashInitialized)
- {
- return _hashValue;
- }
- super.hashCode(); // Initializes _hashValue.
- int sz = _adapterId.length(); // Add hash of adapter ID to base hash.
- for(int i = 0; i < sz; i++)
- {
- _hashValue = 5 * _hashValue + (int)_adapterId.charAt(i);
- }
- return _hashValue;
- }
-
- public boolean
- equals(java.lang.Object obj)
- {
- if(this == obj)
- {
- return true;
- }
- if(!(obj instanceof IndirectReference))
- {
- return false;
- }
- IndirectReference rhs = (IndirectReference)obj;
- if(!super.equals(rhs))
- {
- return false;
- }
- if(!_adapterId.equals(rhs._adapterId))
- {
- return false;
- }
- if(_locatorInfo == null ? rhs._locatorInfo != null : !_locatorInfo.equals(rhs._locatorInfo))
- {
- return false;
- }
- return _locatorCacheTimeout == rhs._locatorCacheTimeout;
- }
-
- private String _adapterId;
- private LocatorInfo _locatorInfo;
- private int _locatorCacheTimeout;
-}
diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java
index 44b7d93bceb..5f33798ab75 100644
--- a/java/src/IceInternal/Instance.java
+++ b/java/src/IceInternal/Instance.java
@@ -313,7 +313,6 @@ public final class Instance
return _implicitContext;
}
-
public void
flushBatchRequests()
{
@@ -538,6 +537,28 @@ public final class Instance
return result;
}
+ public void
+ setDefaultLocator(Ice.LocatorPrx locator)
+ {
+ if(_state == StateDestroyed)
+ {
+ throw new Ice.CommunicatorDestroyedException();
+ }
+
+ _referenceFactory = _referenceFactory.setDefaultLocator(locator);
+ }
+
+ public void
+ setDefaultRouter(Ice.RouterPrx router)
+ {
+ if(_state == StateDestroyed)
+ {
+ throw new Ice.CommunicatorDestroyedException();
+ }
+
+ _referenceFactory = _referenceFactory.setDefaultRouter(router);
+ }
+
//
// Only for use by Ice.CommunicatorI
//
@@ -657,9 +678,7 @@ public final class Instance
_clientACM = _initData.properties.getPropertyAsIntWithDefault("Ice.ACM.Client", 60);
_serverACM = _initData.properties.getPropertyAsInt("Ice.ACM.Server");
- _implicitContext = Ice.ImplicitContextI.create(
- _initData.properties.getProperty("Ice.ImplicitContext"));
-
+ _implicitContext = Ice.ImplicitContextI.create(_initData.properties.getProperty("Ice.ImplicitContext"));
_threadPerConnection = _initData.properties.getPropertyAsInt("Ice.ThreadPerConnection") > 0;
@@ -779,11 +798,17 @@ public final class Instance
// initialization before the plug-in initialization!!! The proxies
// might depend on endpoint factories to be installed by plug-ins.
//
- _referenceFactory.setDefaultRouter(Ice.RouterPrxHelper.uncheckedCast(
- _proxyFactory.propertyToProxy("Ice.Default.Router")));
+ Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(_proxyFactory.propertyToProxy("Ice.Default.Router"));
+ if(router != null)
+ {
+ _referenceFactory = _referenceFactory.setDefaultRouter(router);
+ }
- _referenceFactory.setDefaultLocator(Ice.LocatorPrxHelper.uncheckedCast(
- _proxyFactory.propertyToProxy("Ice.Default.Locator")));
+ Ice.LocatorPrx loc = Ice.LocatorPrxHelper.uncheckedCast(_proxyFactory.propertyToProxy("Ice.Default.Locator"));
+ if(loc != null)
+ {
+ _referenceFactory = _referenceFactory.setDefaultLocator(loc);
+ }
if(_initData.properties.getPropertyAsIntWithDefault("Ice.Admin.DelayCreation", 0) <= 0)
{
@@ -934,8 +959,7 @@ public final class Instance
_referenceFactory = null;
}
- // No destroy function defined.
- // _proxyFactory.destroy();
+ // _proxyFactory.destroy(); // No destroy function defined.
_proxyFactory = null;
if(_routerManager != null)
diff --git a/java/src/IceInternal/LocatorInfo.java b/java/src/IceInternal/LocatorInfo.java
index c5b4b1d0060..d559c4ddee3 100644
--- a/java/src/IceInternal/LocatorInfo.java
+++ b/java/src/IceInternal/LocatorInfo.java
@@ -72,8 +72,10 @@ public final class LocatorInfo
}
public EndpointI[]
- getEndpoints(IndirectReference ref, int ttl, Ice.BooleanHolder cached)
+ getEndpoints(Reference ref, int ttl, Ice.BooleanHolder cached)
{
+ assert(ref.isIndirect());
+
EndpointI[] endpoints = null;
Ice.ObjectPrx object = null;
cached.value = true;
@@ -138,21 +140,16 @@ public final class LocatorInfo
if(object != null)
{
Reference r = ((Ice.ObjectPrxHelperBase)object).__reference();
- if(r instanceof DirectReference)
+ if(!r.isIndirect())
{
endpointsCached = false;
- DirectReference odr = (DirectReference)r;
- endpoints = odr.getEndpoints();
+ endpoints = r.getEndpoints();
}
- else
+ else if(!r.isWellKnown())
{
- IndirectReference oir = (IndirectReference)r;
- if(oir.getAdapterId().length() > 0)
- {
- Ice.BooleanHolder c = new Ice.BooleanHolder();
- endpoints = getEndpoints(oir, ttl, c);
- endpointsCached = c.value;
- }
+ Ice.BooleanHolder c = new Ice.BooleanHolder();
+ endpoints = getEndpoints(r, ttl, c);
+ endpointsCached = c.value;
}
}
@@ -178,7 +175,7 @@ public final class LocatorInfo
}
public void
- getEndpoints(final IndirectReference ref, final int ttl, final GetEndpointsCallback callback)
+ getEndpoints(final Reference ref, final int ttl, final GetEndpointsCallback callback)
{
final String adapterId = ref.getAdapterId();
final Ice.Identity identity = ref.getIdentity();
@@ -298,37 +295,36 @@ public final class LocatorInfo
}
public void
- clearObjectCache(IndirectReference ref)
+ clearObjectCache(Reference ref)
{
- if(ref.getAdapterId().length() == 0)
+ assert(ref.isIndirect());
+ if(ref.isWellKnown())
{
Ice.ObjectPrx object = _table.removeProxy(ref.getIdentity());
if(object != null)
{
- if(((Ice.ObjectPrxHelperBase)object).__reference() instanceof IndirectReference)
+ Reference r = ((Ice.ObjectPrxHelperBase)object).__reference();
+ if(!r.isIndirect())
{
- IndirectReference oir = (IndirectReference)((Ice.ObjectPrxHelperBase)object).__reference();
- if(oir.getAdapterId().length() > 0)
+ if(ref.getInstance().traceLevels().location >= 2)
{
- clearCache(oir);
+ trace("removed endpoints from locator table", ref, r.getEndpoints());
}
}
- else
+ else if(!r.isWellKnown())
{
- if(ref.getInstance().traceLevels().location >= 2)
- {
- trace("removed endpoints from locator table",
- ref, ((Ice.ObjectPrxHelperBase)object).__reference().getEndpoints());
- }
+ clearCache(r);
}
}
}
}
public void
- clearCache(IndirectReference ref)
+ clearCache(Reference ref)
{
- if(ref.getAdapterId().length() > 0)
+ assert(ref.isIndirect());
+
+ if(!ref.isWellKnown())
{
EndpointI[] endpoints = _table.removeAdapterEndpoints(ref.getAdapterId());
@@ -342,32 +338,30 @@ public final class LocatorInfo
Ice.ObjectPrx object = _table.removeProxy(ref.getIdentity());
if(object != null)
{
- if(((Ice.ObjectPrxHelperBase)object).__reference() instanceof IndirectReference)
+ Reference r = ((Ice.ObjectPrxHelperBase)object).__reference();
+ if(!r.isIndirect())
{
- IndirectReference oir = (IndirectReference)((Ice.ObjectPrxHelperBase)object).__reference();
- if(oir.getAdapterId().length() > 0)
+ if(ref.getInstance().traceLevels().location >= 2)
{
- clearCache(oir);
+ trace("removed endpoints from locator table", ref, r.getEndpoints());
}
}
- else
+ else if(!r.isWellKnown())
{
- if(ref.getInstance().traceLevels().location >= 2)
- {
- trace("removed endpoints from locator table",
- ref, ((Ice.ObjectPrxHelperBase)object).__reference().getEndpoints());
- }
+ clearCache(r);
}
}
}
}
private void
- trace(String msg, IndirectReference ref, EndpointI[] endpoints)
+ trace(String msg, Reference ref, EndpointI[] endpoints)
{
+ assert(ref.isIndirect());
+
StringBuffer s = new StringBuffer();
s.append(msg + "\n");
- if(ref.getAdapterId().length() > 0)
+ if(!ref.isWellKnown())
{
s.append("adapter = " + ref.getAdapterId() + "\n");
}
@@ -391,8 +385,10 @@ public final class LocatorInfo
}
private void
- getEndpointsException(IndirectReference ref, Exception exc)
+ getEndpointsException(Reference ref, Exception exc)
{
+ assert(ref.isIndirect());
+
try
{
throw exc;
@@ -460,7 +456,7 @@ public final class LocatorInfo
}
private void
- getEndpointsException(IndirectReference ref, Exception exc, GetEndpointsCallback callback)
+ getEndpointsException(Reference ref, Exception exc, GetEndpointsCallback callback)
{
try
{
@@ -477,7 +473,7 @@ public final class LocatorInfo
}
private void
- getWellKnownObjectEndpoints(final IndirectReference ref,
+ getWellKnownObjectEndpoints(final Reference ref,
final Ice.ObjectPrx object,
final int ttl,
final boolean objectCached,
@@ -487,42 +483,37 @@ public final class LocatorInfo
if(object != null)
{
Reference r = ((Ice.ObjectPrxHelperBase)object).__reference();
- if(r instanceof DirectReference)
+ if(!r.isIndirect())
{
- DirectReference odr = (DirectReference)r;
- endpoints = odr.getEndpoints();
+ endpoints = r.getEndpoints();
}
- else
+ else if(!r.isWellKnown())
{
- IndirectReference oir = (IndirectReference)r;
- if(oir.getAdapterId().length() > 0)
+ getEndpoints(r, ttl, new GetEndpointsCallback()
{
- getEndpoints(oir, ttl, new GetEndpointsCallback()
+ public void
+ setEndpoints(EndpointI[] endpoints, boolean endpointsCached)
+ {
+ if(!objectCached && endpoints != null && endpoints.length > 0)
{
- public void
- setEndpoints(EndpointI[] endpoints, boolean endpointsCached)
- {
- if(!objectCached && endpoints != null && endpoints.length > 0)
- {
- _table.addProxy(ref.getIdentity(), object);
- }
-
+ _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;
- }
+ }
+
+ public void
+ setException(Ice.LocalException ex)
+ {
+ callback.setException(ex);
+ }
+ });
+ return;
}
}
@@ -547,7 +538,7 @@ public final class LocatorInfo
}
private void
- getEndpointsTrace(IndirectReference ref, EndpointI[] endpoints, boolean cached)
+ getEndpointsTrace(Reference ref, EndpointI[] endpoints, boolean cached)
{
if(endpoints != null && endpoints.length > 0)
{
diff --git a/java/src/IceInternal/PropertyNames.java b/java/src/IceInternal/PropertyNames.java
index 6c3a3dac9cf..85f26c55a69 100644
--- a/java/src/IceInternal/PropertyNames.java
+++ b/java/src/IceInternal/PropertyNames.java
@@ -7,7 +7,7 @@
//
// **********************************************************************
//
-// Generated by makeprops.py from file ../config/PropertyNames.xml, Mon Jan 7 11:13:34 2008
+// Generated by makeprops.py from file ../config/PropertyNames.xml, Fri Jan 18 20:32:14 2008
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -26,6 +26,7 @@ public final class PropertyNames
new Property("Ice\\.Admin\\.RegisterProcess", true, null),
new Property("Ice\\.Admin\\.ReplicaGroupId", false, null),
new Property("Ice\\.Admin\\.Router", false, null),
+ new Property("Ice\\.Admin\\.ProxyOptions", false, null),
new Property("Ice\\.Admin\\.ThreadPerConnection", false, null),
new Property("Ice\\.Admin\\.ThreadPerConnection\\.StackSize", false, null),
new Property("Ice\\.Admin\\.ThreadPool\\.Size", false, null),
@@ -140,6 +141,7 @@ public final class PropertyNames
new Property("IceBox\\.ServiceManager\\.RegisterProcess", true, null),
new Property("IceBox\\.ServiceManager\\.ReplicaGroupId", false, null),
new Property("IceBox\\.ServiceManager\\.Router", false, null),
+ new Property("IceBox\\.ServiceManager\\.ProxyOptions", false, null),
new Property("IceBox\\.ServiceManager\\.ThreadPerConnection", false, null),
new Property("IceBox\\.ServiceManager\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceBox\\.ServiceManager\\.ThreadPool\\.Size", false, null),
@@ -187,6 +189,7 @@ public final class PropertyNames
new Property("IceGrid\\.Node\\.RegisterProcess", true, null),
new Property("IceGrid\\.Node\\.ReplicaGroupId", false, null),
new Property("IceGrid\\.Node\\.Router", false, null),
+ new Property("IceGrid\\.Node\\.ProxyOptions", false, null),
new Property("IceGrid\\.Node\\.ThreadPerConnection", false, null),
new Property("IceGrid\\.Node\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceGrid\\.Node\\.ThreadPool\\.Size", false, null),
@@ -227,6 +230,7 @@ public final class PropertyNames
new Property("IceGrid\\.Registry\\.AdminCallbackRouter\\.RegisterProcess", true, null),
new Property("IceGrid\\.Registry\\.AdminCallbackRouter\\.ReplicaGroupId", false, null),
new Property("IceGrid\\.Registry\\.AdminCallbackRouter\\.Router", false, null),
+ new Property("IceGrid\\.Registry\\.AdminCallbackRouter\\.ProxyOptions", false, null),
new Property("IceGrid\\.Registry\\.AdminCallbackRouter\\.ThreadPerConnection", false, null),
new Property("IceGrid\\.Registry\\.AdminCallbackRouter\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceGrid\\.Registry\\.AdminCallbackRouter\\.ThreadPool\\.Size", false, null),
@@ -252,6 +256,7 @@ public final class PropertyNames
new Property("IceGrid\\.Registry\\.AdminSessionManager\\.RegisterProcess", true, null),
new Property("IceGrid\\.Registry\\.AdminSessionManager\\.ReplicaGroupId", false, null),
new Property("IceGrid\\.Registry\\.AdminSessionManager\\.Router", false, null),
+ new Property("IceGrid\\.Registry\\.AdminSessionManager\\.ProxyOptions", false, null),
new Property("IceGrid\\.Registry\\.AdminSessionManager\\.ThreadPerConnection", false, null),
new Property("IceGrid\\.Registry\\.AdminSessionManager\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceGrid\\.Registry\\.AdminSessionManager\\.ThreadPool\\.Size", false, null),
@@ -275,6 +280,7 @@ public final class PropertyNames
new Property("IceGrid\\.Registry\\.Client\\.RegisterProcess", true, null),
new Property("IceGrid\\.Registry\\.Client\\.ReplicaGroupId", false, null),
new Property("IceGrid\\.Registry\\.Client\\.Router", false, null),
+ new Property("IceGrid\\.Registry\\.Client\\.ProxyOptions", false, null),
new Property("IceGrid\\.Registry\\.Client\\.ThreadPerConnection", false, null),
new Property("IceGrid\\.Registry\\.Client\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceGrid\\.Registry\\.Client\\.ThreadPool\\.Size", false, null),
@@ -292,6 +298,7 @@ public final class PropertyNames
new Property("IceGrid\\.Registry\\.Internal\\.RegisterProcess", true, null),
new Property("IceGrid\\.Registry\\.Internal\\.ReplicaGroupId", false, null),
new Property("IceGrid\\.Registry\\.Internal\\.Router", false, null),
+ new Property("IceGrid\\.Registry\\.Internal\\.ProxyOptions", false, null),
new Property("IceGrid\\.Registry\\.Internal\\.ThreadPerConnection", false, null),
new Property("IceGrid\\.Registry\\.Internal\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceGrid\\.Registry\\.Internal\\.ThreadPool\\.Size", false, null),
@@ -318,6 +325,7 @@ public final class PropertyNames
new Property("IceGrid\\.Registry\\.Server\\.RegisterProcess", true, null),
new Property("IceGrid\\.Registry\\.Server\\.ReplicaGroupId", false, null),
new Property("IceGrid\\.Registry\\.Server\\.Router", false, null),
+ new Property("IceGrid\\.Registry\\.Server\\.ProxyOptions", false, null),
new Property("IceGrid\\.Registry\\.Server\\.ThreadPerConnection", false, null),
new Property("IceGrid\\.Registry\\.Server\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceGrid\\.Registry\\.Server\\.ThreadPool\\.Size", false, null),
@@ -332,6 +340,7 @@ public final class PropertyNames
new Property("IceGrid\\.Registry\\.SessionManager\\.RegisterProcess", true, null),
new Property("IceGrid\\.Registry\\.SessionManager\\.ReplicaGroupId", false, null),
new Property("IceGrid\\.Registry\\.SessionManager\\.Router", false, null),
+ new Property("IceGrid\\.Registry\\.SessionManager\\.ProxyOptions", false, null),
new Property("IceGrid\\.Registry\\.SessionManager\\.ThreadPerConnection", false, null),
new Property("IceGrid\\.Registry\\.SessionManager\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceGrid\\.Registry\\.SessionManager\\.ThreadPool\\.Size", false, null),
@@ -371,6 +380,7 @@ public final class PropertyNames
new Property("IcePatch2\\.RegisterProcess", true, null),
new Property("IcePatch2\\.ReplicaGroupId", false, null),
new Property("IcePatch2\\.Router", false, null),
+ new Property("IcePatch2\\.ProxyOptions", false, null),
new Property("IcePatch2\\.ThreadPerConnection", false, null),
new Property("IcePatch2\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IcePatch2\\.ThreadPool\\.Size", false, null),
@@ -452,6 +462,7 @@ public final class PropertyNames
new Property("IceStorm\\.Publish\\.RegisterProcess", true, null),
new Property("IceStorm\\.Publish\\.ReplicaGroupId", false, null),
new Property("IceStorm\\.Publish\\.Router", false, null),
+ new Property("IceStorm\\.Publish\\.ProxyOptions", false, null),
new Property("IceStorm\\.Publish\\.ThreadPerConnection", false, null),
new Property("IceStorm\\.Publish\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceStorm\\.Publish\\.ThreadPool\\.Size", false, null),
@@ -465,6 +476,7 @@ public final class PropertyNames
new Property("IceStorm\\.TopicManager\\.RegisterProcess", true, null),
new Property("IceStorm\\.TopicManager\\.ReplicaGroupId", false, null),
new Property("IceStorm\\.TopicManager\\.Router", false, null),
+ new Property("IceStorm\\.TopicManager\\.ProxyOptions", false, null),
new Property("IceStorm\\.TopicManager\\.ThreadPerConnection", false, null),
new Property("IceStorm\\.TopicManager\\.ThreadPerConnection\\.StackSize", false, null),
new Property("IceStorm\\.TopicManager\\.ThreadPool\\.Size", false, null),
@@ -520,6 +532,7 @@ public final class PropertyNames
new Property("Glacier2\\.Client\\.RegisterProcess", true, null),
new Property("Glacier2\\.Client\\.ReplicaGroupId", false, null),
new Property("Glacier2\\.Client\\.Router", false, null),
+ new Property("Glacier2\\.Client\\.ProxyOptions", false, null),
new Property("Glacier2\\.Client\\.ThreadPerConnection", false, null),
new Property("Glacier2\\.Client\\.ThreadPerConnection\\.StackSize", false, null),
new Property("Glacier2\\.Client\\.ThreadPool\\.Size", false, null),
@@ -571,6 +584,7 @@ public final class PropertyNames
new Property("Glacier2\\.Server\\.RegisterProcess", true, null),
new Property("Glacier2\\.Server\\.ReplicaGroupId", false, null),
new Property("Glacier2\\.Server\\.Router", false, null),
+ new Property("Glacier2\\.Server\\.ProxyOptions", false, null),
new Property("Glacier2\\.Server\\.ThreadPerConnection", false, null),
new Property("Glacier2\\.Server\\.ThreadPerConnection\\.StackSize", false, null),
new Property("Glacier2\\.Server\\.ThreadPool\\.Size", false, null),
diff --git a/java/src/IceInternal/ProxyFactory.java b/java/src/IceInternal/ProxyFactory.java
index 874aae823b3..411bdf6e396 100644
--- a/java/src/IceInternal/ProxyFactory.java
+++ b/java/src/IceInternal/ProxyFactory.java
@@ -14,7 +14,7 @@ public final class ProxyFactory
public Ice.ObjectPrx
stringToProxy(String str)
{
- Reference ref = _instance.referenceFactory().create(str);
+ Reference ref = _instance.referenceFactory().create(str, null);
return referenceToProxy(ref);
}
@@ -35,7 +35,8 @@ public final class ProxyFactory
public Ice.ObjectPrx
propertyToProxy(String prefix)
{
- Reference ref = _instance.referenceFactory().createFromProperties(prefix);
+ String proxy = _instance.initializationData().properties.getProperty(prefix);
+ Reference ref = _instance.referenceFactory().create(proxy, prefix);
return referenceToProxy(ref);
}
@@ -105,13 +106,13 @@ public final class ProxyFactory
Ice.ObjectNotExistException one = (Ice.ObjectNotExistException)ex;
LocatorInfo li = ref.getLocatorInfo();
- if(li != null)
+ if(li != null && ref.isIndirect())
{
//
// We retry ObjectNotExistException if the reference is
// indirect.
//
- li.clearObjectCache((IceInternal.IndirectReference)ref);
+ li.clearObjectCache(ref);
}
else if(ref.getRouterInfo() != null && one.operation.equals("ice_add_proxy"))
{
diff --git a/java/src/IceInternal/Reference.java b/java/src/IceInternal/Reference.java
index 55f947e9880..27a31d55f8e 100644
--- a/java/src/IceInternal/Reference.java
+++ b/java/src/IceInternal/Reference.java
@@ -30,6 +30,12 @@ public abstract class Reference implements Cloneable
return _mode;
}
+ public final boolean
+ getSecure()
+ {
+ return _secure;
+ }
+
public final Ice.Identity
getIdentity()
{
@@ -63,32 +69,22 @@ public abstract class Reference implements Cloneable
}
- public final Ice.Communicator getCommunicator()
+ public final Ice.Communicator
+ getCommunicator()
{
return _communicator;
}
- public RouterInfo
- getRouterInfo()
- {
- return null;
- }
-
- public LocatorInfo
- getLocatorInfo()
- {
- return null;
- }
-
- public abstract boolean getSecure();
- public abstract boolean getPreferSecure();
- public abstract String getAdapterId();
public abstract EndpointI[] getEndpoints();
- public abstract boolean getCollocationOptimization();
- public abstract int getLocatorCacheTimeout();
+ public abstract String getAdapterId();
+ public abstract RouterInfo getRouterInfo();
+ public abstract LocatorInfo getLocatorInfo();
+ public abstract boolean getCollocationOptimized();
public abstract boolean getCacheConnection();
+ public abstract boolean getPreferSecure();
public abstract Ice.EndpointSelectionType getEndpointSelection();
public abstract boolean getThreadPerConnection();
+ public abstract int getLocatorCacheTimeout();
//
// The change* methods (here and in derived classes) create
@@ -126,6 +122,18 @@ public abstract class Reference implements Cloneable
return r;
}
+ public Reference
+ changeSecure(boolean newSecure)
+ {
+ if(newSecure == _secure)
+ {
+ return this;
+ }
+ Reference r = (Reference)_instance.referenceFactory().copy(this);
+ r._secure = newSecure;
+ return r;
+ }
+
public final Reference
changeIdentity(Ice.Identity newIdentity)
{
@@ -163,19 +171,19 @@ public abstract class Reference implements Cloneable
return r;
}
- public abstract Reference changeSecure(boolean newSecure);
- public abstract Reference changePreferSecure(boolean newPreferSecure);
- public abstract Reference changeRouter(Ice.RouterPrx newRouter);
- public abstract Reference changeLocator(Ice.LocatorPrx newLocator);
- public abstract Reference changeTimeout(int newTimeout);
- public abstract Reference changeConnectionId(String connectionId);
- public abstract Reference changeCollocationOptimization(boolean newCollocationOptimization);
public abstract Reference changeAdapterId(String newAdapterId);
public abstract Reference changeEndpoints(EndpointI[] newEndpoints);
- public abstract Reference changeLocatorCacheTimeout(int newTimeout);
+ public abstract Reference changeLocator(Ice.LocatorPrx newLocator);
+ public abstract Reference changeRouter(Ice.RouterPrx newRouter);
+ public abstract Reference changeCollocationOptimized(boolean newCollocationOptimized);
public abstract Reference changeCacheConnection(boolean newCache);
+ public abstract Reference changePreferSecure(boolean newPreferSecure);
public abstract Reference changeEndpointSelection(Ice.EndpointSelectionType newType);
public abstract Reference changeThreadPerConnection(boolean newTpc);
+ public abstract Reference changeLocatorCacheTimeout(int newTimeout);
+
+ public abstract Reference changeTimeout(int newTimeout);
+ public abstract Reference changeConnectionId(String connectionId);
public synchronized int
hashCode()
@@ -207,7 +215,7 @@ public abstract class Reference implements Cloneable
h = 5 * h + (int)_facet.charAt(i);
}
- h = 5 * h + (getSecure() ? 1 : 0);
+ h = 5 * h + (_secure ? 1 : 0);
_hashValue = h;
_hashInitialized = true;
@@ -216,6 +224,12 @@ public abstract class Reference implements Cloneable
}
//
+ // Utility methods
+ //
+ public abstract boolean isIndirect();
+ public abstract boolean isWellKnown();
+
+ //
// Marshal the reference.
//
public void
@@ -241,7 +255,7 @@ public abstract class Reference implements Cloneable
s.writeByte((byte)_mode);
- s.writeBool(getSecure());
+ s.writeBool(_secure);
// Derived class writes the remainder of the reference.
}
@@ -332,7 +346,7 @@ public abstract class Reference implements Cloneable
}
}
- if(getSecure())
+ if(_secure)
{
s.append(" -s");
}
@@ -359,6 +373,11 @@ public abstract class Reference implements Cloneable
return false;
}
+ if(_secure != r._secure)
+ {
+ return false;
+ }
+
if(!_identity.equals(r._identity))
{
return false;
@@ -402,41 +421,44 @@ public abstract class Reference implements Cloneable
return o;
}
- private Instance _instance;
- private Ice.Communicator _communicator;
+ protected int _hashValue;
+ protected boolean _hashInitialized;
+ private static java.util.HashMap _emptyContext = new java.util.HashMap();
+
+ final private Instance _instance;
+ final private Ice.Communicator _communicator;
private int _mode;
+ private boolean _secure;
private Ice.Identity _identity;
private java.util.Map _context;
- private static java.util.HashMap _emptyContext = new java.util.HashMap();
private String _facet;
-
- protected int _hashValue;
- protected boolean _hashInitialized;
protected boolean _overrideCompress;
protected boolean _compress; // Only used if _overrideCompress == true
protected
- Reference(Instance inst,
+ Reference(Instance instance,
Ice.Communicator communicator,
- Ice.Identity ident,
- java.util.Map ctx,
- String fac,
- int md)
+ Ice.Identity identity,
+ java.util.Map context,
+ String facet,
+ int mode,
+ boolean secure)
{
//
// Validate string arguments.
//
- assert(ident.name != null);
- assert(ident.category != null);
- assert(fac != null);
+ assert(identity.name != null);
+ assert(identity.category != null);
+ assert(facet != null);
- _instance = inst;
+ _instance = instance;
_communicator = communicator;
- _mode = md;
- _identity = ident;
- _context = ctx == null ? _emptyContext : ctx;
- _facet = fac;
+ _mode = mode;
+ _secure = secure;
+ _identity = identity;
+ _context = context == null ? _emptyContext : context;
+ _facet = facet;
_hashInitialized = false;
_overrideCompress = false;
_compress = false;
diff --git a/java/src/IceInternal/ReferenceFactory.java b/java/src/IceInternal/ReferenceFactory.java
index b05b9198942..07f61c9c002 100644
--- a/java/src/IceInternal/ReferenceFactory.java
+++ b/java/src/IceInternal/ReferenceFactory.java
@@ -11,87 +11,31 @@ package IceInternal;
public final class ReferenceFactory
{
- public synchronized Reference
- create(Ice.Identity ident,
- java.util.Map context,
- String facet,
- int mode,
- boolean secure,
- boolean preferSecure,
- EndpointI[] endpoints,
- RouterInfo routerInfo,
- boolean collocationOptimization,
- boolean cacheConnection,
- Ice.EndpointSelectionType endpointSelection,
- boolean threadPerConnection)
+ public Reference
+ create(Ice.Identity ident, String facet, Reference tmpl, EndpointI[] endpoints)
{
- if(_instance == null)
- {
- throw new Ice.CommunicatorDestroyedException();
- }
-
if(ident.name.length() == 0 && ident.category.length() == 0)
{
return null;
}
- //
- // Create new reference
- //
- DirectReference ref = new DirectReference(_instance, _communicator, ident, context, facet, mode, secure,
- preferSecure, endpoints, routerInfo, collocationOptimization,
- cacheConnection, endpointSelection, threadPerConnection);
- return updateCache(ref);
+ return create(ident, facet, tmpl.getMode(), tmpl.getSecure(), endpoints, null, null);
}
- public synchronized Reference
- create(Ice.Identity ident,
- java.util.Map context,
- String facet,
- int mode,
- boolean secure,
- boolean preferSecure,
- String adapterId,
- RouterInfo routerInfo,
- LocatorInfo locatorInfo,
- boolean collocationOptimization,
- boolean cacheConnection,
- Ice.EndpointSelectionType endpointSelection,
- boolean threadPerConnection,
- int locatorCacheTimeout)
+ public Reference
+ create(Ice.Identity ident, String facet, Reference tmpl, String adapterId)
{
- if(_instance == null)
- {
- throw new Ice.CommunicatorDestroyedException();
- }
-
if(ident.name.length() == 0 && ident.category.length() == 0)
{
return null;
}
- //
- // Create new reference
- //
- IndirectReference ref = new IndirectReference(_instance, _communicator, ident, context, facet, mode, secure,
- preferSecure, adapterId, routerInfo, locatorInfo,
- collocationOptimization, cacheConnection, endpointSelection,
- threadPerConnection, locatorCacheTimeout);
- return updateCache(ref);
+ return create(ident, facet, tmpl.getMode(), tmpl.getSecure(), null, adapterId, null);
}
- public synchronized Reference
- create(Ice.Identity ident,
- java.util.Map context,
- String facet,
- int mode,
- Ice.ConnectionI[] fixedConnections)
+ public Reference
+ create(Ice.Identity ident, Ice.ConnectionI fixedConnection)
{
- if(_instance == null)
- {
- throw new Ice.CommunicatorDestroyedException();
- }
-
if(ident.name.length() == 0 && ident.category.length() == 0)
{
return null;
@@ -100,19 +44,20 @@ public final class ReferenceFactory
//
// Create new reference
//
- FixedReference ref = new FixedReference(_instance, _communicator, ident, context, facet, mode,
- fixedConnections);
+ FixedReference ref = new FixedReference(_instance,
+ _communicator,
+ ident,
+ _instance.getDefaultContext(),
+ "", // Facet
+ Reference.ModeTwoway,
+ false,
+ fixedConnection);
return updateCache(ref);
}
- public synchronized Reference
+ public Reference
copy(Reference r)
{
- if(_instance == null)
- {
- throw new Ice.CommunicatorDestroyedException();
- }
-
Ice.Identity ident = r.getIdentity();
if(ident.name.length() == 0 && ident.category.length() == 0)
{
@@ -122,7 +67,7 @@ public final class ReferenceFactory
}
public Reference
- create(String s)
+ create(String s, String propertyPrefix)
{
if(s == null || s.length() == 0)
{
@@ -395,16 +340,9 @@ public final class ReferenceFactory
}
}
- RouterInfo routerInfo = _instance.routerManager().get(getDefaultRouter());
- LocatorInfo locatorInfo = _instance.locatorManager().get(getDefaultLocator());
-
if(beg == -1)
{
- return create(ident, _instance.getDefaultContext(), facet, mode, secure,
- _instance.defaultsAndOverrides().defaultPreferSecure, "", routerInfo,
- locatorInfo, _instance.defaultsAndOverrides().defaultCollocationOptimization, true,
- _instance.defaultsAndOverrides().defaultEndpointSelection, _instance.threadPerConnection(),
- _instance.defaultsAndOverrides().defaultLocatorCacheTimeout);
+ return create(ident, facet, mode, secure, null, null, propertyPrefix);
}
java.util.ArrayList endpoints = new java.util.ArrayList();
@@ -492,10 +430,7 @@ public final class ReferenceFactory
EndpointI[] endp = new EndpointI[endpoints.size()];
endpoints.toArray(endp);
- return create(ident, _instance.getDefaultContext(), facet, mode, secure,
- _instance.defaultsAndOverrides().defaultPreferSecure, endp, routerInfo,
- _instance.defaultsAndOverrides().defaultCollocationOptimization, true,
- _instance.defaultsAndOverrides().defaultEndpointSelection, _instance.threadPerConnection());
+ return create(ident, facet, mode, secure, endp, null, propertyPrefix);
}
else if(s.charAt(beg) == '@')
{
@@ -547,11 +482,7 @@ public final class ReferenceFactory
throw e;
}
adapter = token.value;
- return create(ident, _instance.getDefaultContext(), facet, mode, secure,
- _instance.defaultsAndOverrides().defaultPreferSecure, adapter,
- routerInfo, locatorInfo, _instance.defaultsAndOverrides().defaultCollocationOptimization,
- true, _instance.defaultsAndOverrides().defaultEndpointSelection,
- _instance.threadPerConnection(), _instance.defaultsAndOverrides().defaultLocatorCacheTimeout);
+ return create(ident, facet, mode, secure, null, adapter, propertyPrefix);
}
Ice.ProxyParseException ex = new Ice.ProxyParseException();
@@ -560,111 +491,6 @@ public final class ReferenceFactory
}
public Reference
- createFromProperties(String propertyPrefix)
- {
- Ice.Properties properties = _instance.initializationData().properties;
-
- Reference ref = create(properties.getProperty(propertyPrefix));
- if(ref == null)
- {
- return null;
- }
-
- //
- // Warn about unknown properties.
- //
- if(properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0)
- {
- checkForUnknownProperties(propertyPrefix);
- }
-
- String property = propertyPrefix + ".Locator";
- if(properties.getProperty(property).length() != 0)
- {
- ref = ref.changeLocator(Ice.LocatorPrxHelper.uncheckedCast(_communicator.propertyToProxy(property)));
- if(ref instanceof DirectReference)
- {
- String s = "`" + property + "=" + properties.getProperty(property) +
- "': cannot set a locator on a direct reference; setting ignored";
- _instance.initializationData().logger.warning(s);
- }
- }
-
- property = propertyPrefix + ".LocatorCacheTimeout";
- if(properties.getProperty(property).length() != 0)
- {
- ref = ref.changeLocatorCacheTimeout(properties.getPropertyAsInt(property));
- if(ref instanceof DirectReference)
- {
- String s = "`" + property + "=" + properties.getProperty(property) +
- "': cannot set a locator cache timeout on a direct reference; setting ignored";
- _instance.initializationData().logger.warning(s);
- }
- }
-
- property = propertyPrefix + ".Router";
- if(properties.getProperty(property).length() != 0)
- {
- if(propertyPrefix.endsWith(".Router"))
- {
- String s = "`" + property + "=" + properties.getProperty(property) +
- "': cannot set a router on a router; setting ignored";
- _instance.initializationData().logger.warning(s);
- }
- else
- {
- ref = ref.changeRouter(Ice.RouterPrxHelper.uncheckedCast(_communicator.propertyToProxy(property)));
- }
- }
-
- property = propertyPrefix + ".PreferSecure";
- if(properties.getProperty(property).length() != 0)
- {
- ref = ref.changePreferSecure(properties.getPropertyAsInt(property) > 0);
- }
-
- property = propertyPrefix + ".ConnectionCached";
- if(properties.getProperty(property).length() != 0)
- {
- ref = ref.changeCacheConnection(properties.getPropertyAsInt(property) > 0);
- }
-
- property = propertyPrefix + ".EndpointSelection";
- if(properties.getProperty(property).length() != 0)
- {
- String type = properties.getProperty(property);
- if(type.equals("Random"))
- {
- ref = ref.changeEndpointSelection(Ice.EndpointSelectionType.Random);
- }
- else if(type.equals("Ordered"))
- {
- ref = ref.changeEndpointSelection(Ice.EndpointSelectionType.Ordered);
- }
- else
- {
- Ice.EndpointSelectionTypeParseException ex = new Ice.EndpointSelectionTypeParseException();
- ex.str = type;
- throw ex;
- }
- }
-
- property = propertyPrefix + ".CollocationOptimized";
- if(properties.getProperty(property).length() != 0)
- {
- ref = ref.changeCollocationOptimization(properties.getPropertyAsInt(property) > 0);
- }
-
- property = propertyPrefix + ".ThreadPerConnection";
- if(properties.getProperty(property).length() != 0)
- {
- ref = ref.changeThreadPerConnection(properties.getPropertyAsInt(property) > 0);
- }
-
- return ref;
- }
-
- public Reference
create(Ice.Identity ident, BasicStream s)
{
//
@@ -703,11 +529,8 @@ public final class ReferenceFactory
boolean secure = s.readBool();
- EndpointI[] endpoints;
- String adapterId = "";
-
- RouterInfo routerInfo = _instance.routerManager().get(getDefaultRouter());
- LocatorInfo locatorInfo = _instance.locatorManager().get(getDefaultLocator());
+ EndpointI[] endpoints = null;
+ String adapterId = null;
int sz = s.readSize();
if(sz > 0)
@@ -717,42 +540,50 @@ public final class ReferenceFactory
{
endpoints[i] = _instance.endpointFactoryManager().read(s);
}
- return create(ident, _instance.getDefaultContext(), facet, mode, secure,
- _instance.defaultsAndOverrides().defaultPreferSecure, endpoints,
- routerInfo, _instance.defaultsAndOverrides().defaultCollocationOptimization, true,
- _instance.defaultsAndOverrides().defaultEndpointSelection, _instance.threadPerConnection());
}
else
{
- endpoints = new EndpointI[0];
adapterId = s.readString();
- return create(ident, _instance.getDefaultContext(), facet, mode, secure,
- _instance.defaultsAndOverrides().defaultPreferSecure, adapterId, routerInfo, locatorInfo,
- _instance.defaultsAndOverrides().defaultCollocationOptimization, true,
- _instance.defaultsAndOverrides().defaultEndpointSelection, _instance.threadPerConnection(),
- _instance.defaultsAndOverrides().defaultLocatorCacheTimeout);
}
+
+ return create(ident, facet, mode, secure, endpoints, adapterId, null);
}
- public synchronized void
+ public ReferenceFactory
setDefaultRouter(Ice.RouterPrx defaultRouter)
{
- _defaultRouter = defaultRouter;
+ if(_defaultRouter == null ? defaultRouter == null : _defaultRouter.equals(defaultRouter))
+ {
+ return this;
+ }
+
+ ReferenceFactory factory = new ReferenceFactory(_instance, _communicator);
+ factory._defaultLocator = _defaultLocator;
+ factory._defaultRouter = defaultRouter;
+ return factory;
}
- public synchronized Ice.RouterPrx
+ public Ice.RouterPrx
getDefaultRouter()
{
return _defaultRouter;
}
- public synchronized void
+ public ReferenceFactory
setDefaultLocator(Ice.LocatorPrx defaultLocator)
{
- _defaultLocator = defaultLocator;
+ if(_defaultLocator == null ? defaultLocator == null : _defaultLocator.equals(defaultLocator))
+ {
+ return this;
+ }
+
+ ReferenceFactory factory = new ReferenceFactory(_instance, _communicator);
+ factory._defaultRouter = _defaultRouter;
+ factory._defaultLocator = defaultLocator;
+ return factory;
}
- public synchronized Ice.LocatorPrx
+ public Ice.LocatorPrx
getDefaultLocator()
{
return _defaultLocator;
@@ -770,19 +601,10 @@ public final class ReferenceFactory
synchronized void
destroy()
{
- if(_instance == null)
- {
- throw new Ice.CommunicatorDestroyedException();
- }
-
- _instance = null;
- _communicator = null;
- _defaultRouter = null;
- _defaultLocator = null;
_references.clear();
}
- private Reference
+ synchronized private Reference
updateCache(Reference ref)
{
//
@@ -879,8 +701,122 @@ public final class ReferenceFactory
}
}
- private Instance _instance;
- private Ice.Communicator _communicator;
+ private Reference
+ create(Ice.Identity ident, String facet, int mode, boolean secure, EndpointI[] endpoints, String adapterId,
+ String propertyPrefix)
+ {
+ DefaultsAndOverrides defaultsAndOverrides = _instance.defaultsAndOverrides();
+
+ //
+ // Default local proxy options.
+ //
+ LocatorInfo locatorInfo = _instance.locatorManager().get(_defaultLocator);
+ RouterInfo routerInfo = _instance.routerManager().get(_defaultRouter);
+ boolean collocationOptimized = defaultsAndOverrides.defaultCollocationOptimization;
+ boolean cacheConnection = true;
+ boolean preferSecure = defaultsAndOverrides.defaultPreferSecure;
+ Ice.EndpointSelectionType endpointSelection = defaultsAndOverrides.defaultEndpointSelection;
+ boolean threadPerConnection = _instance.threadPerConnection();
+ int locatorCacheTimeout = defaultsAndOverrides.defaultLocatorCacheTimeout;
+
+ //
+ // Override the defaults with the proxy properties if a property prefix is defined.
+ //
+ if(propertyPrefix != null && propertyPrefix.length() > 0)
+ {
+ Ice.Properties properties = _instance.initializationData().properties;
+
+ //
+ // Warn about unknown properties.
+ //
+ if(properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0)
+ {
+ checkForUnknownProperties(propertyPrefix);
+ }
+
+ String property;
+
+ property = propertyPrefix + ".Locator";
+ Ice.LocatorPrx locator = Ice.LocatorPrxHelper.uncheckedCast(_communicator.propertyToProxy(property));
+ if(locator != null)
+ {
+ locatorInfo = _instance.locatorManager().get(locator);
+ }
+
+ property = propertyPrefix + ".Router";
+ Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(_communicator.propertyToProxy(property));
+ if(router != null)
+ {
+ if(propertyPrefix.endsWith(".Router"))
+ {
+ String s = "`" + property + "=" + properties.getProperty(property) +
+ "': cannot set a router on a router; setting ignored";
+ _instance.initializationData().logger.warning(s);
+ }
+ else
+ {
+ routerInfo = _instance.routerManager().get(router);
+ }
+ }
+
+ property = propertyPrefix + ".CollocationOptimized";
+ collocationOptimized = properties.getPropertyAsIntWithDefault(property, collocationOptimized ? 1 : 0) > 0;
+
+ property = propertyPrefix + ".ConnectionCached";
+ cacheConnection = properties.getPropertyAsIntWithDefault(property, cacheConnection ? 1 : 0) > 0;
+
+ property = propertyPrefix + ".PreferSecure";
+ preferSecure = properties.getPropertyAsIntWithDefault(property, preferSecure ? 1 : 0) > 0;
+
+ property = propertyPrefix + ".EndpointSelection";
+ if(properties.getProperty(property).length() > 0)
+ {
+ String type = properties.getProperty(property);
+ if(type.equals("Random"))
+ {
+ endpointSelection = Ice.EndpointSelectionType.Random;
+ }
+ else if(type.equals("Ordered"))
+ {
+ endpointSelection = Ice.EndpointSelectionType.Ordered;
+ }
+ else
+ {
+ throw new Ice.EndpointSelectionTypeParseException(type);
+ }
+ }
+
+ property = propertyPrefix + ".ThreadPerConnection";
+ threadPerConnection = properties.getPropertyAsIntWithDefault(property, threadPerConnection ? 1 : 0) > 0;
+
+ property = propertyPrefix + ".LocatorCacheTimeout";
+ locatorCacheTimeout = properties.getPropertyAsIntWithDefault(property, locatorCacheTimeout);
+ }
+
+ //
+ // Create new reference
+ //
+ return updateCache(new RoutableReference(_instance,
+ _communicator,
+ ident,
+ _instance.getDefaultContext(),
+ facet,
+ mode,
+ secure,
+ endpoints,
+ adapterId,
+ locatorInfo,
+ routerInfo,
+ collocationOptimized,
+ cacheConnection,
+ preferSecure,
+ endpointSelection,
+ threadPerConnection,
+ locatorCacheTimeout));
+ }
+
+ final private Instance _instance;
+ final private Ice.Communicator _communicator;
private Ice.RouterPrx _defaultRouter;
private Ice.LocatorPrx _defaultLocator;
private java.util.WeakHashMap _references = new java.util.WeakHashMap();
diff --git a/java/src/IceInternal/RoutableReference.java b/java/src/IceInternal/RoutableReference.java
index 82dde6c8fe7..63f51bbc484 100644
--- a/java/src/IceInternal/RoutableReference.java
+++ b/java/src/IceInternal/RoutableReference.java
@@ -9,30 +9,36 @@
package IceInternal;
-public abstract class RoutableReference extends Reference
+public class RoutableReference extends Reference
{
- public final RouterInfo
- getRouterInfo()
+ public final EndpointI[]
+ getEndpoints()
{
- return _routerInfo;
+ return _endpoints;
}
- public final boolean
- getSecure()
+ public final String
+ getAdapterId()
{
- return _secure;
+ return _adapterId;
}
- public final boolean
- getPreferSecure()
+ public final LocatorInfo
+ getLocatorInfo()
{
- return _preferSecure;
+ return _locatorInfo;
+ }
+
+ public final RouterInfo
+ getRouterInfo()
+ {
+ return _routerInfo;
}
public final boolean
- getCollocationOptimization()
+ getCollocationOptimized()
{
- return _collocationOptimization;
+ return _collocationOptimized;
}
public final boolean
@@ -41,6 +47,12 @@ public abstract class RoutableReference extends Reference
return _cacheConnection;
}
+ public final boolean
+ getPreferSecure()
+ {
+ return _preferSecure;
+ }
+
public final Ice.EndpointSelectionType
getEndpointSelection()
{
@@ -53,78 +65,91 @@ public abstract class RoutableReference extends Reference
return _threadPerConnection;
}
+ public final int
+ getLocatorCacheTimeout()
+ {
+ return _locatorCacheTimeout;
+ }
+
public Reference
- changeSecure(boolean newSecure)
+ changeCompress(boolean newCompress)
{
- if(newSecure == _secure)
+ RoutableReference r = (RoutableReference)super.changeCompress(newCompress);
+ if(r != this && _endpoints.length > 0) // Also override the compress flag on the endpoints if it was updated.
{
- return this;
+ EndpointI[] newEndpoints = new EndpointI[_endpoints.length];
+ for(int i = 0; i < _endpoints.length; i++)
+ {
+ newEndpoints[i] = _endpoints[i].compress(newCompress);
+ }
+ r._endpoints = newEndpoints;
}
- RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
- r._secure = newSecure;
return r;
}
public Reference
- changePreferSecure(boolean newPreferSecure)
+ changeEndpoints(EndpointI[] newEndpoints)
{
- if(newPreferSecure == _preferSecure)
+ if(java.util.Arrays.equals(newEndpoints, _endpoints))
{
return this;
}
RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
- r._preferSecure = newPreferSecure;
+ r._endpoints = newEndpoints;
+ r._adapterId = "";
+ r.applyOverrides(r._endpoints);
return r;
}
public Reference
- changeRouter(Ice.RouterPrx newRouter)
+ changeAdapterId(String newAdapterId)
{
- RouterInfo newRouterInfo = getInstance().routerManager().get(newRouter);
- if(newRouterInfo != null && _routerInfo != null && newRouterInfo.equals(_routerInfo))
+ if(_adapterId.equals(newAdapterId))
{
return this;
}
RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
- r._routerInfo = newRouterInfo;
- return r;
+ r._adapterId = newAdapterId;
+ r._endpoints = _emptyEndpoints;
+ return r;
}
public Reference
- changeCollocationOptimization(boolean newCollocationOptimization)
+ changeLocator(Ice.LocatorPrx newLocator)
{
- if(newCollocationOptimization == _collocationOptimization)
+ LocatorInfo newLocatorInfo = getInstance().locatorManager().get(newLocator);
+ if(newLocatorInfo != null && _locatorInfo != null && newLocatorInfo.equals(_locatorInfo))
{
return this;
}
RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
- r._collocationOptimization = newCollocationOptimization;
+ r._locatorInfo = newLocatorInfo;
return r;
}
public Reference
- changeTimeout(int newTimeout)
+ changeRouter(Ice.RouterPrx newRouter)
{
- if(_overrideTimeout && _timeout == newTimeout)
+ RouterInfo newRouterInfo = getInstance().routerManager().get(newRouter);
+ if(newRouterInfo != null && _routerInfo != null && newRouterInfo.equals(_routerInfo))
{
return this;
}
RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
- r._timeout = newTimeout;
- r._overrideTimeout = true;
- return r;
+ r._routerInfo = newRouterInfo;
+ return r;
}
public Reference
- changeConnectionId(String id)
+ changeCollocationOptimized(boolean newCollocationOptimized)
{
- if(_connectionId.equals(id))
+ if(newCollocationOptimized == _collocationOptimized)
{
return this;
}
RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
- r._connectionId = id;
- return r;
+ r._collocationOptimized = newCollocationOptimized;
+ return r;
}
public final Reference
@@ -139,6 +164,18 @@ public abstract class RoutableReference extends Reference
return r;
}
+ public Reference
+ changePreferSecure(boolean newPreferSecure)
+ {
+ if(newPreferSecure == _preferSecure)
+ {
+ return this;
+ }
+ RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
+ r._preferSecure = newPreferSecure;
+ return r;
+ }
+
public final Reference
changeEndpointSelection(Ice.EndpointSelectionType newType)
{
@@ -163,33 +200,184 @@ public abstract class RoutableReference extends Reference
return r;
}
+ public Reference
+ changeLocatorCacheTimeout(int newTimeout)
+ {
+ if(_locatorCacheTimeout == newTimeout)
+ {
+ return this;
+ }
+ RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
+ r._locatorCacheTimeout = newTimeout;
+ return r;
+ }
+
+ public Reference
+ changeTimeout(int newTimeout)
+ {
+ if(_overrideTimeout && _timeout == newTimeout)
+ {
+ return this;
+ }
+ RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
+ r._timeout = newTimeout;
+ r._overrideTimeout = true;
+ if(_endpoints.length > 0)
+ {
+ EndpointI[] newEndpoints = new EndpointI[_endpoints.length];
+ for(int i = 0; i < _endpoints.length; i++)
+ {
+ newEndpoints[i] = _endpoints[i].timeout(newTimeout);
+ }
+ r._endpoints = newEndpoints;
+ }
+ return r;
+ }
+
+ public Reference
+ changeConnectionId(String id)
+ {
+ if(_connectionId.equals(id))
+ {
+ return this;
+ }
+ RoutableReference r = (RoutableReference)getInstance().referenceFactory().copy(this);
+ r._connectionId = id;
+ if(_endpoints.length > 0)
+ {
+ EndpointI[] newEndpoints = new EndpointI[_endpoints.length];
+ for(int i = 0; i < _endpoints.length; i++)
+ {
+ newEndpoints[i] = _endpoints[i].connectionId(id);
+ }
+ r._endpoints = newEndpoints;
+ }
+ return r;
+ }
+
+ public boolean
+ isIndirect()
+ {
+ return _endpoints.length == 0;
+ }
+
+ public boolean
+ isWellKnown()
+ {
+ return _endpoints.length == 0 && _adapterId.length() == 0;
+ }
+
+ public void
+ streamWrite(BasicStream s)
+ throws Ice.MarshalException
+ {
+ super.streamWrite(s);
+
+ s.writeSize(_endpoints.length);
+ if(_endpoints.length > 0)
+ {
+ assert(_adapterId.length() == 0);
+ for(int i = 0; i < _endpoints.length; i++)
+ {
+ _endpoints[i].streamWrite(s);
+ }
+ }
+ else
+ {
+ s.writeString(_adapterId); // Adapter id.
+ }
+ }
+
+ public String
+ toString()
+ {
+ //
+ // WARNING: Certain features, such as proxy validation in Glacier2,
+ // depend on the format of proxy strings. Changes to toString() and
+ // methods called to generate parts of the reference string could break
+ // these features. Please review for all features that depend on the
+ // format of proxyToString() before changing this and related code.
+ //
+ StringBuffer s = new StringBuffer();
+ s.append(super.toString());
+ if(_endpoints.length > 0)
+ {
+ for(int i = 0; i < _endpoints.length; i++)
+ {
+ String endp = _endpoints[i].toString();
+ if(endp != null && endp.length() > 0)
+ {
+ s.append(':');
+ s.append(endp);
+ }
+ }
+ }
+ else if(_adapterId.length() > 0)
+ {
+ s.append(" @ ");
+
+ //
+ // If the encoded adapter id string contains characters which
+ // the reference parser uses as separators, then we enclose
+ // the adapter id string in quotes.
+ //
+ String a = IceUtilInternal.StringUtil.escapeString(_adapterId, null);
+ if(IceUtilInternal.StringUtil.findFirstOf(a, " \t\n\r") != -1)
+ {
+ s.append('"');
+ s.append(a);
+ s.append('"');
+ }
+ else
+ {
+ s.append(a);
+ }
+ }
+ return s.toString();
+ }
+
public synchronized int
hashCode()
{
- return super.hashCode();
+ if(_hashInitialized)
+ {
+ return _hashValue;
+ }
+ super.hashCode();
+ int sz = _adapterId.length(); // Add hash of adapter ID to base hash.
+ for(int i = 0; i < sz; i++)
+ {
+ _hashValue = 5 * _hashValue + (int)_adapterId.charAt(i);
+ }
+ return _hashValue;
}
public boolean
equals(java.lang.Object obj)
{
- //
- // Note: if(this == obj) and type test are performed by each non-abstract derived class.
- //
+ if(this == obj)
+ {
+ return true;
+ }
+ if(!(obj instanceof RoutableReference))
+ {
+ return false;
+ }
if(!super.equals(obj))
{
return false;
}
RoutableReference rhs = (RoutableReference)obj; // Guaranteed to succeed.
- if(_secure != rhs._secure)
+ if(_locatorInfo == null ? rhs._locatorInfo != null : !_locatorInfo.equals(rhs._locatorInfo))
{
return false;
}
- if(_preferSecure != rhs._preferSecure)
+ if(_routerInfo == null ? rhs._routerInfo != null : !_routerInfo.equals(rhs._routerInfo))
{
return false;
}
- if(_collocationOptimization != rhs._collocationOptimization)
+ if(_collocationOptimized != rhs._collocationOptimized)
{
return false;
}
@@ -197,10 +385,22 @@ public abstract class RoutableReference extends Reference
{
return false;
}
+ if(_preferSecure != rhs._preferSecure)
+ {
+ return false;
+ }
if(_endpointSelection != rhs._endpointSelection)
{
return false;
}
+ if(_threadPerConnection != rhs._threadPerConnection)
+ {
+ return false;
+ }
+ if(_locatorCacheTimeout != rhs._locatorCacheTimeout)
+ {
+ return false;
+ }
if(!_connectionId.equals(rhs._connectionId))
{
return false;
@@ -213,40 +413,240 @@ public abstract class RoutableReference extends Reference
{
return false;
}
- if(_threadPerConnection != rhs._threadPerConnection)
+ if(!java.util.Arrays.equals(_endpoints, rhs._endpoints))
{
return false;
}
-
- return _routerInfo == null ? rhs._routerInfo == null : _routerInfo.equals(rhs._routerInfo);
+ if(!_adapterId.equals(rhs._adapterId))
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public Ice.ConnectionI
+ getConnection(Ice.BooleanHolder comp)
+ {
+ if(_routerInfo != null)
+ {
+ //
+ // If we route, we send everything to the router's client
+ // proxy endpoints.
+ //
+ EndpointI[] endpts = _routerInfo.getClientEndpoints();
+ if(endpts.length > 0)
+ {
+ applyOverrides(endpts);
+ return createConnection(endpts, comp);
+ }
+ }
+
+ if(_endpoints.length > 0)
+ {
+ return createConnection(_endpoints, comp);
+ }
+
+ while(true)
+ {
+ Ice.BooleanHolder cached = new Ice.BooleanHolder(false);
+ EndpointI[] endpts = null;
+ if(_locatorInfo != null)
+ {
+ endpts = _locatorInfo.getEndpoints(this, _locatorCacheTimeout, cached);
+ applyOverrides(endpts);
+ }
+
+ if(endpts == null || endpts.length == 0)
+ {
+ throw new Ice.NoEndpointException(toString());
+ }
+
+ try
+ {
+ return createConnection(endpts, comp);
+ }
+ catch(Ice.NoEndpointException ex)
+ {
+ throw ex; // No need to retry if there's no endpoints.
+ }
+ catch(Ice.LocalException ex)
+ {
+ assert(_locatorInfo != null);
+ _locatorInfo.clearCache(this);
+ if(cached.value)
+ {
+ TraceLevels traceLevels = getInstance().traceLevels();
+ if(traceLevels.retry >= 2)
+ {
+ String s = "connection to cached endpoints failed\n" +
+ "removing endpoints from cache and trying one more time\n" + ex;
+ getInstance().initializationData().logger.trace(traceLevels.retryCat, s);
+ }
+ continue; // Try again if the endpoints were cached.
+ }
+ throw ex;
+ }
+ }
+ }
+
+ public void
+ getConnection(final GetConnectionCallback callback)
+ {
+ if(_routerInfo != null)
+ {
+ //
+ // If we route, we send everything to the router's client
+ // proxy endpoints.
+ //
+ _routerInfo.getClientEndpoints(new RouterInfo.GetClientEndpointsCallback()
+ {
+ public void
+ setEndpoints(EndpointI[] endpts)
+ {
+ if(endpts.length > 0)
+ {
+ applyOverrides(endpts);
+ createConnection(endpts, callback);
+ }
+ else
+ {
+ getConnectionNoRouterInfo(callback);
+ }
+ }
+
+ public void
+ setException(Ice.LocalException ex)
+ {
+ callback.setException(ex);
+ }
+ });
+ }
+ else
+ {
+ getConnectionNoRouterInfo(callback);
+ }
+ }
+
+ public void
+ getConnectionNoRouterInfo(final GetConnectionCallback callback)
+ {
+ if(_endpoints.length > 0)
+ {
+ createConnection(_endpoints, callback);
+ return;
+ }
+
+ final RoutableReference self = this;
+ if(_locatorInfo != null)
+ {
+ _locatorInfo.getEndpoints(this, _locatorCacheTimeout, new LocatorInfo.GetEndpointsCallback()
+ {
+ public void
+ setEndpoints(EndpointI[] endpoints, final boolean cached)
+ {
+ if(endpoints.length == 0)
+ {
+ callback.setException(new Ice.NoEndpointException(self.toString()));
+ return;
+ }
+
+ applyOverrides(endpoints);
+ createConnection(endpoints, new GetConnectionCallback()
+ {
+ public void
+ setConnection(Ice.ConnectionI connection, boolean compress)
+ {
+ callback.setConnection(connection, compress);
+ }
+
+ public void
+ setException(Ice.LocalException exc)
+ {
+ try
+ {
+ throw exc;
+ }
+ catch(Ice.NoEndpointException ex)
+ {
+ callback.setException(ex); // No need to retry if there's no endpoints.
+ }
+ catch(Ice.LocalException ex)
+ {
+ assert(_locatorInfo != null);
+ _locatorInfo.clearCache(self);
+ if(cached)
+ {
+ TraceLevels traceLvls = getInstance().traceLevels();
+ if(traceLvls.retry >= 2)
+ {
+ String s = "connection to cached endpoints failed\n" +
+ "removing endpoints from cache and trying one more time\n" + ex;
+ getInstance().initializationData().logger.trace(traceLvls.retryCat, s);
+ }
+ getConnectionNoRouterInfo(callback); // Retry.
+ return;
+ }
+ callback.setException(ex);
+ }
+ }
+ });
+ }
+
+ public void
+ setException(Ice.LocalException ex)
+ {
+ callback.setException(ex);
+ }
+ });
+ }
+ else
+ {
+ callback.setException(new Ice.NoEndpointException(toString()));
+ }
}
protected
- RoutableReference(Instance inst,
- Ice.Communicator com,
- Ice.Identity ident,
- java.util.Map ctx,
- String fac,
- int md,
- boolean sec,
- boolean prefSec,
- RouterInfo rtrInfo,
- boolean collocationOpt,
+ RoutableReference(Instance instance,
+ Ice.Communicator communicator,
+ Ice.Identity identity,
+ java.util.Map context,
+ String facet,
+ int mode,
+ boolean secure,
+ EndpointI[] endpoints,
+ String adapterId,
+ LocatorInfo locatorInfo,
+ RouterInfo routerInfo,
+ boolean collocationOptimized,
boolean cacheConnection,
+ boolean prefereSecure,
Ice.EndpointSelectionType endpointSelection,
- boolean threadPerConnection)
+ boolean threadPerConnection,
+ int locatorCacheTimeout)
{
- super(inst, com, ident, ctx, fac, md);
- _secure = sec;
- _preferSecure = prefSec;
- _routerInfo = rtrInfo;
- _collocationOptimization = collocationOpt;
+ super(instance, communicator, identity, context, facet, mode, secure);
+ _endpoints = endpoints;
+ _adapterId = adapterId;
+ _locatorInfo = locatorInfo;
+ _routerInfo = routerInfo;
+ _collocationOptimized = collocationOptimized;
_cacheConnection = cacheConnection;
+ _preferSecure = prefereSecure;
_endpointSelection = endpointSelection;
- _overrideCompress = false;
+ _threadPerConnection = threadPerConnection;
+ _locatorCacheTimeout = locatorCacheTimeout;
_overrideTimeout = false;
_timeout = -1;
- _threadPerConnection = threadPerConnection;
+
+ if(_endpoints == null)
+ {
+ _endpoints = _emptyEndpoints;
+ }
+ if(_adapterId == null)
+ {
+ _adapterId = "";
+ }
+ assert(_adapterId.length() == 0 || _endpoints.length == 0);
}
protected void
@@ -598,15 +998,20 @@ public abstract class RoutableReference extends Reference
private static EndpointComparator _preferNonSecureEndpointComparator = new EndpointComparator(false);
private static EndpointComparator _preferSecureEndpointComparator = new EndpointComparator(true);
+ private static EndpointI[] _emptyEndpoints = new EndpointI[0];
- private boolean _secure;
- private boolean _preferSecure;
+ private EndpointI[] _endpoints;
+ private String _adapterId;
+ private LocatorInfo _locatorInfo; // Null if no router is used.
private RouterInfo _routerInfo; // Null if no router is used.
- private boolean _collocationOptimization;
+ private boolean _collocationOptimized;
private boolean _cacheConnection;
+ private boolean _preferSecure;
private Ice.EndpointSelectionType _endpointSelection;
- private String _connectionId = "";
+ private boolean _threadPerConnection;
+ private int _locatorCacheTimeout;
+
private boolean _overrideTimeout;
private int _timeout; // Only used if _overrideTimeout == true
- private boolean _threadPerConnection;
+ private String _connectionId = "";
}