|
|
@ -10,7 +10,9 @@ import cn.hippo4j.config.event.LocalDataChangeEvent;
|
|
|
|
import cn.hippo4j.config.model.CacheItem;
|
|
|
|
import cn.hippo4j.config.model.CacheItem;
|
|
|
|
import cn.hippo4j.config.model.ConfigAllInfo;
|
|
|
|
import cn.hippo4j.config.model.ConfigAllInfo;
|
|
|
|
import cn.hippo4j.config.toolkit.MapUtil;
|
|
|
|
import cn.hippo4j.config.toolkit.MapUtil;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -25,10 +27,19 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
* @author chen.ma
|
|
|
|
* @author chen.ma
|
|
|
|
* @date 2021/6/24 21:19
|
|
|
|
* @date 2021/6/24 21:19
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
public class ConfigCacheService {
|
|
|
|
public class ConfigCacheService {
|
|
|
|
|
|
|
|
|
|
|
|
static ConfigService configService = null;
|
|
|
|
private static ConfigService configService = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* TODO: 数据结构、客户端停机时 remove 操作待重构
|
|
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
|
|
* key: message-produce+dynamic-threadpool-example+prescription+192.168.20.227:8088
|
|
|
|
|
|
|
|
* val:
|
|
|
|
|
|
|
|
* key: 192.168.20.227:8088
|
|
|
|
|
|
|
|
* val: {@link CacheItem}
|
|
|
|
|
|
|
|
*/
|
|
|
|
private static final ConcurrentHashMap<String, Map<String, CacheItem>> CACHE = new ConcurrentHashMap();
|
|
|
|
private static final ConcurrentHashMap<String, Map<String, CacheItem>> CACHE = new ConcurrentHashMap();
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean isUpdateData(String groupKey, String md5, String ip) {
|
|
|
|
public static boolean isUpdateData(String groupKey, String md5, String ip) {
|
|
|
@ -43,7 +54,7 @@ public class ConfigCacheService {
|
|
|
|
* @param ip
|
|
|
|
* @param ip
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static String getContentMd5IsNullPut(String groupKey, String ip) {
|
|
|
|
private synchronized static String getContentMd5IsNullPut(String groupKey, String ip) {
|
|
|
|
Map<String, CacheItem> cacheItemMap = Optional.ofNullable(CACHE.get(groupKey)).orElse(Maps.newHashMap());
|
|
|
|
Map<String, CacheItem> cacheItemMap = Optional.ofNullable(CACHE.get(groupKey)).orElse(Maps.newHashMap());
|
|
|
|
|
|
|
|
|
|
|
|
CacheItem cacheItem = null;
|
|
|
|
CacheItem cacheItem = null;
|
|
|
@ -92,7 +103,7 @@ public class ConfigCacheService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static CacheItem makeSure(String groupKey, String ip) {
|
|
|
|
public synchronized static CacheItem makeSure(String groupKey, String ip) {
|
|
|
|
Map<String, CacheItem> ipCacheItemMap = CACHE.get(groupKey);
|
|
|
|
Map<String, CacheItem> ipCacheItemMap = CACHE.get(groupKey);
|
|
|
|
CacheItem item = ipCacheItemMap.get(ip);
|
|
|
|
CacheItem item = ipCacheItemMap.get(ip);
|
|
|
|
if (null != item) {
|
|
|
|
if (null != item) {
|
|
|
@ -114,4 +125,18 @@ public class ConfigCacheService {
|
|
|
|
return returnStrCacheItemMap;
|
|
|
|
return returnStrCacheItemMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Remove config cache.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param groupKey 租户 + 项目 + IP
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public synchronized static void removeConfigCache(String groupKey) {
|
|
|
|
|
|
|
|
// 模糊搜索
|
|
|
|
|
|
|
|
List<String> identificationList = MapUtil.parseMapForFilter(CACHE, groupKey);
|
|
|
|
|
|
|
|
for (String cacheMapKey : identificationList) {
|
|
|
|
|
|
|
|
Map<String, CacheItem> removeCacheItem = CACHE.remove(cacheMapKey);
|
|
|
|
|
|
|
|
log.info("Remove invalidated config cache. config info :: {}", JSON.toJSONString(removeCacheItem));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|