Class KiwiInternetAddresses2


  • @Beta
    public final class KiwiInternetAddresses2
    extends Object
    Utilities related to internet addresses.

    These utilities could be considered for kiwi's KiwiInternetAddresses class.

    • Method Detail

      • resolveLocalAddressPreferringSupplied

        public static KiwiInternetAddresses2.SimpleAddressHolder resolveLocalAddressPreferringSupplied​(Supplier<String> hostnameSupplier,
                                                                                                       Supplier<String> ipSupplier)
        Return a KiwiInternetAddresses2.SimpleAddressHolder containing a hostname and IP supplied by the given Suppliers, or falling back to the hostname and address returned by InetAddress.getLocalHost() when a Supplier returns a blank String (null, empty string, whitespace only).

        The primary use case for this is when you might want to override the default hostname and/or IP using some external configuration such as environment variables or system properties specified via command line. The suppliers can do something like: () -> environment.getenv("CUSTOM_HOST")).

        Parameters:
        hostnameSupplier - supplier of hostname, may return blank string
        ipSupplier - supplier of ip address, may return blank string
        Returns:
        a new SimpleAddressHolder instance
        Implementation Note:
        This is a pretty narrow use case, so it most likely won't ever move into kiwi proper. The one place we actually use this is in a "core service" library which does a bunch of setup and initialization common across services. One of the specific things it does is to get the hostname and IP address to use when registering a service, e.g. to Consul. We permit specific overrides to the hostname and/or IP address via environment variables in a service host.