diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2007-06-07 17:01:30 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2007-06-07 17:01:30 +0000 |
commit | a737fcdae3a825d1a3df353a08df3c12285cde43 (patch) | |
tree | ce5c2f7aed6194cb4d94cb07e00b7380bc320e7b /java | |
parent | Added missing IComparable (diff) | |
download | ice-a737fcdae3a825d1a3df353a08df3c12285cde43.tar.bz2 ice-a737fcdae3a825d1a3df353a08df3c12285cde43.tar.xz ice-a737fcdae3a825d1a3df353a08df3c12285cde43.zip |
More changes for bug 1996
Diffstat (limited to 'java')
-rw-r--r-- | java/src/IceInternal/Connector.java | 7 | ||||
-rw-r--r-- | java/src/IceInternal/EndpointI.java | 8 | ||||
-rw-r--r-- | java/src/IceInternal/IncomingConnectionFactory.java | 2 | ||||
-rw-r--r-- | java/src/IceInternal/Network.java | 30 | ||||
-rw-r--r-- | java/src/IceInternal/OutgoingConnectionFactory.java | 243 | ||||
-rw-r--r-- | java/src/IceInternal/TcpConnector.java | 90 | ||||
-rw-r--r-- | java/src/IceInternal/TcpEndpointI.java | 76 | ||||
-rw-r--r-- | java/src/IceInternal/UdpConnector.java | 172 | ||||
-rw-r--r-- | java/src/IceInternal/UdpEndpointI.java | 93 | ||||
-rw-r--r-- | java/src/IceInternal/UnknownEndpointI.java | 14 | ||||
-rw-r--r-- | java/ssl/jdk1.4/IceSSL/ConnectorI.java | 91 | ||||
-rw-r--r-- | java/ssl/jdk1.4/IceSSL/EndpointI.java | 76 | ||||
-rw-r--r-- | java/ssl/jdk1.5/IceSSL/ConnectorI.java | 90 | ||||
-rw-r--r-- | java/ssl/jdk1.5/IceSSL/EndpointI.java | 76 |
14 files changed, 656 insertions, 412 deletions
diff --git a/java/src/IceInternal/Connector.java b/java/src/IceInternal/Connector.java index cb11ec23fcb..7e4c5d16f37 100644 --- a/java/src/IceInternal/Connector.java +++ b/java/src/IceInternal/Connector.java @@ -12,5 +12,12 @@ package IceInternal; public interface Connector { Transceiver connect(int timeout); + short type(); String toString(); + + // + // Compare connectors for sorting process. + // + boolean equals(java.lang.Object obj); + int compareTo(java.lang.Object obj); // From java.lang.Comparable. } diff --git a/java/src/IceInternal/EndpointI.java b/java/src/IceInternal/EndpointI.java index 1781db8a5ea..92924847234 100644 --- a/java/src/IceInternal/EndpointI.java +++ b/java/src/IceInternal/EndpointI.java @@ -87,19 +87,13 @@ abstract public class EndpointI implements Ice.Endpoint, java.lang.Comparable public abstract boolean unknown(); // - // Return client side transceivers for this endpoint, or empty list - // if a transceiver can only be created by a connector. - // - public abstract java.util.ArrayList clientTransceivers(); - - // // Return a server side transceiver for this endpoint, or null if a // transceiver can only be created by an acceptor. In case a // transceiver is created, this operation also returns a new // "effective" endpoint, which might differ from this endpoint, // for example, if a dynamic port number is assigned. // - public abstract Transceiver serverTransceiver(EndpointIHolder endpoint); + public abstract Transceiver transceiver(EndpointIHolder endpoint); // // Return connectors for this endpoint, or empty list if no connector diff --git a/java/src/IceInternal/IncomingConnectionFactory.java b/java/src/IceInternal/IncomingConnectionFactory.java index 09d992523a7..fb977f5d175 100644 --- a/java/src/IceInternal/IncomingConnectionFactory.java +++ b/java/src/IceInternal/IncomingConnectionFactory.java @@ -391,7 +391,7 @@ public final class IncomingConnectionFactory extends EventHandler { EndpointIHolder h = new EndpointIHolder(); h.value = _endpoint; - _transceiver = _endpoint.serverTransceiver(h); + _transceiver = _endpoint.transceiver(h); if(_transceiver != null) { diff --git a/java/src/IceInternal/Network.java b/java/src/IceInternal/Network.java index b23d1dda5d2..57e2b5b6867 100644 --- a/java/src/IceInternal/Network.java +++ b/java/src/IceInternal/Network.java @@ -703,6 +703,36 @@ public final class Network throw e; } + public static int + compareAddress(java.net.InetSocketAddress addr1, java.net.InetSocketAddress addr2) + { + if(addr1.getPort() < addr2.getPort()) + { + return -1; + } + else if(addr2.getPort() < addr1.getPort()) + { + return 1; + } + + byte[] larr = addr1.getAddress().getAddress(); + byte[] rarr = addr2.getAddress().getAddress(); + assert(larr.length == rarr.length); + for(int i = 0; i < larr.length; i++) + { + if(larr[i] < rarr[i]) + { + return -1; + } + else if(rarr[i] < larr[i]) + { + return 1; + } + } + + return 0; + } + public static java.net.InetAddress getLocalAddress() { diff --git a/java/src/IceInternal/OutgoingConnectionFactory.java b/java/src/IceInternal/OutgoingConnectionFactory.java index 93d6e032232..ffec338dd83 100644 --- a/java/src/IceInternal/OutgoingConnectionFactory.java +++ b/java/src/IceInternal/OutgoingConnectionFactory.java @@ -11,6 +11,7 @@ package IceInternal; public final class OutgoingConnectionFactory { + public synchronized void destroy() { @@ -94,9 +95,20 @@ public final class OutgoingConnectionFactory create(EndpointI[] endpts, boolean hasMore, boolean threadPerConnection, Ice.EndpointSelectionType selType, Ice.BooleanHolder compress) { + class ConnectorEndpointPair + { + public ConnectorEndpointPair(Connector c, EndpointI e) + { + connector = c; + endpoint = e; + } + + public Connector connector; + public EndpointI endpoint; + } + assert(endpts.length > 0); - EndpointI[] endpoints = new EndpointI[endpts.length]; - System.arraycopy(endpts, 0, endpoints, 0, endpts.length); + java.util.ArrayList connectors = new java.util.ArrayList(); DefaultsAndOverrides defaultsAndOverrides = _instance.defaultsAndOverrides(); @@ -110,12 +122,12 @@ public final class OutgoingConnectionFactory // // TODO: Remove when we no longer support SSL for JDK 1.4. // - for(int i = 0; i < endpoints.length; i++) + for(int i = 0; i < endpts.length; i++) { - if(!threadPerConnection && endpoints[i].requiresThreadPerConnection()) + if(!threadPerConnection && endpts[i].requiresThreadPerConnection()) { Ice.FeatureNotSupportedException ex = new Ice.FeatureNotSupportedException(); - ex.unsupportedFeature = "endpoint requires thread-per-connection:\n" + endpoints[i].toString(); + ex.unsupportedFeature = "endpoint requires thread-per-connection:\n" + endpts[i].toString(); throw ex; } } @@ -144,34 +156,50 @@ public final class OutgoingConnectionFactory } } - // - // Modify endpoints with overrides. - // + EndpointI[] endpoints = new EndpointI[endpts.length]; + System.arraycopy(endpts, 0, endpoints, 0, endpts.length); for(int i = 0; i < endpoints.length; i++) { + // + // Modify endpoints with overrides. + // if(defaultsAndOverrides.overrideTimeout) { endpoints[i] = endpoints[i].timeout(defaultsAndOverrides.overrideTimeoutValue); } // - // The Connection object does not take the compression flag of - // endpoints into account, but instead gets the information - // about whether messages should be compressed or not from - // other sources. In order to allow connection sharing for - // endpoints that differ in the value of the compression flag - // only, we always set the compression flag to false here in - // this connection factory. + // Create connectors for the endpoint. + // + java.util.ArrayList cons = endpoints[i].connectors(); + assert(cons.size() > 0); + + // + // Shuffle connectors is endpoint selection type is Random. // - endpoints[i] = endpoints[i].compress(false); + if(selType == Ice.EndpointSelectionType.Random) + { + java.util.Collections.shuffle(cons); + } + + p = cons.iterator(); + while(p.hasNext()) + { + connectors.add(new ConnectorEndpointPair((Connector)p.next(), endpoints[i])); + } + } // // Search for existing connections. // - for(int i = 0; i < endpoints.length; i++) + p = connectors.iterator(); + while(p.hasNext()) { - java.util.LinkedList connectionList = (java.util.LinkedList)_connections.get(endpoints[i]); + ConnectorEndpointPair cep = (ConnectorEndpointPair)p.next(); + + + java.util.LinkedList connectionList = (java.util.LinkedList)_connections.get(cep.connector); if(connectionList != null) { java.util.Iterator q = connectionList.iterator(); @@ -193,7 +221,7 @@ public final class OutgoingConnectionFactory } else { - compress.value = endpts[i].compress(); + compress.value = cep.endpoint.compress(); } return connection; @@ -210,16 +238,19 @@ public final class OutgoingConnectionFactory boolean searchAgain = false; while(!_destroyed) { - int i; - for(i = 0; i < endpoints.length; i++) + boolean found = false; + p = connectors.iterator(); + while(p.hasNext()) { - if(_pending.contains(endpoints[i])) - { + ConnectorEndpointPair cep = (ConnectorEndpointPair)p.next(); + if(_pending.contains(cep.connector)) + { + found = true; break; } } - if(i == endpoints.length) + if(!found) { break; } @@ -247,9 +278,12 @@ public final class OutgoingConnectionFactory // if(searchAgain) { - for(int i = 0; i < endpoints.length; i++) + p = connectors.iterator(); + while(p.hasNext()) { - java.util.LinkedList connectionList = (java.util.LinkedList)_connections.get(endpoints[i]); + ConnectorEndpointPair cep = (ConnectorEndpointPair)p.next(); + + java.util.LinkedList connectionList = (java.util.LinkedList)_connections.get(cep.connector); if(connectionList != null) { java.util.Iterator q = connectionList.iterator(); @@ -271,7 +305,7 @@ public final class OutgoingConnectionFactory } else { - compress.value = endpts[i].compress(); + compress.value = cep.endpoint.compress(); } return connection; @@ -287,98 +321,47 @@ public final class OutgoingConnectionFactory // to create connections to the same endpoints, we add our // endpoints to _pending. // - for(int i = 0; i < endpoints.length; i++) + p = connectors.iterator(); + while(p.hasNext()) { - _pending.add(endpoints[i]); + ConnectorEndpointPair cep = (ConnectorEndpointPair)p.next(); + _pending.add(cep.connector); } } + Connector connector = null; Ice.ConnectionI connection = null; Ice.LocalException exception = null; - for(int i = 0; i < endpoints.length; i++) + java.util.Iterator p = connectors.iterator(); + while(p.hasNext()) { - EndpointI endpoint = endpoints[i]; + ConnectorEndpointPair cep = (ConnectorEndpointPair)p.next(); + connector = cep.connector; + EndpointI endpoint = cep.endpoint; try { - java.util.ArrayList connectors = null; - int size; - int timeout = -1; - - java.util.ArrayList transceivers = endpoint.clientTransceivers(); - if(transceivers.size() == 0) + int timeout; + if(defaultsAndOverrides.overrideConnectTimeout) { - connectors = endpoint.connectors(); - size = connectors.size(); - assert(size > 0); - - if(selType == Ice.EndpointSelectionType.Random) - { - java.util.Collections.shuffle(connectors); - } - - if(defaultsAndOverrides.overrideConnectTimeout) - { - timeout = defaultsAndOverrides.overrideConnectTimeoutValue; - } - // It is not necessary to check for overrideTimeout, - // the endpoint has already been modified with this - // override, if set. - else - { - timeout = endpoint.timeout(); - } + timeout = defaultsAndOverrides.overrideConnectTimeoutValue; } + // It is not necessary to check for overrideTimeout, + // the endpoint has already been modified with this + // override, if set. else { - size = transceivers.size(); - if(selType == Ice.EndpointSelectionType.Random) - { - java.util.Collections.shuffle(transceivers); - } + timeout = endpoint.timeout(); } - 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; - } - - // - // Throw exception if this is last transceiver in list. - // - if(j == size - 1) - { - throw ex; - } - } - } + Transceiver transceiver = connector.connect(timeout); + assert(transceiver != null); + + connection = + new Ice.ConnectionI(_instance, transceiver, endpoint.compress(false), null, threadPerConnection); + connection.start(); + connection.validate(); if(defaultsAndOverrides.overrideCompress) { @@ -386,13 +369,23 @@ public final class OutgoingConnectionFactory } else { - compress.value = endpts[i].compress(); + compress.value = endpoint.compress(); } break; } 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(); @@ -400,7 +393,7 @@ public final class OutgoingConnectionFactory { StringBuffer s = new StringBuffer(); s.append("connection to endpoint failed"); - if(hasMore || i < endpoints.length - 1) + if(hasMore || p.hasNext()) { s.append(", trying next endpoint\n"); } @@ -419,9 +412,11 @@ public final class OutgoingConnectionFactory // Signal other threads that we are done with trying to // establish connections to our endpoints. // - for(int i = 0; i < endpoints.length; i++) + p = connectors.iterator(); + while(p.hasNext()) { - _pending.remove(endpoints[i]); + ConnectorEndpointPair cep = (ConnectorEndpointPair)p.next(); + _pending.remove(cep.connector); } notifyAll(); @@ -432,11 +427,11 @@ public final class OutgoingConnectionFactory } else { - java.util.LinkedList connectionList = (java.util.LinkedList)_connections.get(connection.endpoint()); + java.util.LinkedList connectionList = (java.util.LinkedList)_connections.get(connector); if(connectionList == null) { connectionList = new java.util.LinkedList(); - _connections.put(connection.endpoint(), connectionList); + _connections.put(connector, connectionList); } connectionList.add(connection); @@ -498,23 +493,27 @@ public final class OutgoingConnectionFactory // endpoint = endpoint.compress(false); - java.util.LinkedList connectionList = (java.util.LinkedList)_connections.get(endpoints[i]); - if(connectionList != null) + java.util.Iterator p = _connections.values().iterator(); + while(p.hasNext()) { - java.util.Iterator p = connectionList.iterator(); - - while(p.hasNext()) + java.util.LinkedList connectionList = (java.util.LinkedList)p.next(); + + java.util.Iterator q = connectionList.iterator(); + while(q.hasNext()) { - Ice.ConnectionI connection = (Ice.ConnectionI)p.next(); - try + Ice.ConnectionI connection = (Ice.ConnectionI)q.next(); + if(connection.endpoint() == endpoint) { - connection.setAdapter(adapter); - } - catch(Ice.LocalException ex) - { - // - // Ignore, the connection is being closed or closed. - // + try + { + connection.setAdapter(adapter); + } + catch(Ice.LocalException ex) + { + // + // Ignore, the connection is being closed or closed. + // + } } } } diff --git a/java/src/IceInternal/TcpConnector.java b/java/src/IceInternal/TcpConnector.java index eeff5b96501..82776427b96 100644 --- a/java/src/IceInternal/TcpConnector.java +++ b/java/src/IceInternal/TcpConnector.java @@ -9,8 +9,10 @@ package IceInternal; -final class TcpConnector implements Connector +final class TcpConnector implements Connector, java.lang.Comparable { + final static short TYPE = 1; + public Transceiver connect(int timeout) { @@ -34,25 +36,109 @@ final class TcpConnector implements Connector return new TcpTransceiver(_instance, fd); } + public short + type() + { + return TYPE; + } + public String toString() { return Network.addrToString(_addr); } + public int + hashCode() + { + return _hashCode; + } + // // Only for use by TcpEndpoint // - TcpConnector(Instance instance, java.net.InetSocketAddress addr) + TcpConnector(Instance instance, java.net.InetSocketAddress addr, int timeout, String connectionId) { _instance = instance; _traceLevels = instance.traceLevels(); _logger = instance.initializationData().logger; _addr = addr; + _timeout = timeout; + _connectionId = connectionId; + + _hashCode = _addr.getAddress().getHostAddress().hashCode(); + _hashCode = 5 * _hashCode + _addr.getPort(); + _hashCode = 5 * _hashCode + _timeout; + _hashCode = 5 * _hashCode + _connectionId.hashCode(); } + // + // Compare connectors for sorting purposes + // + public boolean + equals(java.lang.Object obj) + { + return compareTo(obj) == 0; + } + + public int + compareTo(java.lang.Object obj) // From java.lang.Comparable + { + TcpConnector p = null; + + try + { + p = (TcpConnector)obj; + } + catch(ClassCastException ex) + { + try + { + Connector c = (Connector)obj; + return type() < c.type() ? -1 : 1; + } + catch(ClassCastException ee) + { + assert(false); + } + } + + if(this == p) + { + return 0; + } + + if(_timeout < p._timeout) + { + return -1; + } + else if(p._timeout < _timeout) + { + return 1; + } + + if(!_connectionId.equals(p._connectionId)) + { + return _connectionId.compareTo(p._connectionId); + } + + if(_timeout < p._timeout) + { + return -1; + } + else if(p._timeout < _timeout) + { + return 1; + } + + return Network.compareAddress(_addr, p._addr); + } + private Instance _instance; private TraceLevels _traceLevels; private Ice.Logger _logger; private java.net.InetSocketAddress _addr; + private int _timeout; + private String _connectionId = ""; + private int _hashCode; } diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java index 3929ab77681..ecdbd544d28 100644 --- a/java/src/IceInternal/TcpEndpointI.java +++ b/java/src/IceInternal/TcpEndpointI.java @@ -318,16 +318,6 @@ final class TcpEndpointI extends EndpointI } // - // Return client side transceivers for this endpoint, or empty list - // if a transceiver can only be created by a connector. - // - public java.util.ArrayList - clientTransceivers() - { - return new java.util.ArrayList(); - } - - // // Return a server side transceiver for this endpoint, or null if a // transceiver can only be created by an acceptor. In case a // transceiver is created, this operation also returns a new @@ -335,7 +325,7 @@ final class TcpEndpointI extends EndpointI // for example, if a dynamic port number is assigned. // public Transceiver - serverTransceiver(EndpointIHolder endpoint) + transceiver(EndpointIHolder endpoint) { endpoint.value = this; return null; @@ -353,7 +343,7 @@ final class TcpEndpointI extends EndpointI java.util.Iterator p = addresses.iterator(); while(p.hasNext()) { - connectors.add(new TcpConnector(_instance, (java.net.InetSocketAddress)p.next())); + connectors.add(new TcpConnector(_instance, (java.net.InetSocketAddress)p.next(), _timeout, _connectionId)); } return connectors; } @@ -454,7 +444,15 @@ final class TcpEndpointI extends EndpointI } catch(ClassCastException ex) { - return 1; + try + { + EndpointI e = (EndpointI)obj; + return type() < e.type() ? -1 : 1; + } + catch(ClassCastException ee) + { + assert(false); + } } if(this == p) @@ -494,57 +492,7 @@ final class TcpEndpointI extends EndpointI return 1; } - if(!_host.equals(p._host)) - { - // - // We do the most time-consuming part of the comparison last. - // - java.net.InetSocketAddress laddr = null; - try - { - laddr = Network.getAddress(_host, _port); - } - catch(Ice.DNSException ex) - { - } - - java.net.InetSocketAddress raddr = null; - try - { - raddr = Network.getAddress(p._host, p._port); - } - catch(Ice.DNSException ex) - { - } - - if(laddr == null && raddr != null) - { - return -1; - } - else if(raddr == null && laddr != null) - { - return 1; - } - else if(laddr != null && raddr != null) - { - byte[] larr = laddr.getAddress().getAddress(); - byte[] rarr = raddr.getAddress().getAddress(); - assert(larr.length == rarr.length); - for(int i = 0; i < larr.length; i++) - { - if(larr[i] < rarr[i]) - { - return -1; - } - else if(rarr[i] < larr[i]) - { - return 1; - } - } - } - } - - return 0; + return _host.compareTo(p._host); } public boolean diff --git a/java/src/IceInternal/UdpConnector.java b/java/src/IceInternal/UdpConnector.java new file mode 100644 index 00000000000..9f76949ad87 --- /dev/null +++ b/java/src/IceInternal/UdpConnector.java @@ -0,0 +1,172 @@ +// ********************************************************************** +// +// 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; + +final class UdpConnector implements Connector, java.lang.Comparable +{ + final static short TYPE = 3; + + public Transceiver + connect(int timeout) + { + return new UdpTransceiver(_instance, _addr, _mcastInterface, _mcastTtl); + } + + public short + type() + { + return TYPE; + } + + public String + toString() + { + return Network.addrToString(_addr); + } + + public int + hashCode() + { + return _hashCode; + } + + // + // Only for use by TcpEndpoint + // + UdpConnector(Instance instance, java.net.InetSocketAddress addr, String mcastInterface, int mcastTtl, + byte protocolMajor, byte protocolMinor, byte encodingMajor, byte encodingMinor, String connectionId) + { + _instance = instance; + _traceLevels = instance.traceLevels(); + _logger = instance.initializationData().logger; + _addr = addr; + _mcastInterface = mcastInterface; + _mcastTtl = mcastTtl; + _protocolMajor = protocolMajor; + _protocolMinor = protocolMinor; + _encodingMajor = encodingMajor; + _encodingMinor = encodingMinor; + _connectionId = connectionId; + + _hashCode = _addr.getAddress().getHostAddress().hashCode(); + _hashCode = 5 * _hashCode + _addr.getPort(); + _hashCode = 5 * _hashCode + _mcastInterface.hashCode(); + _hashCode = 5 * _hashCode + _mcastTtl; + _hashCode = 5 * _hashCode + _connectionId.hashCode(); + } + + // + // Compare connectors for sorting purposes + // + public boolean + equals(java.lang.Object obj) + { + return compareTo(obj) == 0; + } + + public int + compareTo(java.lang.Object obj) // From java.lang.Comparable + { + UdpConnector p = null; + + try + { + p = (UdpConnector)obj; + } + catch(ClassCastException ex) + { + try + { + Connector c = (Connector)obj; + return type() < c.type() ? -1 : 1; + } + catch(ClassCastException ee) + { + assert(false); + } + } + + if(this == p) + { + return 0; + } + + if(!_connectionId.equals(p._connectionId)) + { + return _connectionId.compareTo(p._connectionId); + } + + if(_protocolMajor < p._protocolMajor) + { + return -1; + } + else if(p._protocolMajor < _protocolMajor) + { + return 1; + } + + if(_protocolMinor < p._protocolMinor) + { + return -1; + } + else if(p._protocolMinor < _protocolMinor) + { + return 1; + } + + if(_encodingMajor < p._encodingMajor) + { + return -1; + } + else if(p._encodingMajor < _encodingMajor) + { + return 1; + } + + if(_encodingMinor < p._encodingMinor) + { + return -1; + } + else if(p._encodingMinor < _encodingMinor) + { + return 1; + } + + if(_mcastTtl < p._mcastTtl) + { + return -1; + } + else if(p._mcastTtl < _mcastTtl) + { + return 1; + } + + int rc = _mcastInterface.compareTo(p._mcastInterface); + if(rc != 0) + { + return rc; + } + + return Network.compareAddress(_addr, p._addr); + } + + private Instance _instance; + private TraceLevels _traceLevels; + private Ice.Logger _logger; + private java.net.InetSocketAddress _addr; + private String _mcastInterface; + private int _mcastTtl; + private byte _protocolMajor; + private byte _protocolMinor; + private byte _encodingMajor; + private byte _encodingMinor; + private String _connectionId; + private int _hashCode; +} diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java index d31833d8630..30fbdfdb1c1 100644 --- a/java/src/IceInternal/UdpEndpointI.java +++ b/java/src/IceInternal/UdpEndpointI.java @@ -482,24 +482,6 @@ final class UdpEndpointI extends EndpointI } // - // Return client side transceivers for this endpoint, or empty list - // if a transceiver can only be created by a connector. - // - public java.util.ArrayList - clientTransceivers() - { - java.util.ArrayList transceivers = new java.util.ArrayList(); - java.util.ArrayList addresses = Network.getAddresses(_host, _port); - java.util.Iterator p = addresses.iterator(); - while(p.hasNext()) - { - transceivers.add( - new UdpTransceiver(_instance, (java.net.InetSocketAddress)p.next(), _mcastInterface, _mcastTtl)); - } - return transceivers; - } - - // // Return a server side transceiver for this endpoint, or null if a // transceiver can only be created by an acceptor. In case a // transceiver is created, this operation also returns a new @@ -507,7 +489,7 @@ final class UdpEndpointI extends EndpointI // for example, if a dynamic port number is assigned. // public Transceiver - serverTransceiver(EndpointIHolder endpoint) + transceiver(EndpointIHolder endpoint) { UdpTransceiver p = new UdpTransceiver(_instance, _host, _port, _mcastInterface, _connect); endpoint.value = new UdpEndpointI(_instance, _host, p.effectivePort(), _mcastInterface, _mcastTtl, _connect, @@ -522,7 +504,16 @@ final class UdpEndpointI extends EndpointI public java.util.ArrayList connectors() { - return new java.util.ArrayList(); + java.util.ArrayList connectors = new java.util.ArrayList(); + java.util.ArrayList addresses = Network.getAddresses(_host, _port); + java.util.Iterator p = addresses.iterator(); + while(p.hasNext()) + { + connectors.add( + new UdpConnector(_instance, (java.net.InetSocketAddress)p.next(), _mcastInterface, _mcastTtl, + _protocolMajor, _protocolMinor, _encodingMajor, _encodingMinor, _connectionId)); + } + return connectors; } // @@ -619,7 +610,15 @@ final class UdpEndpointI extends EndpointI } catch(ClassCastException ex) { - return 1; + try + { + EndpointI e = (EndpointI)obj; + return type() < e.type() ? -1 : 1; + } + catch(ClassCastException ee) + { + assert(false); + } } if(this == p) @@ -710,57 +709,7 @@ final class UdpEndpointI extends EndpointI return rc; } - if(!_host.equals(p._host)) - { - // - // We do the most time-consuming part of the comparison last. - // - java.net.InetSocketAddress laddr = null; - try - { - laddr = Network.getAddress(_host, _port); - } - catch(Ice.DNSException ex) - { - } - - java.net.InetSocketAddress raddr = null; - try - { - raddr = Network.getAddress(p._host, p._port); - } - catch(Ice.DNSException ex) - { - } - - if(laddr == null && raddr != null) - { - return -1; - } - else if(raddr == null && laddr != null) - { - return 1; - } - else if(laddr != null && raddr != null) - { - byte[] larr = laddr.getAddress().getAddress(); - byte[] rarr = raddr.getAddress().getAddress(); - assert(larr.length == rarr.length); - for(int i = 0; i < larr.length; i++) - { - if(larr[i] < rarr[i]) - { - return -1; - } - else if(rarr[i] < larr[i]) - { - return 1; - } - } - } - } - - return 0; + return _host.compareTo(p._host); } public boolean diff --git a/java/src/IceInternal/UnknownEndpointI.java b/java/src/IceInternal/UnknownEndpointI.java index 8eae6d67a8e..82518ed810b 100644 --- a/java/src/IceInternal/UnknownEndpointI.java +++ b/java/src/IceInternal/UnknownEndpointI.java @@ -97,6 +97,7 @@ final class UnknownEndpointI extends EndpointI { throw new Ice.EndpointParseException("opaque " + str); } + calcHashValue(); } public @@ -220,16 +221,6 @@ final class UnknownEndpointI extends EndpointI } // - // Return client side transceivers for this endpoint, or empty list - // if a transceiver can only be created by a connector. - // - public java.util.ArrayList - clientTransceivers() - { - return new java.util.ArrayList(); - } - - // // Return a server side transceiver for this endpoint, or null if a // transceiver can only be created by an acceptor. In case a // transceiver is created, this operation also returns a new @@ -237,7 +228,7 @@ final class UnknownEndpointI extends EndpointI // for example, if a dynamic port number is assigned. // public Transceiver - serverTransceiver(EndpointIHolder endpoint) + transceiver(EndpointIHolder endpoint) { endpoint.value = null; return null; @@ -275,7 +266,6 @@ final class UnknownEndpointI extends EndpointI expand() { java.util.ArrayList endps = new java.util.ArrayList(); - calcHashValue(); endps.add(this); return endps; } diff --git a/java/ssl/jdk1.4/IceSSL/ConnectorI.java b/java/ssl/jdk1.4/IceSSL/ConnectorI.java index 86055e1d450..8dd8c9ac9c9 100644 --- a/java/ssl/jdk1.4/IceSSL/ConnectorI.java +++ b/java/ssl/jdk1.4/IceSSL/ConnectorI.java @@ -9,8 +9,10 @@ package IceSSL; -final class ConnectorI implements IceInternal.Connector +final class ConnectorI implements IceInternal.Connector, java.lang.Comparable { + final static short TYPE = 2; + public IceInternal.Transceiver connect(int timeout) { @@ -225,23 +227,105 @@ final class ConnectorI implements IceInternal.Connector return new TransceiverI(_instance, fd, connInfo); } + public short + type() + { + return TYPE; + } + public String toString() { return IceInternal.Network.addrToString(_addr); } + public int + hashCode() + { + return _hashCode; + } + // // Only for use by EndpointI // - ConnectorI(Instance instance, java.net.InetSocketAddress addr) + ConnectorI(Instance instance, java.net.InetSocketAddress addr, int timeout, String connectionId) { _instance = instance; _logger = instance.communicator().getLogger(); _host = addr.getHostName(); _addr = addr; + _timeout = timeout; + _connectionId = connectionId; + + _hashCode = _addr.getAddress().getHostAddress().hashCode(); + _hashCode = 5 * _hashCode + _addr.getPort(); + _hashCode = 5 * _hashCode + _timeout; + _hashCode = 5 * _hashCode + _connectionId.hashCode(); } + // + // Compare connectors for sorting purposes + // + public boolean + equals(java.lang.Object obj) + { + return compareTo(obj) == 0; + } + + public int + compareTo(java.lang.Object obj) // From java.lang.Comparable + { + ConnectorI p = null; + + try + { + p = (ConnectorI)obj; + } + catch(ClassCastException ex) + { + try + { + IceInternal.Connector c = (IceInternal.Connector)obj; + return type() < c.type() ? -1 : 1; + } + catch(ClassCastException ee) + { + assert(false); + } + } + + if(this == p) + { + return 0; + } + + if(_timeout < p._timeout) + { + return -1; + } + else if(p._timeout < _timeout) + { + return 1; + } + + if(!_connectionId.equals(p._connectionId)) + { + return _connectionId.compareTo(p._connectionId); + } + + if(_timeout < p._timeout) + { + return -1; + } + else if(p._timeout < _timeout) + { + return 1; + } + + return IceInternal.Network.compareAddress(_addr, p._addr); + } + + private static class ConnectThread extends Thread { ConnectThread(javax.net.ssl.SSLContext ctx, java.net.InetSocketAddress addr) @@ -385,4 +469,7 @@ final class ConnectorI implements IceInternal.Connector private Ice.Logger _logger; private String _host; private java.net.InetSocketAddress _addr; + private int _timeout; + private String _connectionId; + private int _hashCode; } diff --git a/java/ssl/jdk1.4/IceSSL/EndpointI.java b/java/ssl/jdk1.4/IceSSL/EndpointI.java index 7f708d94794..5c4f7152c70 100644 --- a/java/ssl/jdk1.4/IceSSL/EndpointI.java +++ b/java/ssl/jdk1.4/IceSSL/EndpointI.java @@ -318,16 +318,6 @@ final class EndpointI extends IceInternal.EndpointI } // - // Return client side transceivers for this endpoint, or empty list - // if a transceiver can only be created by a connector. - // - public java.util.ArrayList - clientTransceivers() - { - return new java.util.ArrayList(); - } - - // // Return a server side transceiver for this endpoint, or null if a // transceiver can only be created by an acceptor. In case a // transceiver is created, this operation also returns a new @@ -335,7 +325,7 @@ final class EndpointI extends IceInternal.EndpointI // for example, if a dynamic port number is assigned. // public IceInternal.Transceiver - serverTransceiver(IceInternal.EndpointIHolder endpoint) + transceiver(IceInternal.EndpointIHolder endpoint) { endpoint.value = this; return null; @@ -353,7 +343,7 @@ final class EndpointI extends IceInternal.EndpointI java.util.Iterator p = addresses.iterator(); while(p.hasNext()) { - connectors.add(new ConnectorI(_instance, (java.net.InetSocketAddress)p.next())); + connectors.add(new ConnectorI(_instance, (java.net.InetSocketAddress)p.next(), _timeout, _connectionId)); } return connectors; } @@ -454,7 +444,15 @@ final class EndpointI extends IceInternal.EndpointI } catch(ClassCastException ex) { - return 1; + try + { + IceInternal.EndpointI e = (IceInternal.EndpointI)obj; + return type() < e.type() ? -1 : 1; + } + catch(ClassCastException ee) + { + assert(false); + } } if(this == p) @@ -494,57 +492,7 @@ final class EndpointI extends IceInternal.EndpointI return 1; } - if(!_host.equals(p._host)) - { - // - // We do the most time-consuming part of the comparison last. - // - java.net.InetSocketAddress laddr = null; - try - { - laddr = IceInternal.Network.getAddress(_host, _port); - } - catch(Ice.DNSException ex) - { - } - - java.net.InetSocketAddress raddr = null; - try - { - raddr = IceInternal.Network.getAddress(p._host, p._port); - } - catch(Ice.DNSException ex) - { - } - - if(laddr == null && raddr != null) - { - return -1; - } - else if(raddr == null && laddr != null) - { - return 1; - } - else if(laddr != null && raddr != null) - { - byte[] larr = laddr.getAddress().getAddress(); - byte[] rarr = raddr.getAddress().getAddress(); - assert(larr.length == rarr.length); - for(int i = 0; i < larr.length; i++) - { - if(larr[i] < rarr[i]) - { - return -1; - } - else if(rarr[i] < larr[i]) - { - return 1; - } - } - } - } - - return 0; + return _host.compareTo(p._host); } public boolean diff --git a/java/ssl/jdk1.5/IceSSL/ConnectorI.java b/java/ssl/jdk1.5/IceSSL/ConnectorI.java index 7272a41b2c7..6685a9c1dbc 100644 --- a/java/ssl/jdk1.5/IceSSL/ConnectorI.java +++ b/java/ssl/jdk1.5/IceSSL/ConnectorI.java @@ -9,8 +9,10 @@ package IceSSL; -final class ConnectorI implements IceInternal.Connector +final class ConnectorI implements IceInternal.Connector, java.lang.Comparable { + final static short TYPE = 2; + public IceInternal.Transceiver connect(int timeout) { @@ -96,25 +98,109 @@ final class ConnectorI implements IceInternal.Connector return transceiver; } + public short + type() + { + return TYPE; + } + public String toString() { return IceInternal.Network.addrToString(_addr); } + public int + hashCode() + { + return _hashCode; + } + // // Only for use by EndpointI. // - ConnectorI(Instance instance, java.net.InetSocketAddress addr) + ConnectorI(Instance instance, java.net.InetSocketAddress addr, int timeout, String connectionId) { _instance = instance; _logger = instance.communicator().getLogger(); _host = addr.getHostName(); _addr = addr; + _timeout = timeout; + _connectionId = connectionId; + + _hashCode = _addr.getAddress().getHostAddress().hashCode(); + _hashCode = 5 * _hashCode + _addr.getPort(); + _hashCode = 5 * _hashCode + _timeout; + _hashCode = 5 * _hashCode + _connectionId.hashCode(); + } + + // + // Compare connectors for sorting purposes + // + public boolean + equals(java.lang.Object obj) + { + return compareTo(obj) == 0; + } + + public int + compareTo(java.lang.Object obj) // From java.lang.Comparable + { + ConnectorI p = null; + + try + { + p = (ConnectorI)obj; + } + catch(ClassCastException ex) + { + try + { + IceInternal.Connector c = (IceInternal.Connector)obj; + return type() < c.type() ? -1 : 1; + } + catch(ClassCastException ee) + { + assert(false); + } + } + + if(this == p) + { + return 0; + } + + if(_timeout < p._timeout) + { + return -1; + } + else if(p._timeout < _timeout) + { + return 1; + } + + if(!_connectionId.equals(p._connectionId)) + { + return _connectionId.compareTo(p._connectionId); + } + + if(_timeout < p._timeout) + { + return -1; + } + else if(p._timeout < _timeout) + { + return 1; + } + + return IceInternal.Network.compareAddress(_addr, p._addr); } private Instance _instance; private Ice.Logger _logger; private String _host; private java.net.InetSocketAddress _addr; + private int _timeout; + private String _connectionId; + private int _hashCode; } diff --git a/java/ssl/jdk1.5/IceSSL/EndpointI.java b/java/ssl/jdk1.5/IceSSL/EndpointI.java index 0ecd6d78b3a..a2ffea8f4d6 100644 --- a/java/ssl/jdk1.5/IceSSL/EndpointI.java +++ b/java/ssl/jdk1.5/IceSSL/EndpointI.java @@ -318,16 +318,6 @@ final class EndpointI extends IceInternal.EndpointI } // - // Return client side transceivers for this endpoint, or empty list - // if a transceiver can only be created by a connector. - // - public java.util.ArrayList - clientTransceivers() - { - return new java.util.ArrayList(); - } - - // // Return a server side transceiver for this endpoint, or null if a // transceiver can only be created by an acceptor. In case a // transceiver is created, this operation also returns a new @@ -335,7 +325,7 @@ final class EndpointI extends IceInternal.EndpointI // for example, if a dynamic port number is assigned. // public IceInternal.Transceiver - serverTransceiver(IceInternal.EndpointIHolder endpoint) + transceiver(IceInternal.EndpointIHolder endpoint) { endpoint.value = this; return null; @@ -353,7 +343,7 @@ final class EndpointI extends IceInternal.EndpointI java.util.Iterator p = addresses.iterator(); while(p.hasNext()) { - connectors.add(new ConnectorI(_instance, (java.net.InetSocketAddress)p.next())); + connectors.add(new ConnectorI(_instance, (java.net.InetSocketAddress)p.next(), _timeout, _connectionId)); } return connectors; } @@ -454,7 +444,15 @@ final class EndpointI extends IceInternal.EndpointI } catch(ClassCastException ex) { - return 1; + try + { + IceInternal.EndpointI e = (IceInternal.EndpointI)obj; + return type() < e.type() ? -1 : 1; + } + catch(ClassCastException ee) + { + assert(false); + } } if(this == p) @@ -494,57 +492,7 @@ final class EndpointI extends IceInternal.EndpointI return 1; } - if(!_host.equals(p._host)) - { - // - // We do the most time-consuming part of the comparison last. - // - java.net.InetSocketAddress laddr = null; - try - { - laddr = IceInternal.Network.getAddress(_host, _port); - } - catch(Ice.DNSException ex) - { - } - - java.net.InetSocketAddress raddr = null; - try - { - raddr = IceInternal.Network.getAddress(p._host, p._port); - } - catch(Ice.DNSException ex) - { - } - - if(laddr == null && raddr != null) - { - return -1; - } - else if(raddr == null && laddr != null) - { - return 1; - } - else if(laddr != null && raddr != null) - { - byte[] larr = laddr.getAddress().getAddress(); - byte[] rarr = raddr.getAddress().getAddress(); - assert(larr.length == rarr.length); - for(int i = 0; i < larr.length; i++) - { - if(larr[i] < rarr[i]) - { - return -1; - } - else if(rarr[i] < larr[i]) - { - return 1; - } - } - } - } - - return 0; + return _host.compareTo(p._host); } public boolean |