@@ -57,6 +57,22 @@ public static List<ServiceConfig> toStorkServiceConfig(StorkConfiguration storkC
5757 return storkServicesConfigs ;
5858 }
5959
60+ /**
61+ * Builds a default {@link ServiceConfiguration} for a Quarkus application
62+ * when no explicit service registrar configuration is defined by the developer.
63+ * <p>
64+ * This method generates a minimal configuration with the provided registrar type
65+ * and optionally includes a fully resolved health check URL.
66+ * It retrieves default host and port values from the current Quarkus configuration
67+ * if needed to complete the health check URL.
68+ *
69+ * @param serviceRegistrarType the type of the registrar (e.g., "consul", "eureka"); must not be blank
70+ * @param healthCheckPath the relative path to the health check endpoint (e.g., {@code /q/health/live});
71+ * if provided, a full URL will be constructed using default host and port
72+ * @return a {@link ServiceConfiguration} pre-filled with the type and optional health check URL
73+ * @throws IllegalArgumentException if {@code serviceRegistrarType} is null or blank
74+ */
75+
6076 public static ServiceConfiguration buildDefaultRegistrarConfiguration (String serviceRegistrarType , String healthCheckPath ) {
6177 requireRegistrarTypeNotBlank (serviceRegistrarType );
6278 Map <String , String > parameters = new HashMap <>();
@@ -69,6 +85,20 @@ public static ServiceConfiguration buildDefaultRegistrarConfiguration(String ser
6985 return buildServiceConfigurationWithRegistrar (serviceRegistrarType , true , parameters );
7086 }
7187
88+ /**
89+ * Returns a copy of the given {@link ServiceConfiguration} with the registrar type
90+ * and optional health check URL added if the registrar type is not already set.
91+ * <p>
92+ * If the registrar is already present, its configuration is reused and only the missing
93+ * health check URL may be appended. The registrar is marked as enabled by default unless
94+ * specified otherwise.
95+ *
96+ * @param serviceRegistrarType the registrar type to set if missing (e.g., "consul"); must not be blank
97+ * @param serviceConfiguration the existing service configuration to update
98+ * @param healthCheckUrl optional full health check URL to add to the parameters
99+ * @return an updated {@link ServiceConfiguration} with type and health check URL as needed
100+ * @throws IllegalArgumentException if {@code serviceRegistrarType} is null or blank
101+ */
72102 public static ServiceConfiguration addRegistrarTypeIfAbsent (String serviceRegistrarType ,
73103 ServiceConfiguration serviceConfiguration , String healthCheckUrl ) {
74104 requireRegistrarTypeNotBlank (serviceRegistrarType );
@@ -124,6 +154,21 @@ public Map<String, String> parameters() {
124154 };
125155 }
126156
157+ /**
158+ * Resolves the host (IP address or hostname) to use for service registration.
159+ * <p>
160+ * The method follows the following resolution strategy:
161+ * <ul>
162+ * <li>If {@code parameters} contains a custom {@code ip-address}, it is returned.</li>
163+ * <li>Otherwise, in dev/test mode, {@code localhost} is used as fallback.</li>
164+ * <li>In other modes, {@code 0.0.0.0} is used unless overridden by {@code quarkus.http.host}.</li>
165+ * <li>Finally, if no configuration is present, the method attempts to detect a valid local IP address.</li>
166+ * </ul>
167+ *
168+ * @param parameters a map of registrar parameters that may include {@code ip-address}
169+ * @param quarkusConfig the active Quarkus {@link Config} instance
170+ * @return the resolved host to use for registration
171+ */
127172 public static String getOrDefaultHost (Map <String , String > parameters , Config quarkusConfig ) {
128173 String customHost = parameters .containsKey ("ip-address" ) ? parameters .get ("ip-address" )
129174 : null ;
@@ -141,12 +186,36 @@ public static String getOrDefaultHost(Map<String, String> parameters, Config qua
141186 return customHost ;
142187 }
143188
189+ /**
190+ * Resolves the port to use for service registration.
191+ * <p>
192+ * Priority order:
193+ * <ol>
194+ * <li>If {@code parameters} includes a {@code port}, it is used.</li>
195+ * <li>Else, the value from {@code quarkus.http.port} is used, if present.</li>
196+ * <li>Otherwise, defaults to {@code 8080}.</li>
197+ * </ol>
198+ *
199+ * @param parameters a map of registrar parameters that may include {@code port}
200+ * @param quarkusConfig the active Quarkus {@link Config} instance
201+ * @return the resolved port as an integer
202+ */
144203 public static int getOrDefaultPort (Map <String , String > parameters , Config quarkusConfig ) {
145204 String customPort = parameters .getOrDefault ("port" ,
146205 quarkusConfig .getOptionalValue ("quarkus.http.port" , String .class ).orElse ("8080" ));
147206 return Integer .parseInt (customPort );
148207 }
149208
209+ /**
210+ * Attempts to detect the first valid non-loopback IPv4 address of the host machine.
211+ * <p>
212+ * This is used when no explicit IP address is configured. The method iterates over
213+ * all available network interfaces, filtering out loopback and down interfaces.
214+ * <p>
215+ * If detection fails, it falls back to {@link InetAddress#getLocalHost()}.
216+ *
217+ * @return the detected {@link InetAddress}, or {@code null} if none found
218+ */
150219 public static InetAddress detectAddress () {
151220 try {
152221 Enumeration <NetworkInterface > interfaces = NetworkInterface .getNetworkInterfaces ();
@@ -173,7 +242,16 @@ public static InetAddress detectAddress() {
173242 }
174243 }
175244
176- static InetAddress findFirstValidAddress (List <NetworkInterfaceWrapper > interfaces ) {
245+ /**
246+ * Finds the first valid IPv4 address from the provided list of network interfaces.
247+ * <p>
248+ * The method checks that each interface is up and not a loopback, and then looks for
249+ * a non-loopback {@link Inet4Address} among the available addresses.
250+ *
251+ * @param interfaces a list of {@link NetworkInterfaceWrapper} representing system interfaces
252+ * @return the first valid {@link InetAddress}, or {@code null} if none found
253+ */
254+ private static InetAddress findFirstValidAddress (List <NetworkInterfaceWrapper > interfaces ) {
177255 try {
178256 for (NetworkInterfaceWrapper iface : interfaces ) {
179257 if (!iface .isUp () || iface .isLoopback ())
0 commit comments