From c14e3296cba0a01b760a9481453f2e265af07ee0 Mon Sep 17 00:00:00 2001 From: yidadi <1056027797@qq.com> Date: Thu, 27 Jun 2019 16:50:43 +0800 Subject: [PATCH] Refine the methods and variable name in SlotChainProvider (#871) --- .../sentinel/slotchain/SlotChainProvider.java | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/SlotChainProvider.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/SlotChainProvider.java index dedad3c19d..2d8014865e 100644 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/SlotChainProvider.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/SlotChainProvider.java @@ -15,12 +15,9 @@ */ package com.alibaba.csp.sentinel.slotchain; -import java.util.ArrayList; -import java.util.List; -import java.util.ServiceLoader; - import com.alibaba.csp.sentinel.log.RecordLog; import com.alibaba.csp.sentinel.slots.DefaultSlotChainBuilder; +import java.util.ServiceLoader; /** * A provider for creating slot chains via resolved slot chain builder SPI. @@ -30,7 +27,7 @@ */ public final class SlotChainProvider { - private static volatile SlotChainBuilder builder = null; + private static volatile SlotChainBuilder slotChainBuilder = null; private static final ServiceLoader LOADER = ServiceLoader.load(SlotChainBuilder.class); @@ -41,37 +38,33 @@ public final class SlotChainProvider { * @return new created slot chain */ public static ProcessorSlotChain newSlotChain() { - if (builder != null) { - return builder.build(); + if (slotChainBuilder != null) { + return slotChainBuilder.build(); } resolveSlotChainBuilder(); - if (builder == null) { + if (slotChainBuilder == null) { RecordLog.warn("[SlotChainProvider] Wrong state when resolving slot chain builder, using default"); - builder = new DefaultSlotChainBuilder(); + slotChainBuilder = new DefaultSlotChainBuilder(); } - return builder.build(); + return slotChainBuilder.build(); } private static void resolveSlotChainBuilder() { - List list = new ArrayList(); - boolean hasOther = false; for (SlotChainBuilder builder : LOADER) { if (builder.getClass() != DefaultSlotChainBuilder.class) { - hasOther = true; - list.add(builder); + slotChainBuilder = builder; + break; } } - if (hasOther) { - builder = list.get(0); - } else { + if (slotChainBuilder == null){ // No custom builder, using default. - builder = new DefaultSlotChainBuilder(); + slotChainBuilder = new DefaultSlotChainBuilder(); } RecordLog.info("[SlotChainProvider] Global slot chain builder resolved: " - + builder.getClass().getCanonicalName()); + + slotChainBuilder.getClass().getCanonicalName()); } private SlotChainProvider() {}