From 3513e475766ddf5d3f5741f9adea48783ea18694 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Fri, 22 Nov 2024 11:10:58 -0500 Subject: [PATCH] Fix Java --- .../src/main/java/com/zeroc/Ice/EndpointI.java | 6 +++--- .../src/main/java/com/zeroc/Ice/IPEndpointI.java | 8 +------- .../main/java/com/zeroc/Ice/ObjectAdapter.java | 14 ++++++-------- .../main/java/com/zeroc/Ice/OpaqueEndpointI.java | 2 +- .../main/java/com/zeroc/Ice/SSL/EndpointI.java | 4 ++-- .../main/java/com/zeroc/Ice/TcpEndpointI.java | 16 ++++++++++++++++ .../main/java/com/zeroc/Ice/UdpEndpointI.java | 14 ++++++++++++++ .../src/main/java/com/zeroc/Ice/WSEndpoint.java | 4 ++-- .../src/main/java/com/zeroc/IceBT/EndpointI.java | 2 +- .../main/java/test/Ice/background/EndpointI.java | 4 ++-- 10 files changed, 48 insertions(+), 26 deletions(-) diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/EndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/EndpointI.java index d7ed37361c4..ce50e8f0412 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/EndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/EndpointI.java @@ -120,9 +120,9 @@ public abstract Acceptor acceptor( // address. public abstract boolean isLoopbackOrMulticast(); - // Returns a new endpoint with the specified host; returns this when this operation is not - // applicable. - public abstract EndpointI withPublishedHost(String host); + // Returns a new endpoint with the specified host (if not empty) and all local options cleared. + // May return this. + public abstract EndpointI toPublishedEndpoint(String publishedHost); // // Check whether the endpoint is equivalent to another one. diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/IPEndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/IPEndpointI.java index 6802d758efe..ea4dfc3124a 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/IPEndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/IPEndpointI.java @@ -128,11 +128,6 @@ public boolean isLoopbackOrMulticast() { } } - @Override - public EndpointI withPublishedHost(String host) { - return createEndpoint(host, _port, _connectionId); - } - @Override public boolean equivalent(EndpointI endpoint) { if (!(endpoint instanceof IPEndpointI)) { @@ -142,8 +137,7 @@ public boolean equivalent(EndpointI endpoint) { IPEndpointI ipEndpointI = (IPEndpointI) endpoint; return ipEndpointI.type() == type() && ipEndpointI._normalizedHost.equals(_normalizedHost) - && ipEndpointI._port == _port - && java.util.Objects.equals(ipEndpointI._sourceAddr, _sourceAddr); + && ipEndpointI._port == _port; } public java.util.List connectors( diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java index cf7a720ed4d..f8ac6195807 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java @@ -1428,14 +1428,12 @@ private EndpointI[] computePublishedEndpoints() { } } - if (!publishedHost.isEmpty()) { - // Replace the host in all endpoints by publishedHost (when applicable). - final String publishedHostCapture = publishedHost; - endpoints = - endpoints - .map(e -> e.withPublishedHost(publishedHostCapture)) - .distinct(); - } + // Replace the host in all endpoints by publishedHost (when applicable) and clear + // local options. + final String publishedHostCapture = publishedHost; + endpoints = + endpoints.map(e -> e.toPublishedEndpoint(publishedHostCapture)).distinct(); + endpointsArray = endpoints.toArray(EndpointI[]::new); } else { endpointsArray = endpointsList.toArray(EndpointI[]::new); diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/OpaqueEndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/OpaqueEndpointI.java index 5451aa1a514..572afff8595 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/OpaqueEndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/OpaqueEndpointI.java @@ -191,7 +191,7 @@ public boolean isLoopbackOrMulticast() { } @Override - public EndpointI withPublishedHost(String host) { + public EndpointI toPublishedEndpoint(String publishedHost) { return this; } diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/SSL/EndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/SSL/EndpointI.java index c9b32f02347..44bad80262a 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/SSL/EndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/SSL/EndpointI.java @@ -174,8 +174,8 @@ public boolean isLoopbackOrMulticast() { } @Override - public com.zeroc.Ice.EndpointI withPublishedHost(String host) { - return endpoint(_delegate.withPublishedHost(host)); + public com.zeroc.Ice.EndpointI toPublishedEndpoint(String publishedHost) { + return endpoint(_delegate.toPublishedEndpoint(publishedHost)); } @Override diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java index fa28e53e54b..eb2671983bf 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java @@ -213,6 +213,22 @@ public int hashCode() { return h; } + @Override + public EndpointI toPublishedEndpoint(String publishedHost) { + if (publishedHost.isEmpty() && _sourceAddr == null && _connectionId.isEmpty()) { + return this; + } else { + return new TcpEndpointI( + _instance, + publishedHost.isEmpty() ? _host : publishedHost, + _port, + null, + _timeout, + "", + _compress); + } + } + @Override protected boolean checkOption(String option, String argument, String endpoint) { if (super.checkOption(option, argument, endpoint)) { diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/UdpEndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/UdpEndpointI.java index a80c4f35184..843f19763e3 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/UdpEndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/UdpEndpointI.java @@ -317,6 +317,20 @@ public void fillEndpointInfo(IPEndpointInfo info) { } } + @Override + public EndpointI toPublishedEndpoint(String publishedHost) { + return new UdpEndpointI( + _instance, + publishedHost.isEmpty() ? _host : publishedHost, + _port, + null, + "", + -1, + false, // for "connect" + "", + _compress); + } + @Override protected boolean checkOption(String option, String argument, String endpoint) { if (super.checkOption(option, argument, endpoint)) { diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/WSEndpoint.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/WSEndpoint.java index 07756599c49..5cddd5db2d2 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/WSEndpoint.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/WSEndpoint.java @@ -184,8 +184,8 @@ public boolean isLoopbackOrMulticast() { } @Override - public EndpointI withPublishedHost(String host) { - return endpoint(_delegate.withPublishedHost(host)); + public EndpointI toPublishedEndpoint(String publishedHost) { + return endpoint(_delegate.toPublishedEndpoint(publishedHost)); } @Override diff --git a/java/src/com.zeroc.icebt/src/main/java/com/zeroc/IceBT/EndpointI.java b/java/src/com.zeroc.icebt/src/main/java/com/zeroc/IceBT/EndpointI.java index 9d6099b6753..a1631a46a45 100644 --- a/java/src/com.zeroc.icebt/src/main/java/com/zeroc/IceBT/EndpointI.java +++ b/java/src/com.zeroc.icebt/src/main/java/com/zeroc/IceBT/EndpointI.java @@ -166,7 +166,7 @@ public boolean isLoopbackOrMulticast() { } @Override - public com.zeroc.Ice.EndpointI withPublishedHost(String host) { + public com.zeroc.Ice.EndpointI toPublishedEndpoint(String publishedHost) { return this; } diff --git a/java/test/src/main/java/test/Ice/background/EndpointI.java b/java/test/src/main/java/test/Ice/background/EndpointI.java index 0ec32379616..5bcc90556b7 100644 --- a/java/test/src/main/java/test/Ice/background/EndpointI.java +++ b/java/test/src/main/java/test/Ice/background/EndpointI.java @@ -159,8 +159,8 @@ public boolean isLoopbackOrMulticast() { } @Override - public com.zeroc.Ice.EndpointI withPublishedHost(String host) { - return endpoint(_endpoint.withPublishedHost(host)); + public com.zeroc.Ice.EndpointI toPublishedEndpoint(String publishedHost) { + return endpoint(_endpoint.toPublishedEndpoint(publishedHost)); } @Override