summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/RoutableReference.java
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2006-02-14 12:06:57 +0000
committerBenoit Foucher <benoit@zeroc.com>2006-02-14 12:06:57 +0000
commit770b66fc97582743bf045f709feac5c468c9d06d (patch)
treede6f5b22ed6c5a22d072337a647c9d3ac626eaa1 /java/src/IceInternal/RoutableReference.java
parentFixed another race condition in the activator test suite. (diff)
downloadice-770b66fc97582743bf045f709feac5c468c9d06d.tar.bz2
ice-770b66fc97582743bf045f709feac5c468c9d06d.tar.xz
ice-770b66fc97582743bf045f709feac5c468c9d06d.zip
- Added ice_cacheConnection, ice_endpointSelection
- Fixed a bug where connection.close(true) would print a connection warning. - Fixed a bug where ice_newEndpoints would throw a ClassCastException - Added test/Ice/binding test suite.
Diffstat (limited to 'java/src/IceInternal/RoutableReference.java')
-rw-r--r--java/src/IceInternal/RoutableReference.java175
1 files changed, 175 insertions, 0 deletions
diff --git a/java/src/IceInternal/RoutableReference.java b/java/src/IceInternal/RoutableReference.java
index 00dbec6508a..f515adaeb7b 100644
--- a/java/src/IceInternal/RoutableReference.java
+++ b/java/src/IceInternal/RoutableReference.java
@@ -121,6 +121,181 @@ public abstract class RoutableReference extends Reference
_collocationOptimization = collocationOpt;
}
+ protected Ice.ConnectionI
+ createConnection(EndpointI[] allEndpoints, Ice.BooleanHolder compress)
+ {
+ java.util.ArrayList endpoints = new java.util.ArrayList();
+
+ //
+ // Filter out unknown endpoints.
+ //
+ for(int i = 0; i < allEndpoints.length; i++)
+ {
+ if(!allEndpoints[i].unknown())
+ {
+ endpoints.add(allEndpoints[i]);
+ }
+ }
+
+ //
+ // Filter out endpoints according to the mode of the reference.
+ //
+ switch(getMode())
+ {
+ case Reference.ModeTwoway:
+ case Reference.ModeOneway:
+ case Reference.ModeBatchOneway:
+ {
+ //
+ // Filter out datagram endpoints.
+ //
+ java.util.Iterator i = endpoints.iterator();
+ while(i.hasNext())
+ {
+ EndpointI endpoint = (EndpointI)i.next();
+ if(endpoint.datagram())
+ {
+ i.remove();
+ }
+ }
+ break;
+ }
+
+ case Reference.ModeDatagram:
+ case Reference.ModeBatchDatagram:
+ {
+ //
+ // Filter out non-datagram endpoints.
+ //
+ java.util.Iterator i = endpoints.iterator();
+ while(i.hasNext())
+ {
+ EndpointI endpoint = (EndpointI)i.next();
+ if(!endpoint.datagram())
+ {
+ i.remove();
+ }
+ }
+ break;
+ }
+ }
+
+ //
+ // Sort the endpoints according to the endpoint selection type.
+ //
+ switch(getEndpointSelection().value())
+ {
+ case Ice.EndpointSelectionType._Random:
+ java.util.Collections.shuffle(endpoints);
+ break;
+ case Ice.EndpointSelectionType._Ordered:
+ // Nothing to do.
+ break;
+ default:
+ assert(false);
+ break;
+ }
+
+ //
+ // If a secure connection is requested, 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.
+ //
+ if(getSecure())
+ {
+ java.util.Iterator i = endpoints.iterator();
+ while(i.hasNext())
+ {
+ EndpointI endpoint = (EndpointI)i.next();
+ if(!endpoint.secure())
+ {
+ i.remove();
+ }
+ }
+ }
+ else
+ {
+ java.util.Collections.sort(endpoints, _endpointComparator);
+ }
+
+ if(endpoints.size() == 0)
+ {
+ Ice.NoEndpointException ex = new Ice.NoEndpointException();
+ ex.proxy = toString();
+ throw ex;
+ }
+
+ //
+ // Finally, create the connection.
+ //
+ OutgoingConnectionFactory factory = getInstance().outgoingConnectionFactory();
+ if(getCacheConnection() || endpoints.size() == 1)
+ {
+ //
+ // Get an existing connection or create one if there's no
+ // existing connection to one of the given endpoints.
+ //
+ return factory.create((EndpointI[])endpoints.toArray(new EndpointI[endpoints.size()]), false, compress);
+ }
+ else
+ {
+ //
+ // Go through the list of endpoints and try to create the
+ // connection until it succeeds. This is different from just
+ // calling create() with the given endpoints since this might
+ // create a new connection even if there's an existing
+ // connection for one of the endpoints.
+ //
+
+ Ice.LocalException exception = null;
+ EndpointI[] endpoint = new EndpointI[1];
+
+ java.util.Iterator i = endpoints.iterator();
+ while(i.hasNext())
+ {
+ try
+ {
+ endpoint[0] = (EndpointI)i.next();
+ return factory.create(endpoint, i.hasNext(), compress);
+ }
+ catch(Ice.LocalException ex)
+ {
+ exception = ex;
+ }
+ }
+
+ assert(exception != null);
+ throw exception;
+ }
+ }
+
+ static class EndpointComparator implements java.util.Comparator
+ {
+ public int
+ compare(java.lang.Object l, java.lang.Object r)
+ {
+ IceInternal.EndpointI le = (IceInternal.EndpointI)l;
+ IceInternal.EndpointI re = (IceInternal.EndpointI)r;
+ boolean ls = le.secure();
+ boolean rs = re.secure();
+ if((ls && rs) || (!ls && !rs))
+ {
+ return 0;
+ }
+ else if(!ls && rs)
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ }
+
+ private static EndpointComparator _endpointComparator = new EndpointComparator();
+
private boolean _secure;
private RouterInfo _routerInfo; // Null if no router is used.
private boolean _collocationOptimization;