Skip to content

Commit

Permalink
chore: improve
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Mar 13, 2023
1 parent e68140a commit 86e1bd2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public void filter(ContainerRequestContext context) throws IOException {
if (globalMasterInfo == null || !globalMasterInfo.isFeatureSupport()) {
return;
}
GlobalMasterInfo.Info masterInfo = globalMasterInfo.info();
if (masterInfo == null || masterInfo.isMaster() ||
StringUtils.isEmpty(masterInfo.url())) {
GlobalMasterInfo.NodeInfo masterNodeInfo = globalMasterInfo.nodeInfo();
if (masterNodeInfo == null || masterNodeInfo.isMaster() ||
StringUtils.isEmpty(masterNodeInfo.url())) {
return;
}
String url = masterInfo.url();
String url = masterNodeInfo.url();

URI redirectUri;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@

public class GlobalMasterInfo {

private volatile Info info;
private NodeInfo nodeInfo;
private volatile boolean featureSupport;

public GlobalMasterInfo() {
this.featureSupport = false;
this.info = new Info(false, "");
this.nodeInfo = new NodeInfo(false, "");
}

public void info(boolean isMaster, String url) {
this.info = new Info(isMaster, url);
public final void nodeInfo(boolean isMaster, String url) {
// final local variable avoid instruction rearrangement
final NodeInfo tempNodeInfo = new NodeInfo(isMaster, url);
this.nodeInfo = tempNodeInfo;
}

public Info info() {
return this.info;
public final NodeInfo nodeInfo() {
return this.nodeInfo;
}

public void isFeatureSupport(boolean featureSupport) {
Expand All @@ -43,12 +45,12 @@ public boolean isFeatureSupport() {
return this.featureSupport;
}

public static class Info {
public static class NodeInfo {

private boolean isMaster;
private String url;
private final boolean isMaster;
private final String url;

public Info(boolean isMaster, String url) {
public NodeInfo(boolean isMaster, String url) {
this.isMaster = isMaster;
this.url = url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public void error(StateMachineContext context, Throwable e) {
public void initGlobalMasterInfo(StateMachineContext context) {
StateMachineContext.MasterServerInfo master = context.master();
if (master == null) {
this.globalMasterInfo.info(false, null);
this.globalMasterInfo.nodeInfo(false, "");
return;
}

boolean isMaster = Objects.equals(context.node(), master.node());
String url = master.url();
this.globalMasterInfo.info(isMaster, url);
this.globalMasterInfo.nodeInfo(isMaster, url);
}
}

0 comments on commit 86e1bd2

Please sign in to comment.