Skip to content

Commit

Permalink
Fix Java
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Nov 22, 2024
1 parent f60efc7 commit 3513e47
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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<Connector> connectors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public boolean isLoopbackOrMulticast() {
}

@Override
public EndpointI withPublishedHost(String host) {
public EndpointI toPublishedEndpoint(String publishedHost) {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions java/test/src/main/java/test/Ice/background/EndpointI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3513e47

Please sign in to comment.