From 2f90a87cab40d69ecc7d02036636047b7806668d Mon Sep 17 00:00:00 2001 From: drgnchan <40224023+drgnchan@users.noreply.github.com> Date: Wed, 7 Apr 2021 00:43:27 -0500 Subject: [PATCH] feat: Fix typo in FlowRuleManager and improve code with Map.computeIfAbsent in MetricTimerListener (#2110) --- .../alibaba/csp/sentinel/node/metric/MetricTimerListener.java | 4 +--- .../csp/sentinel/slots/block/flow/FlowRuleManager.java | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricTimerListener.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricTimerListener.java index 93992cc9..9dda6c83 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricTimerListener.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricTimerListener.java @@ -62,9 +62,7 @@ public class MetricTimerListener implements Runnable { MetricNode metricNode = entry.getValue(); metricNode.setResource(node.getName()); metricNode.setClassification(node.getResourceType()); - if (maps.get(time) == null) { - maps.put(time, new ArrayList()); - } + maps.computeIfAbsent(time, k -> new ArrayList()); List nodes = maps.get(time); nodes.add(entry.getValue()); } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java index eda0faaf..9dfa3f27 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java @@ -77,7 +77,7 @@ public class FlowRuleManager { private static void startMetricTimerListener() { long flushInterval = SentinelConfig.metricLogFlushIntervalSec(); if (flushInterval <= 0) { - RecordLog.info("[FlowRuleManager] The MetricTimerListener is'n started. If you want to start it, " + RecordLog.info("[FlowRuleManager] The MetricTimerListener isn't started. If you want to start it, " + "please change the value(current: {}) of config({}) more than 0 to start it.", flushInterval, SentinelConfig.METRIC_FLUSH_INTERVAL); return;