Skip to content

Commit

Permalink
Remove AddressHelper class
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Feb 7, 2025
1 parent 61e91c4 commit 825eacd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 58 deletions.
55 changes: 0 additions & 55 deletions vertx-core/src/main/java/io/vertx/core/eventbus/AddressHelper.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import io.vertx.core.*;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.AddressHelper;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.eventbus.EventBusOptions;
import io.vertx.core.eventbus.MessageCodec;
Expand Down Expand Up @@ -41,6 +40,11 @@
import io.vertx.core.spi.cluster.RegistrationInfo;
import io.vertx.core.spi.metrics.VertxMetrics;

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -86,7 +90,34 @@ public ClusteredEventBus(VertxInternal vertx, VertxOptions options, ClusterManag
this.client = client;
}

private NetClient createNetClient(VertxInternal vertx, NetClientOptions clientOptions) {
/**
* Pick a default address for clustered event bus when none was provided by either the user or the cluster manager.
*/
public static String defaultAddress() {
Enumeration<NetworkInterface> nets;
try {
nets = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) {
return null;
}
NetworkInterface netinf;
while (nets.hasMoreElements()) {
netinf = nets.nextElement();

Enumeration<InetAddress> addresses = netinf.getInetAddresses();

while (addresses.hasMoreElements()) {
InetAddress address = addresses.nextElement();
if (!address.isAnyLocalAddress() && !address.isMulticastAddress()
&& !(address instanceof Inet6Address)) {
return address.getHostAddress();
}
}
}
return null;
}

private NetClient createNetClient(VertxInternal vertx, NetClientOptions clientOptions) {
NetClientBuilder builder = new NetClientBuilder(vertx, clientOptions);
VertxMetrics metricsSPI = vertx.metricsSPI();
if (metricsSPI != null) {
Expand Down Expand Up @@ -263,7 +294,7 @@ private String getClusterHost() {
if ((host = clusterManager.clusterHost()) != null) {
return host;
}
return AddressHelper.defaultAddress();
return defaultAddress();
}

private int getClusterPublicPort(int actualPort) {
Expand Down

0 comments on commit 825eacd

Please sign in to comment.