|
|
@ -30,7 +30,6 @@ import lombok.SneakyThrows;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
@ -43,20 +42,21 @@ import java.util.concurrent.CountDownLatch;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.CLIENT_VERSION;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.CONFIG_CONTROLLER_PATH;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.CONFIG_LONG_POLL_TIMEOUT;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.CONFIG_LONG_POLL_TIMEOUT;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.GROUP_KEY_DELIMITER_TRANSLATION;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.GROUP_KEY_DELIMITER_TRANSLATION;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.WORD_SEPARATOR;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LINE_SEPARATOR;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LINE_SEPARATOR;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LISTENER_PATH;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.PROBE_MODIFY_REQUEST;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LONG_PULLING_CLIENT_IDENTIFICATION;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.WEIGHT_CONFIGS;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LONG_PULLING_TIMEOUT;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LONG_PULLING_TIMEOUT;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LONG_PULLING_CLIENT_IDENTIFICATION;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LONG_PULLING_TIMEOUT_NO_HANGUP;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LONG_PULLING_TIMEOUT_NO_HANGUP;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.CLIENT_VERSION;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.LISTENER_PATH;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.INITIAL_CAPACITY;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.DATA_GROUP_TENANT_SIZE;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.CONFIG_CONTROLLER_PATH;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.NULL;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.NULL;
|
|
|
|
import static cn.hippo4j.common.constant.Constants.PROBE_MODIFY_REQUEST;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.WEIGHT_CONFIGS;
|
|
|
|
|
|
|
|
import static cn.hippo4j.common.constant.Constants.WORD_SEPARATOR;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Client worker.
|
|
|
|
* Client worker.
|
|
|
@ -77,6 +77,8 @@ public class ClientWorker implements DisposableBean {
|
|
|
|
private final CountDownLatch cacheCondition = new CountDownLatch(1);
|
|
|
|
private final CountDownLatch cacheCondition = new CountDownLatch(1);
|
|
|
|
private final ConcurrentHashMap<String, CacheData> cacheMap = new ConcurrentHashMap<>(16);
|
|
|
|
private final ConcurrentHashMap<String, CacheData> cacheMap = new ConcurrentHashMap<>(16);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final long defaultTimedOut = 3000L;
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("all")
|
|
|
|
@SuppressWarnings("all")
|
|
|
|
public ClientWorker(HttpAgent httpAgent,
|
|
|
|
public ClientWorker(HttpAgent httpAgent,
|
|
|
|
String identify,
|
|
|
|
String identify,
|
|
|
@ -113,13 +115,16 @@ public class ClientWorker implements DisposableBean {
|
|
|
|
executorService.shutdownNow();
|
|
|
|
executorService.shutdownNow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* LongPollingRunnable
|
|
|
|
|
|
|
|
*/
|
|
|
|
class LongPollingRunnable implements Runnable {
|
|
|
|
class LongPollingRunnable implements Runnable {
|
|
|
|
|
|
|
|
|
|
|
|
private boolean cacheMapInitEmptyFlag;
|
|
|
|
private boolean cacheMapInitEmptyFlag;
|
|
|
|
|
|
|
|
|
|
|
|
private final CountDownLatch cacheCondition;
|
|
|
|
private final CountDownLatch cacheCondition;
|
|
|
|
|
|
|
|
|
|
|
|
public LongPollingRunnable(boolean cacheMapInitEmptyFlag, CountDownLatch cacheCondition) {
|
|
|
|
LongPollingRunnable(boolean cacheMapInitEmptyFlag, CountDownLatch cacheCondition) {
|
|
|
|
this.cacheMapInitEmptyFlag = cacheMapInitEmptyFlag;
|
|
|
|
this.cacheMapInitEmptyFlag = cacheMapInitEmptyFlag;
|
|
|
|
this.cacheCondition = cacheCondition;
|
|
|
|
this.cacheCondition = cacheCondition;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -147,7 +152,7 @@ public class ClientWorker implements DisposableBean {
|
|
|
|
String itemId = keys[1];
|
|
|
|
String itemId = keys[1];
|
|
|
|
String namespace = keys[2];
|
|
|
|
String namespace = keys[2];
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String content = getServerConfig(namespace, itemId, tpId, 3000L);
|
|
|
|
String content = getServerConfig(namespace, itemId, tpId, defaultTimedOut);
|
|
|
|
CacheData cacheData = cacheMap.get(tpId);
|
|
|
|
CacheData cacheData = cacheMap.get(tpId);
|
|
|
|
String poolContent = ContentUtil.getPoolContent(JSONUtil.parseObject(content, ThreadPoolParameterInfo.class));
|
|
|
|
String poolContent = ContentUtil.getPoolContent(JSONUtil.parseObject(content, ThreadPoolParameterInfo.class));
|
|
|
|
cacheData.setContent(poolContent);
|
|
|
|
cacheData.setContent(poolContent);
|
|
|
@ -157,7 +162,7 @@ public class ClientWorker implements DisposableBean {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (CacheData cacheData : cacheDataList) {
|
|
|
|
for (CacheData cacheData : cacheDataList) {
|
|
|
|
if (!cacheData.isInitializing() || inInitializingCacheList
|
|
|
|
if (!cacheData.isInitializing() || inInitializingCacheList
|
|
|
|
.contains(GroupKey.getKeyTenant(cacheData.threadPoolId, cacheData.itemId, cacheData.tenantId))) {
|
|
|
|
.contains(GroupKey.getKeyTenant(cacheData.getThreadPoolId(), cacheData.getItemId(), cacheData.getTenantId()))) {
|
|
|
|
cacheData.checkListenerMd5();
|
|
|
|
cacheData.checkListenerMd5();
|
|
|
|
cacheData.setInitializing(false);
|
|
|
|
cacheData.setInitializing(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -170,13 +175,13 @@ public class ClientWorker implements DisposableBean {
|
|
|
|
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.threadPoolId).append(WORD_SEPARATOR);
|
|
|
|
sb.append(cacheData.getThreadPoolId()).append(WORD_SEPARATOR);
|
|
|
|
sb.append(cacheData.itemId).append(WORD_SEPARATOR);
|
|
|
|
sb.append(cacheData.getItemId()).append(WORD_SEPARATOR);
|
|
|
|
sb.append(cacheData.tenantId).append(WORD_SEPARATOR);
|
|
|
|
sb.append(cacheData.getTenantId()).append(WORD_SEPARATOR);
|
|
|
|
sb.append(identify).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.threadPoolId, cacheData.itemId, cacheData.tenantId));
|
|
|
|
inInitializingCacheList.add(GroupKey.getKeyTenant(cacheData.getThreadPoolId(), cacheData.getItemId(), cacheData.getTenantId()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean isInitializingCacheList = !inInitializingCacheList.isEmpty();
|
|
|
|
boolean isInitializingCacheList = !inInitializingCacheList.isEmpty();
|
|
|
@ -213,7 +218,7 @@ public class ClientWorker implements DisposableBean {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getServerConfig(String namespace, String itemId, String threadPoolId, 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<>(INITIAL_CAPACITY);
|
|
|
|
params.put("namespace", namespace);
|
|
|
|
params.put("namespace", namespace);
|
|
|
|
params.put("itemId", itemId);
|
|
|
|
params.put("itemId", itemId);
|
|
|
|
params.put("tpId", threadPoolId);
|
|
|
|
params.put("tpId", threadPoolId);
|
|
|
@ -241,7 +246,7 @@ public class ClientWorker implements DisposableBean {
|
|
|
|
String[] keyArr = dataIdAndGroup.split(WORD_SEPARATOR);
|
|
|
|
String[] keyArr = dataIdAndGroup.split(WORD_SEPARATOR);
|
|
|
|
String dataId = keyArr[0];
|
|
|
|
String dataId = keyArr[0];
|
|
|
|
String group = keyArr[1];
|
|
|
|
String group = keyArr[1];
|
|
|
|
if (keyArr.length == 3) {
|
|
|
|
if (keyArr.length == DATA_GROUP_TENANT_SIZE) {
|
|
|
|
String tenant = keyArr[2];
|
|
|
|
String tenant = keyArr[2];
|
|
|
|
updateList.add(GroupKey.getKeyTenant(dataId, group, tenant));
|
|
|
|
updateList.add(GroupKey.getKeyTenant(dataId, group, tenant));
|
|
|
|
log.info("[{}] Refresh thread pool changed.", dataId);
|
|
|
|
log.info("[{}] Refresh thread pool changed.", dataId);
|
|
|
@ -274,7 +279,7 @@ public class ClientWorker implements DisposableBean {
|
|
|
|
if (lastCacheData == null) {
|
|
|
|
if (lastCacheData == null) {
|
|
|
|
String serverConfig;
|
|
|
|
String serverConfig;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
serverConfig = getServerConfig(namespace, itemId, threadPoolId, 3000L);
|
|
|
|
serverConfig = getServerConfig(namespace, itemId, threadPoolId, defaultTimedOut);
|
|
|
|
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) {
|
|
|
|