|
|
|
@ -19,12 +19,11 @@ package cn.hippo4j.springboot.starter.remote;
|
|
|
|
|
|
|
|
|
|
import cn.hippo4j.common.config.ApplicationContextHolder;
|
|
|
|
|
import cn.hippo4j.common.constant.Constants;
|
|
|
|
|
import cn.hippo4j.common.design.builder.ThreadFactoryBuilder;
|
|
|
|
|
import cn.hippo4j.common.toolkit.StringUtil;
|
|
|
|
|
import cn.hippo4j.common.toolkit.http.HttpUtil;
|
|
|
|
|
import cn.hippo4j.common.web.base.Result;
|
|
|
|
|
import cn.hippo4j.common.design.builder.ThreadFactoryBuilder;
|
|
|
|
|
import cn.hippo4j.springboot.starter.config.BootstrapProperties;
|
|
|
|
|
import cn.hippo4j.springboot.starter.core.ClientShutdown;
|
|
|
|
|
import cn.hippo4j.springboot.starter.security.SecurityProxy;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
@ -32,12 +31,10 @@ import java.util.Map;
|
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Server http agent.
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class ServerHttpAgent implements HttpAgent {
|
|
|
|
|
|
|
|
|
|
private final BootstrapProperties dynamicThreadPoolProperties;
|
|
|
|
@ -48,8 +45,6 @@ public class ServerHttpAgent implements HttpAgent {
|
|
|
|
|
|
|
|
|
|
private ServerHealthCheck serverHealthCheck;
|
|
|
|
|
|
|
|
|
|
private ClientShutdown clientShutdown;
|
|
|
|
|
|
|
|
|
|
private ScheduledExecutorService executorService;
|
|
|
|
|
|
|
|
|
|
private final long securityInfoRefreshIntervalMills = TimeUnit.SECONDS.toMillis(5);
|
|
|
|
@ -115,9 +110,6 @@ public class ServerHttpAgent implements HttpAgent {
|
|
|
|
|
public Result httpPostByConfig(String path, Map<String, String> headers, Map<String, String> paramValues, long readTimeoutMs) {
|
|
|
|
|
isHealthStatus();
|
|
|
|
|
injectSecurityInfo(paramValues);
|
|
|
|
|
if (isPrepareClose()) {
|
|
|
|
|
return new Result();
|
|
|
|
|
}
|
|
|
|
|
return HttpUtil.post(buildUrl(path), headers, paramValues, readTimeoutMs, Result.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -137,18 +129,6 @@ public class ServerHttpAgent implements HttpAgent {
|
|
|
|
|
serverHealthCheck.isHealthStatus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isPrepareClose() {
|
|
|
|
|
if (clientShutdown == null) {
|
|
|
|
|
clientShutdown = ApplicationContextHolder.getBean(ClientShutdown.class);
|
|
|
|
|
}
|
|
|
|
|
if (clientShutdown.isPrepareClose()) {
|
|
|
|
|
clientShutdown.countDown();
|
|
|
|
|
log.info("client prepare shutdown");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map injectSecurityInfo(Map<String, String> params) {
|
|
|
|
|
if (StringUtil.isNotBlank(securityProxy.getAccessToken())) {
|
|
|
|
|
params.put(Constants.ACCESS_TOKEN, securityProxy.getAccessToken());
|
|
|
|
|