Skip to content

Commit

Permalink
[ISSUE #9154] Solve the nullcheck of value previously dereferenced. (#…
Browse files Browse the repository at this point in the history
…9157)

* [ISSUE #9154] Solve the nullcheck of value previously dereferenced.

* [ISSUE #9154] Remove unused import.
  • Loading branch information
jjastan authored Sep 19, 2022
1 parent 419530d commit 45f38b5
Showing 1 changed file with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.alibaba.nacos.core.remote.control;

import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.common.executor.ExecutorFactory;
import com.alibaba.nacos.common.notify.Event;
Expand All @@ -36,6 +35,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -153,31 +153,30 @@ public boolean applyTps(String pointName, String connectionId, List<MonitorKey>

@Override
public void onEvent(TpsControlRuleChangeEvent event) {

if (event == null) {
Loggers.TPS_CONTROL.info("Tps control rule change event receive, but event is null");
return;
}

Loggers.TPS_CONTROL
.info("Tps control rule change event receive,pointName={}, ruleContent={} ", event.getPointName(),
.info("Tps control rule change event receive, pointName={}, ruleContent={} ", event.getPointName(),
event.ruleContent);
if (event == null || event.getPointName() == null) {
if (event.getPointName() == null) {
return;
}

try {
TpsControlRule tpsControlRule = StringUtils.isBlank(event.ruleContent) ? new TpsControlRule()
: JacksonUtils.toObj(event.ruleContent, TpsControlRule.class);
if (!points.containsKey(event.getPointName())) {
Loggers.TPS_CONTROL.info("Tps control rule change event ignore,pointName={} ", event.getPointName());
Loggers.TPS_CONTROL.info("Tps control rule change event ignore, pointName={} ", event.getPointName());
return;
}
try {
saveRuleToLocal(event.getPointName(), tpsControlRule);
} catch (Throwable throwable) {
Loggers.TPS_CONTROL
.warn("Tps control rule persist fail,pointName={},error={} ", event.getPointName(), throwable);

}

saveRuleToLocal(event.getPointName(), tpsControlRule);
} catch (Exception e) {
Loggers.TPS_CONTROL.warn("Tps control rule apply error ,error= ", e);
Loggers.TPS_CONTROL.warn("Tps control rule apply error, error= ", e);
}

}

@Override
Expand Down Expand Up @@ -300,14 +299,18 @@ private synchronized void loadRuleFromLocal(TpsMonitorPoint tpsMonitorPoint) thr
}

private synchronized void saveRuleToLocal(String pointName, TpsControlRule tpsControlRule) throws IOException {

File pointFile = getRuleFile(pointName);
if (!pointFile.exists()) {
pointFile.createNewFile();
try {
File pointFile = getRuleFile(pointName);
if (!pointFile.exists()) {
pointFile.createNewFile();
}
String content = JacksonUtils.toJson(tpsControlRule);
DiskUtils.writeFile(pointFile, content.getBytes(StandardCharsets.UTF_8), false);
Loggers.TPS_CONTROL.info("Save rule to local,pointName={}, ruleContent ={} ", pointName, content);
} catch (IOException e) {
Loggers.TPS_CONTROL
.warn("Tps control rule persist fail, pointName={},error={} ", pointName, e);
}
String content = JacksonUtils.toJson(tpsControlRule);
DiskUtils.writeFile(pointFile, content.getBytes(Constants.ENCODE), false);
Loggers.TPS_CONTROL.info("Save rule to local,pointName={}, ruleContent ={} ", pointName, content);
}

private File getRuleFile(String pointName) {
Expand Down

0 comments on commit 45f38b5

Please sign in to comment.