Skip to content

Commit

Permalink
[ISSUE#12583] ProtocolManager代码优化 (#12584)
Browse files Browse the repository at this point in the history
* [ISSUE#12583] ProtocolManager代码优化

* update: revert getBeanIfExist()
  • Loading branch information
HMYDK authored Sep 3, 2024
1 parent de33667 commit 62f4a37
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ public class ProtocolManager extends MemberChangeListener implements DisposableB

private final ServerMemberManager memberManager;

private boolean apInit = false;
private volatile boolean apInit = false;

private boolean cpInit = false;
private volatile boolean cpInit = false;

private final Object cpLock = new Object();

private final Object apLock = new Object();

private Set<Member> oldMembers;

Expand All @@ -80,20 +84,24 @@ public static Set<String> toCPMembersInfo(Collection<Member> members) {
}

public CPProtocol getCpProtocol() {
synchronized (this) {
if (!cpInit) {
initCPProtocol();
cpInit = true;
if (!cpInit){
synchronized (cpLock) {
if (!cpInit) {
initCPProtocol();
cpInit = true;
}
}
}
return cpProtocol;
}

public APProtocol getApProtocol() {
synchronized (this) {
if (!apInit) {
initAPProtocol();
apInit = true;
if (!apInit) {
synchronized (apLock) {
if (!apInit) {
initAPProtocol();
apInit = true;
}
}
}
return apProtocol;
Expand Down

0 comments on commit 62f4a37

Please sign in to comment.