Package org.kiwiproject.beta.net
Class KiwiInternetAddresses2
java.lang.Object
org.kiwiproject.beta.net.KiwiInternetAddresses2
Utilities related to internet addresses.
These utilities could be considered for kiwi's KiwiInternetAddresses class.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionresolveLocalAddressPreferringEnv(@Nullable String hostnameEnvVar, @Nullable String ipEnvVar) Return aKiwiInternetAddresses2.SimpleAddressHoldercontaining a hostname and IP stored in the given environment variables, or fall back to the hostname and address returned byInetAddress.getLocalHost()when the environment variables do not exist or have blank values.resolveLocalAddressPreferringSupplied(Supplier<String> hostnameSupplier, Supplier<String> ipSupplier) Return aKiwiInternetAddresses2.SimpleAddressHoldercontaining a hostname and IP supplied by the given Suppliers, or falling back to the hostname and address returned byInetAddress.getLocalHost()when a Supplier returns a blank String (null, empty string, whitespace only).
-
Method Details
-
resolveLocalAddressPreferringEnv
public static KiwiInternetAddresses2.SimpleAddressHolder resolveLocalAddressPreferringEnv(@Nullable String hostnameEnvVar, @Nullable String ipEnvVar) Return aKiwiInternetAddresses2.SimpleAddressHoldercontaining a hostname and IP stored in the given environment variables, or fall back to the hostname and address returned byInetAddress.getLocalHost()when the environment variables do not exist or have blank values.- Parameters:
hostnameEnvVar- the environment variable to check for hostnameipEnvVar- the environment variable to check for IP address- Returns:
- a new SimpleAddressHolder instance
- See Also:
-
resolveLocalAddressPreferringSupplied
public static KiwiInternetAddresses2.SimpleAddressHolder resolveLocalAddressPreferringSupplied(Supplier<String> hostnameSupplier, Supplier<String> ipSupplier) Return aKiwiInternetAddresses2.SimpleAddressHoldercontaining a hostname and IP supplied by the given Suppliers, or falling back to the hostname and address returned byInetAddress.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, the supplier may return blank stringipSupplier- supplier of ip address, the supplier 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.
-