diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2007-05-18 13:34:42 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2007-05-18 13:34:42 +0000 |
commit | 3f53f8f12436f8c731a11cbb78738d34037d2dac (patch) | |
tree | b14241e46b8877c5b7db79149ebfee21e9906f4e | |
parent | Multi-home host support (diff) | |
download | ice-3f53f8f12436f8c731a11cbb78738d34037d2dac.tar.bz2 ice-3f53f8f12436f8c731a11cbb78738d34037d2dac.tar.xz ice-3f53f8f12436f8c731a11cbb78738d34037d2dac.zip |
Multi-home post support
-rw-r--r-- | java/CHANGES | 4 | ||||
-rw-r--r-- | java/src/IceInternal/EndpointI.java | 10 | ||||
-rw-r--r-- | java/src/IceInternal/Network.java | 35 | ||||
-rw-r--r-- | java/src/IceInternal/OutgoingConnectionFactory.java | 85 | ||||
-rw-r--r-- | java/src/IceInternal/RoutableReference.java | 5 | ||||
-rw-r--r-- | java/src/IceInternal/TcpEndpointI.java | 32 | ||||
-rw-r--r-- | java/src/IceInternal/UdpEndpointI.java | 32 | ||||
-rw-r--r-- | java/src/IceInternal/UnknownEndpointI.java | 18 | ||||
-rw-r--r-- | java/ssl/jdk1.4/IceSSL/EndpointI.java | 32 | ||||
-rw-r--r-- | java/ssl/jdk1.5/IceSSL/EndpointI.java | 32 |
10 files changed, 212 insertions, 73 deletions
diff --git a/java/CHANGES b/java/CHANGES index 9bf9a68d4a4..f65ebf02605 100644 --- a/java/CHANGES +++ b/java/CHANGES @@ -1,6 +1,10 @@ Changes since version 3.2.X (binary incompabible) ------------------------------------------------- +- If a proxy contains a host which is multihomed, the client will now + try all the available ip addresses. Previously, only the first in the + address list returned by the DNS was used and others were ignored. + - Fixed a bug in IceSSL for JDK 1.5 that could cause a hang during the SSL handshake. diff --git a/java/src/IceInternal/EndpointI.java b/java/src/IceInternal/EndpointI.java index 8b8ac0528bb..f20208d8b44 100644 --- a/java/src/IceInternal/EndpointI.java +++ b/java/src/IceInternal/EndpointI.java @@ -87,10 +87,10 @@ abstract public class EndpointI implements Ice.Endpoint, java.lang.Comparable public abstract boolean unknown(); // - // Return a client side transceiver for this endpoint, or null if a - // transceiver can only be created by a connector. + // Return client side transceivers for this endpoint, or empty list + // if a transceiver can only be created by a connector. // - public abstract Transceiver clientTransceiver(); + public abstract java.util.ArrayList clientTransceivers(); // // Return a server side transceiver for this endpoint, or null if a @@ -102,10 +102,10 @@ abstract public class EndpointI implements Ice.Endpoint, java.lang.Comparable public abstract Transceiver serverTransceiver(EndpointIHolder endpoint); // - // Return a connector for this endpoint, or null if no connector + // Return connectors for this endpoint, or empty list if no connector // is available. // - public abstract Connector connector(); + public abstract java.util.ArrayList connectors(); // // Return an acceptor for this endpoint, or null if no acceptors diff --git a/java/src/IceInternal/Network.java b/java/src/IceInternal/Network.java index 92a1547d234..cfa52fa0e4c 100644 --- a/java/src/IceInternal/Network.java +++ b/java/src/IceInternal/Network.java @@ -654,6 +654,41 @@ public final class Network } public static java.util.ArrayList + getHosts(String host) + { + java.util.ArrayList hosts = new java.util.ArrayList(); + try + { + java.net.InetAddress[] addrs = java.net.InetAddress.getAllByName(host); + for(int i = 0; i < addrs.length; ++i) + { + if(addrs[i] instanceof java.net.Inet4Address) + { + hosts.add(addrs[i].getHostAddress()); + } + } + } + catch(java.net.UnknownHostException ex) + { + Ice.DNSException e = new Ice.DNSException(); + e.host = host; + throw e; + } + + // + // No Inet4Address available. + // + if(hosts.size() == 0) + { + Ice.DNSException e = new Ice.DNSException(); + e.host = host; + throw e; + } + + return hosts; + } + + public static java.util.ArrayList getLocalHosts() { java.util.ArrayList hosts = new java.util.ArrayList(); diff --git a/java/src/IceInternal/OutgoingConnectionFactory.java b/java/src/IceInternal/OutgoingConnectionFactory.java index 8e64eb846e6..93d6e032232 100644 --- a/java/src/IceInternal/OutgoingConnectionFactory.java +++ b/java/src/IceInternal/OutgoingConnectionFactory.java @@ -91,7 +91,8 @@ public final class OutgoingConnectionFactory } public Ice.ConnectionI - create(EndpointI[] endpts, boolean hasMore, boolean threadPerConnection, Ice.BooleanHolder compress) + create(EndpointI[] endpts, boolean hasMore, boolean threadPerConnection, Ice.EndpointSelectionType selType, + Ice.BooleanHolder compress) { assert(endpts.length > 0); EndpointI[] endpoints = new EndpointI[endpts.length]; @@ -301,13 +302,22 @@ public final class OutgoingConnectionFactory try { - Transceiver transceiver = endpoint.clientTransceiver(); - if(transceiver == null) + java.util.ArrayList connectors = null; + int size; + int timeout = -1; + + java.util.ArrayList transceivers = endpoint.clientTransceivers(); + if(transceivers.size() == 0) { - Connector connector = endpoint.connector(); - assert(connector != null); + connectors = endpoint.connectors(); + size = connectors.size(); + assert(size > 0); + + if(selType == Ice.EndpointSelectionType.Random) + { + java.util.Collections.shuffle(connectors); + } - int timeout; if(defaultsAndOverrides.overrideConnectTimeout) { timeout = defaultsAndOverrides.overrideConnectTimeoutValue; @@ -319,13 +329,56 @@ public final class OutgoingConnectionFactory { timeout = endpoint.timeout(); } + } + else + { + size = transceivers.size(); + if(selType == Ice.EndpointSelectionType.Random) + { + java.util.Collections.shuffle(transceivers); + } + } + + for(int j = 0; j < size; ++j) + { + try + { + Transceiver transceiver; + if(transceivers.size() == size) + { + transceiver = (Transceiver)transceivers.get(j); + } + else + { + transceiver = ((Connector)connectors.get(j)).connect(timeout); + assert(transceiver != null); + } + + connection = new Ice.ConnectionI(_instance, transceiver, endpoint, null, threadPerConnection); + connection.start(); + connection.validate(); + } + catch(Ice.LocalException ex) + { + // + // If a connection object was constructed, then validate() + // must have raised the exception. + // + if(connection != null) + { + connection.waitUntilFinished(); // We must call waitUntilFinished() for cleanup. + connection = null; + } - transceiver = connector.connect(timeout); - assert(transceiver != null); + // + // Throw exception if this is last transceiver in list. + // + if(j == size - 1) + { + throw ex; + } + } } - connection = new Ice.ConnectionI(_instance, transceiver, endpoint, null, threadPerConnection); - connection.start(); - connection.validate(); if(defaultsAndOverrides.overrideCompress) { @@ -340,16 +393,6 @@ public final class OutgoingConnectionFactory catch(Ice.LocalException ex) { exception = ex; - - // - // If a connection object was constructed, then validate() - // must have raised the exception. - // - if(connection != null) - { - connection.waitUntilFinished(); // We must call waitUntilFinished() for cleanup. - connection = null; - } } TraceLevels traceLevels = _instance.traceLevels(); diff --git a/java/src/IceInternal/RoutableReference.java b/java/src/IceInternal/RoutableReference.java index 4c3a4b5bc7f..f04c30eb86c 100644 --- a/java/src/IceInternal/RoutableReference.java +++ b/java/src/IceInternal/RoutableReference.java @@ -431,7 +431,7 @@ public abstract class RoutableReference extends Reference // existing connection to one of the given endpoints. // return factory.create((EndpointI[])endpoints.toArray( - new EndpointI[endpoints.size()]), false, _threadPerConnection, compress); + new EndpointI[endpoints.size()]), false, _threadPerConnection, getEndpointSelection(), compress); } else { @@ -452,7 +452,8 @@ public abstract class RoutableReference extends Reference try { endpoint[0] = (EndpointI)i.next(); - return factory.create(endpoint, i.hasNext(), _threadPerConnection, compress); + return factory.create(endpoint, i.hasNext(), _threadPerConnection, getEndpointSelection(), + compress); } catch(Ice.LocalException ex) { diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java index 21eb90d067c..80a455eb0c7 100644 --- a/java/src/IceInternal/TcpEndpointI.java +++ b/java/src/IceInternal/TcpEndpointI.java @@ -297,13 +297,13 @@ final class TcpEndpointI extends EndpointI } // - // Return a client side transceiver for this endpoint, or null if a - // transceiver can only be created by a connector. + // Return client side transceivers for this endpoint, or empty list + // if a transceiver can only be created by a connector. // - public Transceiver - clientTransceiver() + public java.util.ArrayList + clientTransceivers() { - return null; + return new java.util.ArrayList(); } // @@ -321,13 +321,27 @@ final class TcpEndpointI extends EndpointI } // - // Return a connector for this endpoint, or null if no connector + // Return connectors for this endpoint, or empty list if no connector // is available. // - public Connector - connector() + public java.util.ArrayList + connectors() { - return new TcpConnector(_instance, _host, _port); + java.util.ArrayList connectors = new java.util.ArrayList(); + java.util.ArrayList hosts = Network.getHosts(_host); + if(hosts.size() > 0) + { + java.util.Iterator p = hosts.iterator(); + while(p.hasNext()) + { + connectors.add(new TcpConnector(_instance, (String)p.next(), _port)); + } + } + else + { + connectors.add(new TcpConnector(_instance, _host, _port)); + } + return connectors; } // diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java index 6207a0499b8..672cb5b5a3d 100644 --- a/java/src/IceInternal/UdpEndpointI.java +++ b/java/src/IceInternal/UdpEndpointI.java @@ -432,13 +432,27 @@ final class UdpEndpointI extends EndpointI } // - // Return a client side transceiver for this endpoint, or null if a - // transceiver can only be created by a connector. + // Return client side transceivers for this endpoint, or empty list + // if a transceiver can only be created by a connector. // - public Transceiver - clientTransceiver() + public java.util.ArrayList + clientTransceivers() { - return new UdpTransceiver(_instance, _host, _port); + java.util.ArrayList transceivers = new java.util.ArrayList(); + java.util.ArrayList hosts = Network.getHosts(_host); + if(hosts.size() > 0) + { + java.util.Iterator p = hosts.iterator(); + while(p.hasNext()) + { + transceivers.add(new UdpTransceiver(_instance, (String)p.next(), _port)); + } + } + else + { + transceivers.add(new UdpTransceiver(_instance, _host, _port)); + } + return transceivers; } // @@ -458,13 +472,13 @@ final class UdpEndpointI extends EndpointI } // - // Return a connector for this endpoint, or null if no connector + // Return connectors for this endpoint, or empty list if no connector // is available. // - public Connector - connector() + public java.util.ArrayList + connectors() { - return null; + return new java.util.ArrayList(); } // diff --git a/java/src/IceInternal/UnknownEndpointI.java b/java/src/IceInternal/UnknownEndpointI.java index 3c5fc415a32..300da7a056f 100644 --- a/java/src/IceInternal/UnknownEndpointI.java +++ b/java/src/IceInternal/UnknownEndpointI.java @@ -220,13 +220,13 @@ final class UnknownEndpointI extends EndpointI } // - // Return a client side transceiver for this endpoint, or null if a - // transceiver can only be created by a connector. + // Return client side transceivers for this endpoint, or empty list + // if a transceiver can only be created by a connector. // - public Transceiver - clientTransceiver() + public java.util.ArrayList + clientTransceivers() { - return null; + return new java.util.ArrayList(); } // @@ -244,13 +244,13 @@ final class UnknownEndpointI extends EndpointI } // - // Return a connector for this endpoint, or null if no connector + // Return connectors for this endpoint, or empty list if no connector // is available. // - public Connector - connector() + public java.util.ArrayList + connectors() { - return null; + return new java.util.ArrayList(); } // diff --git a/java/ssl/jdk1.4/IceSSL/EndpointI.java b/java/ssl/jdk1.4/IceSSL/EndpointI.java index 40c51386679..c4ba4c26664 100644 --- a/java/ssl/jdk1.4/IceSSL/EndpointI.java +++ b/java/ssl/jdk1.4/IceSSL/EndpointI.java @@ -297,13 +297,13 @@ final class EndpointI extends IceInternal.EndpointI } // - // Return a client side transceiver for this endpoint, or null if a - // transceiver can only be created by a connector. + // Return client side transceivers for this endpoint, or empty list + // if a transceiver can only be created by a connector. // - public IceInternal.Transceiver - clientTransceiver() + public java.util.ArrayList + clientTransceivers() { - return null; + return new java.util.ArrayList(); } // @@ -321,13 +321,27 @@ final class EndpointI extends IceInternal.EndpointI } // - // Return a connector for this endpoint, or null if no connector + // Return connectors for this endpoint, or empty list if no connector // is available. // - public IceInternal.Connector - connector() + public java.util.ArrayList + connectors() { - return new ConnectorI(_instance, _host, _port); + java.util.ArrayList connectors = new java.util.ArrayList(); + java.util.ArrayList hosts = IceInternal.Network.getHosts(_host); + if(hosts.size() > 0) + { + java.util.Iterator p = hosts.iterator(); + while(p.hasNext()) + { + connectors.add(new ConnectorI(_instance, (String)p.next(), _port)); + } + } + else + { + connectors.add(new ConnectorI(_instance, _host, _port)); + } + return connectors; } // diff --git a/java/ssl/jdk1.5/IceSSL/EndpointI.java b/java/ssl/jdk1.5/IceSSL/EndpointI.java index fb640240eff..8689845887c 100644 --- a/java/ssl/jdk1.5/IceSSL/EndpointI.java +++ b/java/ssl/jdk1.5/IceSSL/EndpointI.java @@ -297,13 +297,13 @@ final class EndpointI extends IceInternal.EndpointI } // - // Return a client side transceiver for this endpoint, or null if a - // transceiver can only be created by a connector. + // Return client side transceivers for this endpoint, or empty list + // if a transceiver can only be created by a connector. // - public IceInternal.Transceiver - clientTransceiver() + public java.util.ArrayList + clientTransceivers() { - return null; + return new java.util.ArrayList(); } // @@ -321,13 +321,27 @@ final class EndpointI extends IceInternal.EndpointI } // - // Return a connector for this endpoint, or null if no connector + // Return connectors for this endpoint, or empty list if no connector // is available. // - public IceInternal.Connector - connector() + public java.util.ArrayList + connectors() { - return new ConnectorI(_instance, _host, _port); + java.util.ArrayList connectors = new java.util.ArrayList(); + java.util.ArrayList hosts = IceInternal.Network.getHosts(_host); + if(hosts.size() > 0) + { + java.util.Iterator p = hosts.iterator(); + while(p.hasNext()) + { + connectors.add(new ConnectorI(_instance, (String)p.next(), _port)); + } + } + else + { + connectors.add(new ConnectorI(_instance, _host, _port)); + } + return connectors; } // |