修改asn缓存初始化方法加入参数是否强制刷新,部署多个tomcat服务时个个tomcat缓存可能存在不一致的情况,这就需要强制重新加载缓存
This commit is contained in:
@@ -65,16 +65,36 @@ public class AsnCacheUtils{
|
||||
return configGroupInfos;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 初始化缓存
|
||||
*
|
||||
* @param force是否强制刷新
|
||||
*/
|
||||
//@PostConstruct
|
||||
public synchronized static void init() {
|
||||
public synchronized static void init(boolean force) {
|
||||
long start=System.currentTimeMillis();
|
||||
logger.warn("AsnCacheUtils init start...");
|
||||
Cache cache=getCache(ASN_NO_CACHE);
|
||||
if(force) {
|
||||
List<ConfigGroupInfo> list=configGroupInfoDao.findAllList(4);
|
||||
Map<Long,Map<Long,ConfigGroupInfo>> groupMap=Maps.newHashMap();
|
||||
for(ConfigGroupInfo configGroupInfo:list) {
|
||||
if(groupMap.containsKey(configGroupInfo.getAsnId()/cache_rage)) {
|
||||
groupMap.get(configGroupInfo.getAsnId()/cache_rage)
|
||||
.put(configGroupInfo.getAsnId(), configGroupInfo);
|
||||
}else {
|
||||
Map<Long,ConfigGroupInfo> m=Maps.newHashMap();
|
||||
m.put(configGroupInfo.getAsnId(), configGroupInfo);
|
||||
groupMap.put(configGroupInfo.getAsnId()/cache_rage, m);
|
||||
}
|
||||
}
|
||||
for(Entry<Long, Map<Long, ConfigGroupInfo>> e:groupMap.entrySet()) {
|
||||
Element element = new Element(e.getKey(), e.getValue());
|
||||
cache.put(element);
|
||||
}
|
||||
}else {
|
||||
//查询总量
|
||||
Long count=configGroupInfoDao.getCountByType(4);
|
||||
//缓存key
|
||||
boolean loadDatabase=false;
|
||||
if(cache.getKeys().size()==0) {
|
||||
loadDatabase=true;
|
||||
@@ -105,6 +125,8 @@ public class AsnCacheUtils{
|
||||
cache.put(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long end=System.currentTimeMillis();
|
||||
logger.warn("AsnCacheUtils init finish,cost:"+(end-start));
|
||||
}
|
||||
|
||||
@@ -1197,7 +1197,7 @@ public class BaseController {
|
||||
ipPortCfgs=this.checkIpCfgMulity(serviceDict, regionDict, null, list);
|
||||
} else if (regionDict.getFunctionId().equals(600)) {// ASN IP
|
||||
//加载asn缓存
|
||||
AsnCacheUtils.init();
|
||||
AsnCacheUtils.init(true);
|
||||
BlockingQueue<AsnIpTemplate> list = ei.getDataList(AsnIpTemplate.class );
|
||||
ipPortCfgs=this.checkIpCfgMulity(serviceDict, regionDict, asnNoMaps, list);
|
||||
} else if (regionDict.getFunctionId().equals(301)) {// DDOS IP
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AsnIpController extends BaseController{
|
||||
|
||||
// List<PolicyGroupInfo> policyGroups=policyGroupInfoService.findPolicyGroupInfosByType(4);
|
||||
// model.addAttribute("policyGroups", policyGroups);
|
||||
AsnCacheUtils.init();
|
||||
AsnCacheUtils.init(false);
|
||||
List<ConfigGroupInfo> policyGroups=AsnCacheUtils.getAllAsnGroup();
|
||||
model.addAttribute("policyGroups", policyGroups);
|
||||
return "/basics/asnIpCfgList";
|
||||
@@ -137,7 +137,7 @@ public class AsnIpController extends BaseController{
|
||||
@RequestMapping(value="ajaxGroupName",method=RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Map<String, String> ajaxGroupName(Model model,String ids){
|
||||
AsnCacheUtils.init();
|
||||
AsnCacheUtils.init(false);
|
||||
Map<String, String> groupMap=new HashMap<>();
|
||||
for(String id:ids.split(",")) {
|
||||
ConfigGroupInfo info=AsnCacheUtils.get(Long.parseLong(id));
|
||||
|
||||
@@ -168,7 +168,7 @@ public class AsnIpCfgService extends CrudService<CrudDao<AsnIpCfg>, AsnIpCfg> {
|
||||
configGroupInfoS.clear();
|
||||
}
|
||||
//刷新缓存
|
||||
AsnCacheUtils.init();
|
||||
AsnCacheUtils.init(true);
|
||||
long end=System.currentTimeMillis();
|
||||
logger.warn("Save group finish,cost:"+(end-start));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user