fix:loadAllIdentifies同时更新VersionMap

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