Merge pull request #477 from mabaiwan/develop

hippo4j-spring-boot-starter code naming and log optimization
pull/483/head
小马哥 2 years ago committed by GitHub
commit f4a3f3a966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,10 @@
package cn.hippo4j.common.model; package cn.hippo4j.common.model;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.util.List; import java.util.List;
@ -26,6 +29,9 @@ import java.util.List;
* Thread detail state info. * Thread detail state info.
*/ */
@Data @Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
public class ThreadDetailStateInfo { public class ThreadDetailStateInfo {

@ -0,0 +1,44 @@
package cn.hippo4j.common.toolkit;
import cn.hutool.core.util.StrUtil;
import java.util.HashSet;
import java.util.Set;
/**
* Boolean util.
*/
public class BooleanUtil {
private static final Set<String> TREE_SET = new HashSet(3);
static {
TREE_SET.add("true");
TREE_SET.add("yes");
TREE_SET.add("1");
}
/**
* To boolean.
*
* @param valueStr
* @return
*/
public static boolean toBoolean(String valueStr) {
if (StrUtil.isNotBlank(valueStr)) {
valueStr = valueStr.trim().toLowerCase();
return TREE_SET.contains(valueStr);
}
return false;
}
/**
* Is true.
*
* @param bool
* @return
*/
public static boolean isTrue(Boolean bool) {
return Boolean.TRUE.equals(bool);
}
}

@ -29,7 +29,7 @@ import cn.hippo4j.config.model.biz.notify.NotifyRespDTO;
import cn.hippo4j.config.service.biz.NotifyService; import cn.hippo4j.config.service.biz.NotifyService;
import cn.hippo4j.config.toolkit.BeanUtil; import cn.hippo4j.config.toolkit.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.BooleanUtil; import cn.hippo4j.common.toolkit.BooleanUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;

@ -103,9 +103,4 @@ public class BootstrapProperties implements BootstrapPropertiesInterface {
* Time interval for client to collect monitoring data. unit: ms * Time interval for client to collect monitoring data. unit: ms
*/ */
private Long collectInterval = 5000L; private Long collectInterval = 5000L;
/**
* JSON serialization type.
*/
private String jsonSerializeType = "JACKSON";
} }

@ -43,23 +43,21 @@ public class DiscoveryConfiguration {
private final ConfigurableEnvironment environment; private final ConfigurableEnvironment environment;
private final BootstrapProperties properties; private final BootstrapProperties bootstrapProperties;
private final InetUtils hippo4JInetUtils; private final InetUtils hippo4JInetUtils;
@Bean @Bean
@SneakyThrows @SneakyThrows
public InstanceInfo instanceConfig() { public InstanceInfo instanceConfig() {
String namespace = properties.getNamespace(); String namespace = bootstrapProperties.getNamespace();
String itemId = properties.getItemId(); String itemId = bootstrapProperties.getItemId();
String port = environment.getProperty("server.port", "8080"); String port = environment.getProperty("server.port", "8080");
String applicationName = environment.getProperty("spring.dynamic.thread-pool.item-id"); String applicationName = environment.getProperty("spring.dynamic.thread-pool.item-id");
String active = environment.getProperty("spring.profiles.active", "UNKNOWN"); String active = environment.getProperty("spring.profiles.active", "UNKNOWN");
InstanceInfo instanceInfo = new InstanceInfo(); InstanceInfo instanceInfo = new InstanceInfo();
String instanceId = CloudCommonIdUtil.getDefaultInstanceId(environment, hippo4JInetUtils); String instanceId = CloudCommonIdUtil.getDefaultInstanceId(environment, hippo4JInetUtils);
instanceId = StrBuilder.create().append(instanceId).append(IDENTIFY_SLICER_SYMBOL).append(CLIENT_IDENTIFICATION_VALUE).toString(); instanceId = StrBuilder.create().append(instanceId).append(IDENTIFY_SLICER_SYMBOL).append(CLIENT_IDENTIFICATION_VALUE).toString();
String contextPath = environment.getProperty("server.servlet.context-path", ""); String contextPath = environment.getProperty("server.servlet.context-path", "");
instanceInfo.setInstanceId(instanceId) instanceInfo.setInstanceId(instanceId)
.setIpApplicationName(CloudCommonIdUtil.getIpApplicationName(environment, hippo4JInetUtils)) .setIpApplicationName(CloudCommonIdUtil.getIpApplicationName(environment, hippo4JInetUtils))
@ -68,16 +66,13 @@ public class DiscoveryConfiguration {
.setPort(port) .setPort(port)
.setClientBasePath(contextPath) .setClientBasePath(contextPath)
.setGroupKey(ContentUtil.getGroupKey(itemId, namespace)); .setGroupKey(ContentUtil.getGroupKey(itemId, namespace));
String callBackUrl = new StringBuilder().append(instanceInfo.getHostName()).append(":") String callBackUrl = new StringBuilder().append(instanceInfo.getHostName()).append(":")
.append(port).append(instanceInfo.getClientBasePath()) .append(port).append(instanceInfo.getClientBasePath())
.toString(); .toString();
instanceInfo.setCallBackUrl(callBackUrl); instanceInfo.setCallBackUrl(callBackUrl);
String identify = IdentifyUtil.generate(environment, hippo4JInetUtils); String identify = IdentifyUtil.generate(environment, hippo4JInetUtils);
instanceInfo.setIdentify(identify); instanceInfo.setIdentify(identify);
instanceInfo.setActive(active.toUpperCase()); instanceInfo.setActive(active.toUpperCase());
return instanceInfo; return instanceInfo;
} }

@ -24,9 +24,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
/** /**
* Netty ClientCon figuration * Netty client configuration.
*/ */
@ConditionalOnProperty(prefix = BootstrapProperties.PREFIX, name = "report-type", matchIfMissing = false, havingValue = "netty") @ConditionalOnProperty(prefix = BootstrapProperties.PREFIX, name = "report-type", havingValue = "netty")
public class NettyClientConfiguration { public class NettyClientConfiguration {
@Bean @Bean

@ -40,14 +40,14 @@ public class WebThreadPoolController {
@GetMapping("/web/base/info") @GetMapping("/web/base/info")
public Result<ThreadPoolBaseInfo> getPoolBaseState() { public Result<ThreadPoolBaseInfo> getPoolBaseState() {
ThreadPoolBaseInfo poolBaseInfo = webThreadPoolServiceChoose.choose().simpleInfo(); ThreadPoolBaseInfo result = webThreadPoolServiceChoose.choose().simpleInfo();
return Results.success(poolBaseInfo); return Results.success(result);
} }
@GetMapping("/web/run/state") @GetMapping("/web/run/state")
public Result<ThreadPoolRunStateInfo> getPoolRunState() { public Result<ThreadPoolRunStateInfo> getPoolRunState() {
ThreadPoolRunStateInfo poolRunState = webThreadPoolServiceChoose.choose().getWebRunStateInfo(); ThreadPoolRunStateInfo result = webThreadPoolServiceChoose.choose().getWebRunStateInfo();
return Results.success(poolRunState); return Results.success(result);
} }
@PostMapping("/web/update/pool") @PostMapping("/web/update/pool")

@ -45,13 +45,13 @@ public class WebThreadPoolRunStateController {
@GetMapping("/run/state/{threadPoolId}") @GetMapping("/run/state/{threadPoolId}")
public Result<ThreadPoolRunStateInfo> getPoolRunState(@PathVariable("threadPoolId") String threadPoolId) { public Result<ThreadPoolRunStateInfo> getPoolRunState(@PathVariable("threadPoolId") String threadPoolId) {
ThreadPoolRunStateInfo poolRunState = threadPoolRunStateHandler.getPoolRunState(threadPoolId); ThreadPoolRunStateInfo result = threadPoolRunStateHandler.getPoolRunState(threadPoolId);
return Results.success(poolRunState); return Results.success(result);
} }
@GetMapping("/run/thread/state/{threadPoolId}") @GetMapping("/run/thread/state/{threadPoolId}")
public Result<List<ThreadDetailStateInfo>> getThreadStateDetail(@PathVariable("threadPoolId") String threadPoolId) { public Result<List<ThreadDetailStateInfo>> getThreadStateDetail(@PathVariable("threadPoolId") String threadPoolId) {
List<ThreadDetailStateInfo> detailStateInfo = threadDetailState.getThreadDetailStateInfo(threadPoolId); List<ThreadDetailStateInfo> result = threadDetailState.getThreadDetailStateInfo(threadPoolId);
return Results.success(detailStateInfo); return Results.success(result);
} }
} }

@ -44,50 +44,50 @@ public class BaseThreadDetailStateHandler implements ThreadDetailState {
@Override @Override
public List<ThreadDetailStateInfo> getThreadDetailStateInfo(String threadPoolId) { public List<ThreadDetailStateInfo> getThreadDetailStateInfo(String threadPoolId) {
DynamicThreadPoolWrapper poolWrapper = GlobalThreadPoolManage.getExecutorService(threadPoolId); DynamicThreadPoolWrapper dynamicThreadPoolWrapper = GlobalThreadPoolManage.getExecutorService(threadPoolId);
ThreadPoolExecutor executor = poolWrapper.getExecutor(); ThreadPoolExecutor threadPoolExecutor = dynamicThreadPoolWrapper.getExecutor();
return getThreadDetailStateInfo(executor); return getThreadDetailStateInfo(threadPoolExecutor);
} }
@Override @Override
public List<ThreadDetailStateInfo> getThreadDetailStateInfo(ThreadPoolExecutor threadPoolExecutor) { public List<ThreadDetailStateInfo> getThreadDetailStateInfo(ThreadPoolExecutor threadPoolExecutor) {
List<ThreadDetailStateInfo> resultThreadState = new ArrayList(); List<ThreadDetailStateInfo> resultThreadStates = new ArrayList();
try { try {
// TODO: Should the object be copied deeply to avoid the destruction of the worker
HashSet<Object> workers = (HashSet<Object>) ReflectUtil.getFieldValue(threadPoolExecutor, WORKERS); HashSet<Object> workers = (HashSet<Object>) ReflectUtil.getFieldValue(threadPoolExecutor, WORKERS);
if (CollectionUtil.isEmpty(workers)) { if (CollectionUtil.isEmpty(workers)) {
return resultThreadState; return resultThreadStates;
} }
for (Object worker : workers) { for (Object worker : workers) {
Thread thread; Thread thread;
try { try {
thread = (Thread) ReflectUtil.getFieldValue(worker, THREAD); thread = (Thread) ReflectUtil.getFieldValue(worker, THREAD);
if (thread == null) { if (thread == null) {
log.warn("Reflection get worker thread is null. Worker :: {}", worker); log.warn("Reflection get worker thread is null. Worker: {}", worker);
continue; continue;
} }
} catch (Exception ex) { } catch (Exception ex) {
log.error("Reflection get worker thread exception. Worker :: {}", worker, ex); log.error("Reflection get worker thread exception. Worker: {}", worker, ex);
continue; continue;
} }
long threadId = thread.getId(); long threadId = thread.getId();
String threadName = thread.getName(); String threadName = thread.getName();
String threadStatus = thread.getState().name(); String threadStatus = thread.getState().name();
StackTraceElement[] stackTrace = thread.getStackTrace(); StackTraceElement[] stackTrace = thread.getStackTrace();
List<String> stacks = new ArrayList(stackTrace.length); List<String> threadStack = new ArrayList(stackTrace.length);
for (int i = 0; i < stackTrace.length; i++) { for (int i = 0; i < stackTrace.length; i++) {
stacks.add(stackTrace[i].toString()); threadStack.add(stackTrace[i].toString());
} }
ThreadDetailStateInfo threadState = new ThreadDetailStateInfo(); ThreadDetailStateInfo threadState = ThreadDetailStateInfo.builder()
threadState.setThreadId(threadId) .threadId(threadId)
.setThreadName(threadName) .threadName(threadName)
.setThreadStatus(threadStatus) .threadStatus(threadStatus)
.setThreadStack(stacks); .threadStack(threadStack)
resultThreadState.add(threadState); .build();
resultThreadStates.add(threadState);
} }
} catch (Exception ex) { } catch (Exception ex) {
log.error("Failed to get thread status.", ex); log.error("Failed to get thread status.", ex);
} }
return resultThreadState; return resultThreadStates;
} }
} }

@ -22,6 +22,8 @@ import cn.hippo4j.springboot.starter.wrapper.ManagerListenerWrapper;
import cn.hippo4j.common.toolkit.ContentUtil; import cn.hippo4j.common.toolkit.ContentUtil;
import cn.hippo4j.common.toolkit.Md5Util; import cn.hippo4j.common.toolkit.Md5Util;
import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.constant.Constants;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -32,6 +34,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
@Slf4j @Slf4j
public class CacheData { public class CacheData {
@Getter
public volatile String md5; public volatile String md5;
public volatile String content; public volatile String content;
@ -40,21 +43,23 @@ public class CacheData {
public final String itemId; public final String itemId;
public final String tpId; public final String threadPoolId;
@Setter
private int taskId; private int taskId;
@Setter
private volatile boolean isInitializing = true; private volatile boolean isInitializing = true;
private volatile long localConfigLastModified; private volatile long localConfigLastModified;
private final CopyOnWriteArrayList<ManagerListenerWrapper> listeners; private final CopyOnWriteArrayList<ManagerListenerWrapper> listeners;
public CacheData(String tenantId, String itemId, String tpId) { public CacheData(String tenantId, String itemId, String threadPoolId) {
this.tenantId = tenantId; this.tenantId = tenantId;
this.itemId = itemId; this.itemId = itemId;
this.tpId = tpId; this.threadPoolId = threadPoolId;
this.content = ContentUtil.getPoolContent(GlobalThreadPoolManage.getPoolParameter(tpId)); this.content = ContentUtil.getPoolContent(GlobalThreadPoolManage.getPoolParameter(threadPoolId));
this.md5 = getMd5String(content); this.md5 = getMd5String(content);
this.listeners = new CopyOnWriteArrayList(); this.listeners = new CopyOnWriteArrayList();
} }
@ -65,28 +70,28 @@ public class CacheData {
} }
ManagerListenerWrapper managerListenerWrap = new ManagerListenerWrapper(md5, listener); ManagerListenerWrapper managerListenerWrap = new ManagerListenerWrapper(md5, listener);
if (listeners.addIfAbsent(managerListenerWrap)) { if (listeners.addIfAbsent(managerListenerWrap)) {
log.info("Add listener status :: ok, thread pool id :: {}, listeners count :: {}", tpId, listeners.size()); log.info("Add listener status: ok, thread pool id: {}, listeners count: {}", threadPoolId, listeners.size());
} }
} }
public void checkListenerMd5() { public void checkListenerMd5() {
for (ManagerListenerWrapper wrap : listeners) { for (ManagerListenerWrapper managerListenerWrapper : listeners) {
if (!md5.equals(wrap.getLastCallMd5())) { if (!md5.equals(managerListenerWrapper.getLastCallMd5())) {
safeNotifyListener(content, md5, wrap); safeNotifyListener(content, md5, managerListenerWrapper);
} }
} }
} }
private void safeNotifyListener(String content, String md5, ManagerListenerWrapper wrap) { private void safeNotifyListener(String content, String md5, ManagerListenerWrapper managerListenerWrapper) {
Listener listener = wrap.getListener(); Listener listener = managerListenerWrapper.getListener();
Runnable runnable = () -> { Runnable runnable = () -> {
wrap.setLastCallMd5(md5); managerListenerWrapper.setLastCallMd5(md5);
listener.receiveConfigInfo(content); listener.receiveConfigInfo(content);
}; };
try { try {
listener.getExecutor().execute(runnable); listener.getExecutor().execute(runnable);
} catch (Exception ex) { } catch (Exception ex) {
log.error("Failed to execute listener. message :: {}", ex.getMessage()); log.error("Failed to execute listener. message: {}", ex.getMessage());
} }
} }
@ -99,19 +104,7 @@ public class CacheData {
return (null == config) ? Constants.NULL : Md5Util.md5Hex(config, Constants.ENCODE); return (null == config) ? Constants.NULL : Md5Util.md5Hex(config, Constants.ENCODE);
} }
public String getMd5() {
return this.md5;
}
public void setTaskId(Integer taskId) {
this.taskId = taskId;
}
public boolean isInitializing() { public boolean isInitializing() {
return isInitializing; return isInitializing;
} }
public void setInitializing(boolean isInitializing) {
this.isInitializing = isInitializing;
}
} }

@ -48,7 +48,7 @@ public class ClientWorker {
private final HttpAgent agent; private final HttpAgent agent;
private final String identification; private final String identify;
private final ServerHealthCheck serverHealthCheck; private final ServerHealthCheck serverHealthCheck;
@ -61,26 +61,26 @@ public class ClientWorker {
private final ConcurrentHashMap<String, CacheData> cacheMap = new ConcurrentHashMap(16); private final ConcurrentHashMap<String, CacheData> cacheMap = new ConcurrentHashMap(16);
@SuppressWarnings("all") @SuppressWarnings("all")
public ClientWorker(HttpAgent httpAgent, String identification, ServerHealthCheck serverHealthCheck) { public ClientWorker(HttpAgent httpAgent, String identify, ServerHealthCheck serverHealthCheck) {
this.agent = httpAgent; this.agent = httpAgent;
this.identification = identification; this.identify = identify;
this.timeout = CONFIG_LONG_POLL_TIMEOUT; this.timeout = CONFIG_LONG_POLL_TIMEOUT;
this.serverHealthCheck = serverHealthCheck; this.serverHealthCheck = serverHealthCheck;
this.executor = Executors.newScheduledThreadPool(1, r -> { this.executor = Executors.newScheduledThreadPool(1, runnable -> {
Thread t = new Thread(r); Thread thread = new Thread(runnable);
t.setName("client.worker.executor"); thread.setName("client.worker.executor");
t.setDaemon(true); thread.setDaemon(true);
return t; return thread;
}); });
this.executorService = Executors.newSingleThreadScheduledExecutor( this.executorService = Executors.newSingleThreadScheduledExecutor(
ThreadFactoryBuilder.builder().prefix("client.long.polling.executor").daemon(true).build()); ThreadFactoryBuilder.builder().prefix("client.long.polling.executor").daemon(true).build());
log.info("Client identity :: {}", identification); log.info("Client identify: {}", identify);
this.executor.scheduleWithFixedDelay(() -> { this.executor.scheduleWithFixedDelay(() -> {
try { try {
awaitApplicationComplete.await(); awaitApplicationComplete.await();
checkConfigInfo(); checkConfigInfo();
} catch (Throwable e) { } catch (Throwable ex) {
log.error("Sub check rotate check error.", e); log.error("Sub check rotate check error.", ex);
} }
}, 1L, 1024L, TimeUnit.MILLISECONDS); }, 1L, 1024L, TimeUnit.MILLISECONDS);
} }
@ -123,7 +123,7 @@ public class ClientWorker {
} }
for (CacheData cacheData : cacheDataList) { for (CacheData cacheData : cacheDataList) {
if (!cacheData.isInitializing() || inInitializingCacheList if (!cacheData.isInitializing() || inInitializingCacheList
.contains(GroupKey.getKeyTenant(cacheData.tpId, cacheData.itemId, cacheData.tenantId))) { .contains(GroupKey.getKeyTenant(cacheData.threadPoolId, cacheData.itemId, cacheData.tenantId))) {
cacheData.checkListenerMd5(); cacheData.checkListenerMd5();
cacheData.setInitializing(false); cacheData.setInitializing(false);
} }
@ -136,13 +136,13 @@ public class ClientWorker {
private List<String> checkUpdateDataIds(List<CacheData> cacheDataList, List<String> inInitializingCacheList) { private List<String> checkUpdateDataIds(List<CacheData> cacheDataList, List<String> inInitializingCacheList) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (CacheData cacheData : cacheDataList) { for (CacheData cacheData : cacheDataList) {
sb.append(cacheData.tpId).append(WORD_SEPARATOR); sb.append(cacheData.threadPoolId).append(WORD_SEPARATOR);
sb.append(cacheData.itemId).append(WORD_SEPARATOR); sb.append(cacheData.itemId).append(WORD_SEPARATOR);
sb.append(cacheData.tenantId).append(WORD_SEPARATOR); sb.append(cacheData.tenantId).append(WORD_SEPARATOR);
sb.append(identification).append(WORD_SEPARATOR); sb.append(identify).append(WORD_SEPARATOR);
sb.append(cacheData.getMd5()).append(LINE_SEPARATOR); sb.append(cacheData.getMd5()).append(LINE_SEPARATOR);
if (cacheData.isInitializing()) { if (cacheData.isInitializing()) {
inInitializingCacheList.add(GroupKey.getKeyTenant(cacheData.tpId, cacheData.itemId, cacheData.tenantId)); inInitializingCacheList.add(GroupKey.getKeyTenant(cacheData.threadPoolId, cacheData.itemId, cacheData.tenantId));
} }
} }
boolean isInitializingCacheList = !inInitializingCacheList.isEmpty(); boolean isInitializingCacheList = !inInitializingCacheList.isEmpty();
@ -156,7 +156,7 @@ public class ClientWorker {
Map<String, String> headers = new HashMap(2); Map<String, String> headers = new HashMap(2);
headers.put(LONG_PULLING_TIMEOUT, "" + timeout); headers.put(LONG_PULLING_TIMEOUT, "" + timeout);
// Confirm the identity of the client, and can be modified separately when modifying the thread pool configuration. // Confirm the identity of the client, and can be modified separately when modifying the thread pool configuration.
headers.put(LONG_PULLING_CLIENT_IDENTIFICATION, identification); headers.put(LONG_PULLING_CLIENT_IDENTIFICATION, identify);
// told server do not hang me up if new initializing cacheData added in // told server do not hang me up if new initializing cacheData added in
if (isInitializingCacheList) { if (isInitializingCacheList) {
headers.put(LONG_PULLING_TIMEOUT_NO_HANGUP, "true"); headers.put(LONG_PULLING_TIMEOUT_NO_HANGUP, "true");
@ -172,23 +172,22 @@ public class ClientWorker {
} }
} catch (Exception ex) { } catch (Exception ex) {
setHealthServer(false); setHealthServer(false);
log.error("Check update get changed dataId exception. error message :: {}", ex.getMessage()); log.error("Check update get changed dataId exception. error message: {}", ex.getMessage());
} }
return Collections.emptyList(); return Collections.emptyList();
} }
public String getServerConfig(String namespace, String itemId, String tpId, long readTimeout) { public String getServerConfig(String namespace, String itemId, String threadPoolId, long readTimeout) {
Map<String, String> params = new HashMap(3); Map<String, String> params = new HashMap(3);
params.put("namespace", namespace); params.put("namespace", namespace);
params.put("itemId", itemId); params.put("itemId", itemId);
params.put("tpId", tpId); params.put("tpId", threadPoolId);
params.put("instanceId", identification); params.put("instanceId", identify);
Result result = agent.httpGetByConfig(CONFIG_CONTROLLER_PATH, null, params, readTimeout); Result result = agent.httpGetByConfig(CONFIG_CONTROLLER_PATH, null, params, readTimeout);
if (result.isSuccess()) { if (result.isSuccess()) {
return JSONUtil.toJSONString(result.getData()); return JSONUtil.toJSONString(result.getData());
} }
log.error("Sub server namespace :: {}, itemId :: {}, tpId :: {}, result code :: {}", log.error("Sub server namespace: {}, itemId: {}, threadPoolId: {}, result code: {}", namespace, itemId, threadPoolId, result.getCode());
namespace, itemId, tpId, result.getCode());
return NULL; return NULL;
} }
@ -219,28 +218,28 @@ public class ClientWorker {
return updateList; return updateList;
} }
public void addTenantListeners(String namespace, String itemId, String tpId, List<? extends Listener> listeners) { public void addTenantListeners(String namespace, String itemId, String threadPoolId, List<? extends Listener> listeners) {
CacheData cacheData = addCacheDataIfAbsent(namespace, itemId, tpId); CacheData cacheData = addCacheDataIfAbsent(namespace, itemId, threadPoolId);
for (Listener listener : listeners) { for (Listener listener : listeners) {
cacheData.addListener(listener); cacheData.addListener(listener);
} }
} }
public CacheData addCacheDataIfAbsent(String namespace, String itemId, String tpId) { public CacheData addCacheDataIfAbsent(String namespace, String itemId, String threadPoolId) {
CacheData cacheData = cacheMap.get(tpId); CacheData cacheData = cacheMap.get(threadPoolId);
if (cacheData != null) { if (cacheData != null) {
return cacheData; return cacheData;
} }
cacheData = new CacheData(namespace, itemId, tpId); cacheData = new CacheData(namespace, itemId, threadPoolId);
CacheData lastCacheData = cacheMap.putIfAbsent(tpId, cacheData); CacheData lastCacheData = cacheMap.putIfAbsent(threadPoolId, cacheData);
if (lastCacheData == null) { if (lastCacheData == null) {
String serverConfig; String serverConfig;
try { try {
serverConfig = getServerConfig(namespace, itemId, tpId, 3000L); serverConfig = getServerConfig(namespace, itemId, threadPoolId, 3000L);
ThreadPoolParameterInfo poolInfo = JSONUtil.parseObject(serverConfig, ThreadPoolParameterInfo.class); ThreadPoolParameterInfo poolInfo = JSONUtil.parseObject(serverConfig, ThreadPoolParameterInfo.class);
cacheData.setContent(ContentUtil.getPoolContent(poolInfo)); cacheData.setContent(ContentUtil.getPoolContent(poolInfo));
} catch (Exception ex) { } catch (Exception ex) {
log.error("Cache Data Error. Service Unavailable :: {}", ex.getMessage()); log.error("Cache Data Error. Service Unavailable: {}", ex.getMessage());
} }
int taskId = cacheMap.size() / CONFIG_LONG_POLL_TIMEOUT; int taskId = cacheMap.size() / CONFIG_LONG_POLL_TIMEOUT;
cacheData.setTaskId(taskId); cacheData.setTaskId(taskId);

@ -27,7 +27,7 @@ import org.springframework.boot.diagnostics.FailureAnalysis;
public class ConfigEmptyAnalyzer extends AbstractFailureAnalyzer<ConfigEmptyException> { public class ConfigEmptyAnalyzer extends AbstractFailureAnalyzer<ConfigEmptyException> {
@Override @Override
protected FailureAnalysis analyze(Throwable rootFailure, ConfigEmptyException cause) { protected FailureAnalysis analyze(Throwable rootFailure, ConfigEmptyException configEmptyException) {
return new FailureAnalysis(cause.getDescription(), cause.getAction(), cause); return new FailureAnalysis(configEmptyException.getDescription(), configEmptyException.getAction(), configEmptyException);
} }
} }

@ -27,10 +27,10 @@ public interface ConfigService {
* *
* @param tenantId * @param tenantId
* @param itemId * @param itemId
* @param tpId * @param threadPoolId
* @param listener * @param listener
*/ */
void addListener(String tenantId, String itemId, String tpId, Listener listener); void addListener(String tenantId, String itemId, String threadPoolId, Listener listener);
/** /**
* Get server status. * Get server status.

@ -63,7 +63,7 @@ public class DiscoveryClient implements DisposableBean {
new Integer(1), new Integer(1),
ThreadFactoryBuilder.builder().daemon(true).prefix("client.discovery.scheduler").build()); ThreadFactoryBuilder.builder().daemon(true).prefix("client.discovery.scheduler").build());
register(); register();
// init the schedule tasks // Init the schedule tasks.
initScheduledTasks(); initScheduledTasks();
} }
@ -79,10 +79,10 @@ public class DiscoveryClient implements DisposableBean {
registerResult = httpAgent.httpPostByDiscovery(urlPath, instanceInfo); registerResult = httpAgent.httpPostByDiscovery(urlPath, instanceInfo);
} catch (Exception ex) { } catch (Exception ex) {
registerResult = Results.failure(ErrorCodeEnum.SERVICE_ERROR); registerResult = Results.failure(ErrorCodeEnum.SERVICE_ERROR);
log.error("{}{} - registration failed :: {}", PREFIX, appPathIdentifier, ex.getMessage()); log.error("{}{} - registration failed: {}", PREFIX, appPathIdentifier, ex.getMessage());
} }
if (log.isInfoEnabled()) { if (log.isInfoEnabled()) {
log.info("{}{} - registration status :: {}", PREFIX, appPathIdentifier, registerResult.isSuccess() ? "success" : "fail"); log.info("{}{} - registration status: {}", PREFIX, appPathIdentifier, registerResult.isSuccess() ? "success" : "fail");
} }
return registerResult.isSuccess(); return registerResult.isSuccess();
} }
@ -124,7 +124,7 @@ public class DiscoveryClient implements DisposableBean {
} }
} }
boolean renew() { private boolean renew() {
Result renewResult; Result renewResult;
try { try {
InstanceInfo.InstanceRenew instanceRenew = new InstanceInfo.InstanceRenew() InstanceInfo.InstanceRenew instanceRenew = new InstanceInfo.InstanceRenew()

@ -21,6 +21,7 @@ import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.constant.Constants; import cn.hippo4j.common.constant.Constants;
import cn.hippo4j.common.enums.EnableEnum; import cn.hippo4j.common.enums.EnableEnum;
import cn.hippo4j.common.model.ThreadPoolParameterInfo; import cn.hippo4j.common.model.ThreadPoolParameterInfo;
import cn.hippo4j.common.toolkit.BooleanUtil;
import cn.hippo4j.common.toolkit.JSONUtil; import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.web.base.Result; import cn.hippo4j.common.web.base.Result;
import cn.hippo4j.core.executor.DynamicThreadPool; import cn.hippo4j.core.executor.DynamicThreadPool;
@ -33,7 +34,6 @@ import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil;
import cn.hippo4j.message.service.ThreadPoolNotifyAlarm; import cn.hippo4j.message.service.ThreadPoolNotifyAlarm;
import cn.hippo4j.springboot.starter.config.BootstrapProperties; import cn.hippo4j.springboot.starter.config.BootstrapProperties;
import cn.hippo4j.springboot.starter.remote.HttpAgent; import cn.hippo4j.springboot.starter.remote.HttpAgent;
import cn.hutool.core.util.BooleanUtil;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
@ -63,7 +63,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
private final ThreadPoolOperation threadPoolOperation; private final ThreadPoolOperation threadPoolOperation;
private final ServerThreadPoolDynamicRefresh threadPoolDynamicRefresh; private final ServerThreadPoolDynamicRefresh serverThreadPoolDynamicRefresh;
@Override @Override
public Object postProcessBeforeInitialization(Object bean, String beanName) { public Object postProcessBeforeInitialization(Object bean, String beanName) {
@ -88,14 +88,14 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
return bean; return bean;
} }
DynamicThreadPoolExecutor dynamicThreadPoolExecutor = (DynamicThreadPoolExecutor) bean; DynamicThreadPoolExecutor dynamicThreadPoolExecutor = (DynamicThreadPoolExecutor) bean;
DynamicThreadPoolWrapper wrap = new DynamicThreadPoolWrapper(dynamicThreadPoolExecutor.getThreadPoolId(), dynamicThreadPoolExecutor); DynamicThreadPoolWrapper dynamicThreadPoolWrapper = new DynamicThreadPoolWrapper(dynamicThreadPoolExecutor.getThreadPoolId(), dynamicThreadPoolExecutor);
ThreadPoolExecutor remoteExecutor = fillPoolAndRegister(wrap); ThreadPoolExecutor remoteThreadPoolExecutor = fillPoolAndRegister(dynamicThreadPoolWrapper);
subscribeConfig(wrap); subscribeConfig(dynamicThreadPoolWrapper);
return remoteExecutor; return remoteThreadPoolExecutor;
} }
if (bean instanceof DynamicThreadPoolWrapper) { if (bean instanceof DynamicThreadPoolWrapper) {
DynamicThreadPoolWrapper wrap = (DynamicThreadPoolWrapper) bean; DynamicThreadPoolWrapper dynamicThreadPoolWrapper = (DynamicThreadPoolWrapper) bean;
registerAndSubscribe(wrap); registerAndSubscribe(dynamicThreadPoolWrapper);
} }
return bean; return bean;
} }
@ -103,22 +103,22 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
/** /**
* Register and subscribe. * Register and subscribe.
* *
* @param dynamicThreadPoolWrap * @param dynamicThreadPoolWrapper
*/ */
protected void registerAndSubscribe(DynamicThreadPoolWrapper dynamicThreadPoolWrap) { protected void registerAndSubscribe(DynamicThreadPoolWrapper dynamicThreadPoolWrapper) {
fillPoolAndRegister(dynamicThreadPoolWrap); fillPoolAndRegister(dynamicThreadPoolWrapper);
subscribeConfig(dynamicThreadPoolWrap); subscribeConfig(dynamicThreadPoolWrapper);
} }
/** /**
* Fill the thread pool and register. * Fill the thread pool and register.
* *
* @param dynamicThreadPoolWrap * @param dynamicThreadPoolWrapper
*/ */
protected ThreadPoolExecutor fillPoolAndRegister(DynamicThreadPoolWrapper dynamicThreadPoolWrap) { protected ThreadPoolExecutor fillPoolAndRegister(DynamicThreadPoolWrapper dynamicThreadPoolWrapper) {
String tpId = dynamicThreadPoolWrap.getThreadPoolId(); String threadPoolId = dynamicThreadPoolWrapper.getThreadPoolId();
Map<String, String> queryStrMap = new HashMap(3); Map<String, String> queryStrMap = new HashMap(3);
queryStrMap.put(TP_ID, tpId); queryStrMap.put(TP_ID, threadPoolId);
queryStrMap.put(ITEM_ID, properties.getItemId()); queryStrMap.put(ITEM_ID, properties.getItemId());
queryStrMap.put(NAMESPACE, properties.getNamespace()); queryStrMap.put(NAMESPACE, properties.getNamespace());
boolean isSubscribe = false; boolean isSubscribe = false;
@ -134,43 +134,43 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
newDynamicThreadPoolExecutor = ThreadPoolBuilder.builder() newDynamicThreadPoolExecutor = ThreadPoolBuilder.builder()
.dynamicPool() .dynamicPool()
.workQueue(workQueue) .workQueue(workQueue)
.threadFactory(tpId) .threadFactory(threadPoolId)
.poolThreadSize(threadPoolParameterInfo.corePoolSizeAdapt(), threadPoolParameterInfo.maximumPoolSizeAdapt()) .poolThreadSize(threadPoolParameterInfo.corePoolSizeAdapt(), threadPoolParameterInfo.maximumPoolSizeAdapt())
.keepAliveTime(threadPoolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS) .keepAliveTime(threadPoolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS)
.rejected(RejectedTypeEnum.createPolicy(threadPoolParameterInfo.getRejectedType())) .rejected(RejectedTypeEnum.createPolicy(threadPoolParameterInfo.getRejectedType()))
.allowCoreThreadTimeOut(EnableEnum.getBool(threadPoolParameterInfo.getAllowCoreThreadTimeOut())) .allowCoreThreadTimeOut(EnableEnum.getBool(threadPoolParameterInfo.getAllowCoreThreadTimeOut()))
.build(); .build();
// Set dynamic thread pool enhancement parameters. // Set dynamic thread pool enhancement parameters.
if (dynamicThreadPoolWrap.getExecutor() instanceof AbstractDynamicExecutorSupport) { if (dynamicThreadPoolWrapper.getExecutor() instanceof AbstractDynamicExecutorSupport) {
ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm( ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm(
BooleanUtil.toBoolean(threadPoolParameterInfo.getIsAlarm().toString()), BooleanUtil.toBoolean(threadPoolParameterInfo.getIsAlarm().toString()),
threadPoolParameterInfo.getCapacityAlarm(), threadPoolParameterInfo.getCapacityAlarm(),
threadPoolParameterInfo.getLivenessAlarm()); threadPoolParameterInfo.getLivenessAlarm());
GlobalNotifyAlarmManage.put(tpId, threadPoolNotifyAlarm); GlobalNotifyAlarmManage.put(threadPoolId, threadPoolNotifyAlarm);
TaskDecorator taskDecorator = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).getTaskDecorator(); TaskDecorator taskDecorator = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrapper.getExecutor()).getTaskDecorator();
((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setTaskDecorator(taskDecorator); ((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setTaskDecorator(taskDecorator);
long awaitTerminationMillis = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).awaitTerminationMillis; long awaitTerminationMillis = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrapper.getExecutor()).awaitTerminationMillis;
boolean waitForTasksToCompleteOnShutdown = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).waitForTasksToCompleteOnShutdown; boolean waitForTasksToCompleteOnShutdown = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrapper.getExecutor()).waitForTasksToCompleteOnShutdown;
((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setSupportParam(awaitTerminationMillis, waitForTasksToCompleteOnShutdown); ((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setSupportParam(awaitTerminationMillis, waitForTasksToCompleteOnShutdown);
long executeTimeOut = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrap.getExecutor()).getExecuteTimeOut(); long executeTimeOut = ((DynamicThreadPoolExecutor) dynamicThreadPoolWrapper.getExecutor()).getExecuteTimeOut();
((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setExecuteTimeOut(executeTimeOut); ((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setExecuteTimeOut(executeTimeOut);
} }
dynamicThreadPoolWrap.setExecutor(newDynamicThreadPoolExecutor); dynamicThreadPoolWrapper.setExecutor(newDynamicThreadPoolExecutor);
isSubscribe = true; isSubscribe = true;
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
newDynamicThreadPoolExecutor = dynamicThreadPoolWrap.getExecutor() != null ? dynamicThreadPoolWrap.getExecutor() : CommonDynamicThreadPool.getInstance(tpId); newDynamicThreadPoolExecutor = dynamicThreadPoolWrapper.getExecutor() != null ? dynamicThreadPoolWrapper.getExecutor() : CommonDynamicThreadPool.getInstance(threadPoolId);
dynamicThreadPoolWrap.setExecutor(newDynamicThreadPoolExecutor); dynamicThreadPoolWrapper.setExecutor(newDynamicThreadPoolExecutor);
log.error("Failed to initialize thread pool configuration. error message :: {}", ex.getMessage()); log.error("Failed to initialize thread pool configuration. error message: {}", ex.getMessage());
} finally { } finally {
if (Objects.isNull(dynamicThreadPoolWrap.getExecutor())) { if (Objects.isNull(dynamicThreadPoolWrapper.getExecutor())) {
dynamicThreadPoolWrap.setExecutor(CommonDynamicThreadPool.getInstance(tpId)); dynamicThreadPoolWrapper.setExecutor(CommonDynamicThreadPool.getInstance(threadPoolId));
} }
// Set whether to subscribe to the remote thread pool configuration. // Set whether to subscribe to the remote thread pool configuration.
dynamicThreadPoolWrap.setSubscribeFlag(isSubscribe); dynamicThreadPoolWrapper.setSubscribeFlag(isSubscribe);
} }
GlobalThreadPoolManage.register(dynamicThreadPoolWrap.getThreadPoolId(), threadPoolParameterInfo, dynamicThreadPoolWrap); GlobalThreadPoolManage.register(dynamicThreadPoolWrapper.getThreadPoolId(), threadPoolParameterInfo, dynamicThreadPoolWrapper);
return newDynamicThreadPoolExecutor; return newDynamicThreadPoolExecutor;
} }
@ -192,7 +192,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
*/ */
protected void subscribeConfig(DynamicThreadPoolWrapper dynamicThreadPoolWrap) { protected void subscribeConfig(DynamicThreadPoolWrapper dynamicThreadPoolWrap) {
if (dynamicThreadPoolWrap.isSubscribeFlag()) { if (dynamicThreadPoolWrap.isSubscribeFlag()) {
threadPoolOperation.subscribeConfig(dynamicThreadPoolWrap.getThreadPoolId(), configRefreshExecutorService, config -> threadPoolDynamicRefresh.dynamicRefresh(config)); threadPoolOperation.subscribeConfig(dynamicThreadPoolWrap.getThreadPoolId(), configRefreshExecutorService, config -> serverThreadPoolDynamicRefresh.dynamicRefresh(config));
} }
} }
} }

@ -145,7 +145,7 @@ public class ServerThreadPoolDynamicRefresh implements ThreadPoolDynamicRefresh
ResizableCapacityLinkedBlockingQueue queue = (ResizableCapacityLinkedBlockingQueue) executor.getQueue(); ResizableCapacityLinkedBlockingQueue queue = (ResizableCapacityLinkedBlockingQueue) executor.getQueue();
queue.setCapacity(parameter.getCapacity()); queue.setCapacity(parameter.getCapacity());
} else { } else {
log.warn("The queue length cannot be modified. Queue type mismatch. Current queue type :: {}", executor.getQueue().getClass().getSimpleName()); log.warn("The queue length cannot be modified. Queue type mismatch. Current queue type: {}", executor.getQueue().getClass().getSimpleName());
} }
} }
if (parameter.getKeepAliveTime() != null) { if (parameter.getKeepAliveTime() != null) {

@ -17,7 +17,10 @@
package cn.hippo4j.springboot.starter.core; package cn.hippo4j.springboot.starter.core;
import cn.hippo4j.adapter.base.*; import cn.hippo4j.adapter.base.ThreadPoolAdapter;
import cn.hippo4j.adapter.base.ThreadPoolAdapterCacheConfig;
import cn.hippo4j.adapter.base.ThreadPoolAdapterRegisterAction;
import cn.hippo4j.adapter.base.ThreadPoolAdapterState;
import cn.hippo4j.common.config.ApplicationContextHolder; import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.toolkit.CollectionUtil; import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.web.base.Result; import cn.hippo4j.common.web.base.Result;
@ -28,7 +31,6 @@ import cn.hippo4j.springboot.starter.remote.HttpAgent;
import cn.hippo4j.springboot.starter.toolkit.CloudCommonIdUtil; import cn.hippo4j.springboot.starter.toolkit.CloudCommonIdUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner; import org.springframework.boot.ApplicationRunner;
@ -36,9 +38,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL; import static cn.hippo4j.common.constant.Constants.IDENTIFY_SLICER_SYMBOL;
import static cn.hippo4j.common.constant.Constants.REGISTER_ADAPTER_PATH; import static cn.hippo4j.common.constant.Constants.REGISTER_ADAPTER_PATH;
@ -65,24 +64,24 @@ public class ThreadPoolAdapterRegister implements ApplicationRunner, ThreadPoolA
@Override @Override
public List<ThreadPoolAdapterCacheConfig> getThreadPoolAdapterCacheConfigs(Map<String, ThreadPoolAdapter> threadPoolAdapterMap) { public List<ThreadPoolAdapterCacheConfig> getThreadPoolAdapterCacheConfigs(Map<String, ThreadPoolAdapter> threadPoolAdapterMap) {
List<ThreadPoolAdapterCacheConfig> cacheConfigList = Lists.newArrayList(); List<ThreadPoolAdapterCacheConfig> adapterCacheConfigList = Lists.newArrayList();
for (Map.Entry<String, ThreadPoolAdapter> threadPoolAdapterEntry : threadPoolAdapterMap.entrySet()) { for (Map.Entry<String, ThreadPoolAdapter> threadPoolAdapterEntry : threadPoolAdapterMap.entrySet()) {
ThreadPoolAdapter val = threadPoolAdapterEntry.getValue(); ThreadPoolAdapter threadPoolAdapter = threadPoolAdapterEntry.getValue();
List<ThreadPoolAdapterState> threadPoolStates = val.getThreadPoolStates(); List<ThreadPoolAdapterState> threadPoolStates = threadPoolAdapter.getThreadPoolStates();
if (CollectionUtil.isEmpty(threadPoolStates) || threadPoolStates.size() == 0) { if (CollectionUtil.isEmpty(threadPoolStates) || threadPoolStates.size() == 0) {
continue; continue;
} }
ThreadPoolAdapterCacheConfig cacheConfig = new ThreadPoolAdapterCacheConfig(); ThreadPoolAdapterCacheConfig cacheConfig = new ThreadPoolAdapterCacheConfig();
cacheConfig.setMark(val.mark()); cacheConfig.setMark(threadPoolAdapter.mark());
String tenantItemKey = properties.getNamespace() + IDENTIFY_SLICER_SYMBOL + properties.getItemId(); String tenantItemKey = properties.getNamespace() + IDENTIFY_SLICER_SYMBOL + properties.getItemId();
cacheConfig.setTenantItemKey(tenantItemKey); cacheConfig.setTenantItemKey(tenantItemKey);
cacheConfig.setClientIdentify(IdentifyUtil.getIdentify()); cacheConfig.setClientIdentify(IdentifyUtil.getIdentify());
String clientAddress = CloudCommonIdUtil.getClientIpPort(environment, hippo4JInetUtils); String clientAddress = CloudCommonIdUtil.getClientIpPort(environment, hippo4JInetUtils);
cacheConfig.setClientAddress(clientAddress); cacheConfig.setClientAddress(clientAddress);
cacheConfig.setThreadPoolAdapterStates(threadPoolStates); cacheConfig.setThreadPoolAdapterStates(threadPoolStates);
cacheConfigList.add(cacheConfig); adapterCacheConfigList.add(cacheConfig);
} }
return cacheConfigList; return adapterCacheConfigList;
} }
@Override @Override

@ -33,14 +33,14 @@ public class ThreadPoolConfigService implements ConfigService, ApplicationListen
private final ServerHealthCheck serverHealthCheck; private final ServerHealthCheck serverHealthCheck;
public ThreadPoolConfigService(HttpAgent httpAgent, String identification, ServerHealthCheck serverHealthCheck) { public ThreadPoolConfigService(HttpAgent httpAgent, String identify, ServerHealthCheck serverHealthCheck) {
this.serverHealthCheck = serverHealthCheck; this.serverHealthCheck = serverHealthCheck;
this.clientWorker = new ClientWorker(httpAgent, identification, serverHealthCheck); this.clientWorker = new ClientWorker(httpAgent, identify, serverHealthCheck);
} }
@Override @Override
public void addListener(String tenantId, String itemId, String tpId, Listener listener) { public void addListener(String tenantId, String itemId, String threadPoolId, Listener listener) {
clientWorker.addTenantListeners(tenantId, itemId, tpId, Arrays.asList(listener)); clientWorker.addTenantListeners(tenantId, itemId, threadPoolId, Arrays.asList(listener));
} }
@Override @Override

@ -35,7 +35,7 @@ public class ThreadPoolOperation {
this.configService = configService; this.configService = configService;
} }
public Listener subscribeConfig(String tpId, Executor executor, ThreadPoolSubscribeCallback threadPoolSubscribeCallback) { public Listener subscribeConfig(String threadPoolId, Executor executor, ThreadPoolSubscribeCallback threadPoolSubscribeCallback) {
Listener configListener = new Listener() { Listener configListener = new Listener() {
@Override @Override
@ -48,7 +48,7 @@ public class ThreadPoolOperation {
return executor; return executor;
} }
}; };
configService.addListener(properties.getNamespace(), properties.getItemId(), tpId, configListener); configService.addListener(properties.getNamespace(), properties.getItemId(), threadPoolId, configListener);
return configListener; return configListener;
} }
} }

@ -99,7 +99,7 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp
Message message = messageCollectVessel.take(); Message message = messageCollectVessel.take();
messageSender.send(message); messageSender.send(message);
} catch (Throwable ex) { } catch (Throwable ex) {
log.error("Consumption buffer container task failed. Number of buffer container tasks :: {}", messageCollectVessel.size(), ex); log.error("Consumption buffer container task failed. Number of buffer container tasks: {}", messageCollectVessel.size(), ex);
} }
} }
} }
@ -143,7 +143,7 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp
ThreadUtil.newThread(this, "client.thread.reporting.task", Boolean.TRUE).start(); ThreadUtil.newThread(this, "client.thread.reporting.task", Boolean.TRUE).start();
} }
if (GlobalThreadPoolManage.getThreadPoolNum() > 0) { if (GlobalThreadPoolManage.getThreadPoolNum() > 0) {
log.info("Dynamic thread pool :: [{}]. The dynamic thread pool starts data collection and reporting. ", getThreadPoolNum()); log.info("Dynamic thread pool: [{}]. The dynamic thread pool starts data collection and reporting.", getThreadPoolNum());
} }
} }

@ -64,7 +64,7 @@ public class NettyConnectSender implements MessageSender {
}); });
bootstrap.connect(serverNettyAgent.getNettyServerAddress(), serverNettyAgent.getNettyServerPort()).sync(); bootstrap.connect(serverNettyAgent.getNettyServerAddress(), serverNettyAgent.getNettyServerPort()).sync();
} catch (Exception e) { } catch (Exception e) {
log.error("netty send error ", e); log.error("Netty send error.", e);
} }
} }
} }

@ -70,7 +70,7 @@ public class ServerNotifyConfigBuilder implements NotifyConfigBuilder {
try { try {
result = httpAgent.httpPostByDiscovery(BASE_PATH + "/notify/list/config", new ThreadPoolNotifyRequest(groupKeys)); result = httpAgent.httpPostByDiscovery(BASE_PATH + "/notify/list/config", new ThreadPoolNotifyRequest(groupKeys));
} catch (Throwable ex) { } catch (Throwable ex) {
log.error("Get dynamic thread pool notify configuration error. message :: {}", ex.getMessage()); log.error("Get dynamic thread pool notify configuration error. message: {}", ex.getMessage());
} }
if (result != null && result.isSuccess() && result.getData() != null) { if (result != null && result.isSuccess() && result.getData() != null) {
String resultDataStr = JSONUtil.toJSONString(result.getData()); String resultDataStr = JSONUtil.toJSONString(result.getData());

@ -110,8 +110,7 @@ public abstract class AbstractHealthCheck implements ServerHealthCheck, Initiali
@Override @Override
@SneakyThrows @SneakyThrows
public boolean isHealthStatus() { public boolean isHealthStatus() {
while (contextInitComplete while (contextInitComplete && !healthStatus && !clientShutdownHook) {
&& !healthStatus && !clientShutdownHook) {
healthMainLock.lock(); healthMainLock.lock();
try { try {
healthCondition.await(); healthCondition.await();
@ -152,7 +151,7 @@ public abstract class AbstractHealthCheck implements ServerHealthCheck, Initiali
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
/** /**
* Add a hook function, when the client stops, if the server is in an unhealthy state, * Add a hook function, when the client stops, if the server is in an unhealthy state,
* the client destroy function will suspend operation * the client destroy function will suspend operation.
*/ */
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
clientShutdownHook = true; clientShutdownHook = true;

@ -61,8 +61,7 @@ public class SecurityProxy {
public boolean applyToken(List<String> servers) { public boolean applyToken(List<String> servers) {
try { try {
if ((System.currentTimeMillis() - lastRefreshTime) < TimeUnit.SECONDS if ((System.currentTimeMillis() - lastRefreshTime) < TimeUnit.SECONDS.toMillis(tokenTtl - tokenRefreshWindow)) {
.toMillis(tokenTtl - tokenRefreshWindow)) {
return true; return true;
} }
for (String server : servers) { for (String server : servers) {
@ -85,7 +84,7 @@ public class SecurityProxy {
try { try {
Result<String> result = httpClientUtil.restApiPost(url, bodyMap, Result.class); Result<String> result = httpClientUtil.restApiPost(url, bodyMap, Result.class);
if (!result.isSuccess()) { if (!result.isSuccess()) {
log.error("Error getting access token. message :: {}", result.getMessage()); log.error("Error getting access token. message: {}", result.getMessage());
return false; return false;
} }
String tokenJsonStr = JSONUtil.toJSONString(result.getData()); String tokenJsonStr = JSONUtil.toJSONString(result.getData());
@ -94,7 +93,7 @@ public class SecurityProxy {
tokenTtl = tokenInfo.getTokenTtl(); tokenTtl = tokenInfo.getTokenTtl();
tokenRefreshWindow = tokenTtl / 10; tokenRefreshWindow = tokenTtl / 10;
} catch (Throwable ex) { } catch (Throwable ex) {
log.error("Failed to apply for token. message :: {}", ex.getMessage()); log.error("Failed to apply for token. message: {}", ex.getMessage());
return false; return false;
} }
} }

Loading…
Cancel
Save