fix:loadAllIdentifies同时更新VersionMap

This commit is contained in:
ChessNineeee
2021-05-27 22:55:39 +08:00
parent 31e995af1c
commit d117f5359b
+10 -7
View File
@@ -76,10 +76,9 @@ public class IdentityManager {
public void init() {
try{
this.identifies = loadAllIdentifies();
loadAllIdentifies();
this.defaultIdentity = Persist.getDefaultIdentityFromStorage("");
this.privateKeyEncryptionAlgorithm = Common.SM4ECB;
this.versionMap = new ConcurrentHashMap<>(); // TODO versionMap初始化方式待定
}catch (Exception ex){
System.out.println(String.format("创建IdentifyManager实例失败:%s", ex.getMessage()));
}
@@ -88,18 +87,22 @@ public class IdentityManager {
/**
* 从sqlite中加载全部网络身份信息并封装成ConcurrentMap
* 从sqlite中加载全部网络身份信息并封装成identifies与versionMap
* @return {ConcurrentMap}
* @throws Exception
*/
private ConcurrentMap<String, Identity> loadAllIdentifies() throws Exception{
private void loadAllIdentifies() throws Exception{
List<Identity> identities = Persist.getAllIdentityFromStorage("");
ConcurrentHashMap<String, Identity> res = new ConcurrentHashMap<>();
ConcurrentHashMap<String, Identity> tempIdentifiesMap = new ConcurrentHashMap<>();
ConcurrentHashMap<String, Long> tempVersionMap = new ConcurrentHashMap<>();
for (Identity id:
identities) {
res.put(id.getName(), id);
tempIdentifiesMap.put(id.getName(), id);
tempVersionMap.put(id.getName(), 0L);
}
return res;
this.identifies = tempIdentifiesMap;
this.versionMap = tempVersionMap;
}