Add method and field annotations (#890)

pull/892/head
马称 Ma Chen 2 years ago committed by GitHub
parent c423ffa448
commit 563d509787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,14 +26,31 @@ import org.springframework.core.env.PropertyResolver;
*/
public class CloudCommonIdUtil {
/**
* Splice target information separator
*/
private static final String SEPARATOR = ":";
/**
* Get client ip port.
*
* @param resolver resolver
* @param inetUtils inet utils
* @return ip and port
*/
public static String getClientIpPort(PropertyResolver resolver, InetUtils inetUtils) {
String hostname = inetUtils.findFirstNonLoopBackHostInfo().getIpAddress();
String port = resolver.getProperty("server.port", "8080");
return combineParts(hostname, SEPARATOR, port);
}
/**
* Get default instance id.
*
* @param resolver resolver
* @param inetUtils inet utils
* @return default instance id
*/
@SneakyThrows
public static String getDefaultInstanceId(PropertyResolver resolver, InetUtils inetUtils) {
String namePart = getIpApplicationName(resolver, inetUtils);
@ -41,6 +58,13 @@ public class CloudCommonIdUtil {
return combineParts(namePart, SEPARATOR, indexPart);
}
/**
* Get ip application name.
*
* @param resolver resolver
* @param inetUtils inet utils
* @return ip application name
*/
@SneakyThrows
public static String getIpApplicationName(PropertyResolver resolver, InetUtils inetUtils) {
String hostname = inetUtils.findFirstNonLoopBackHostInfo().getIpAddress();
@ -48,6 +72,14 @@ public class CloudCommonIdUtil {
return combineParts(hostname, SEPARATOR, appName);
}
/**
* Combine parts.
*
* @param firstPart first part
* @param separator separator
* @param secondPart second part
* @return combined
*/
public static String combineParts(String firstPart, String separator, String secondPart) {
String combined = null;
if (firstPart != null && secondPart != null) {

Loading…
Cancel
Save