|
|
@ -1,9 +1,17 @@
|
|
|
|
package cn.hippo4j.starter.toolkit;
|
|
|
|
package cn.hippo4j.starter.toolkit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hippo4j.common.config.ApplicationContextHolder;
|
|
|
|
|
|
|
|
import cn.hippo4j.starter.config.BootstrapProperties;
|
|
|
|
import cn.hippo4j.starter.toolkit.inet.InetUtils;
|
|
|
|
import cn.hippo4j.starter.toolkit.inet.InetUtils;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
|
|
|
import com.google.common.base.Joiner;
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
import org.springframework.core.env.ConfigurableEnvironment;
|
|
|
|
import org.springframework.core.env.ConfigurableEnvironment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.GROUP_KEY_DELIMITER;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
|
|
|
|
import static cn.hippo4j.starter.config.DynamicThreadPoolAutoConfiguration.CLIENT_IDENTIFICATION_VALUE;
|
|
|
|
import static cn.hippo4j.starter.config.DynamicThreadPoolAutoConfiguration.CLIENT_IDENTIFICATION_VALUE;
|
|
|
|
|
|
|
|
|
|
|
@ -15,6 +23,8 @@ import static cn.hippo4j.starter.config.DynamicThreadPoolAutoConfiguration.CLIEN
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class IdentifyUtil {
|
|
|
|
public class IdentifyUtil {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String identify;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Generate identify.
|
|
|
|
* Generate identify.
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -22,7 +32,10 @@ public class IdentifyUtil {
|
|
|
|
* @param hippo4JInetUtils
|
|
|
|
* @param hippo4JInetUtils
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static String generate(ConfigurableEnvironment environment, InetUtils hippo4JInetUtils) {
|
|
|
|
public static synchronized String generate(ConfigurableEnvironment environment, InetUtils hippo4JInetUtils) {
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(identify)) {
|
|
|
|
|
|
|
|
return identify;
|
|
|
|
|
|
|
|
}
|
|
|
|
String ip = hippo4JInetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
|
|
|
|
String ip = hippo4JInetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
|
|
|
|
String port = environment.getProperty("server.port");
|
|
|
|
String port = environment.getProperty("server.port");
|
|
|
|
String identification = StrUtil.builder(ip,
|
|
|
|
String identification = StrUtil.builder(ip,
|
|
|
@ -32,7 +45,45 @@ public class IdentifyUtil {
|
|
|
|
CLIENT_IDENTIFICATION_VALUE
|
|
|
|
CLIENT_IDENTIFICATION_VALUE
|
|
|
|
).toString();
|
|
|
|
).toString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
identify = identification;
|
|
|
|
return identification;
|
|
|
|
return identification;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get identify.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
|
|
|
public static String getIdentify() {
|
|
|
|
|
|
|
|
while (StrUtil.isBlank(identify)) {
|
|
|
|
|
|
|
|
ConfigurableEnvironment environment = ApplicationContextHolder.getBean(ConfigurableEnvironment.class);
|
|
|
|
|
|
|
|
InetUtils inetUtils = ApplicationContextHolder.getBean(InetUtils.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (environment != null && inetUtils != null) {
|
|
|
|
|
|
|
|
String identify = generate(environment, inetUtils);
|
|
|
|
|
|
|
|
return identify;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Thread.sleep(500);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return identify;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get thread pool identify.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param threadPoolId
|
|
|
|
|
|
|
|
* @param properties
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String getThreadPoolIdentify(String threadPoolId, BootstrapProperties properties) {
|
|
|
|
|
|
|
|
ArrayList<String> params = Lists.newArrayList(
|
|
|
|
|
|
|
|
threadPoolId, properties.getItemId(), properties.getNamespace(), getIdentify()
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Joiner.on(GROUP_KEY_DELIMITER).join(params);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|