GuoYL123 commented on a change in pull request #1894:
URL: 
https://github.com/apache/servicecomb-java-chassis/pull/1894#discussion_r462821368



##########
File path: 
handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/QpsControllerManager.java
##########
@@ -209,22 +210,25 @@ public QpsControllerManager setGlobalQpsStrategy(String 
globalLimitKey, String g
   }
 
   private AbstractQpsStrategy chooseStrategy(String globalConfigKey, Long 
limit, Long bucket,
-      String strategyKey) {
-    AbstractQpsStrategy strategy;
-    switch (StrategyType.parseStrategyType(strategyKey)) {
-      case FixedWindow:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
-        break;
-      case LeakyBucket:
-        strategy = new LeakyBucketStrategy(globalConfigKey, limit);
-        break;
-      case TokenBucket:
-        strategy = new TokenBucketStrategy(globalConfigKey, limit, bucket);
+      String strategyName) {
+    if (StringUtils.isEmpty(strategyName)) {
+      strategyName = "FixedWindow";
+    }
+    AbstractQpsStrategy strategy = null;
+    List<IStrategyFactory> strategyFactories = SPIServiceUtils
+        .getOrLoadSortedService(IStrategyFactory.class);
+    for (IStrategyFactory strategyFactory : strategyFactories) {
+      strategy = strategyFactory.getStrategy(strategyName);
+      if (strategy != null) {
         break;
-      case SlidingWindow:
-      default:
-        strategy = new FixedWindowStrategy(globalConfigKey, limit);
+      }
+    }
+    if (strategy == null) {
+      throw new ServiceCombException("the qps strategy name is not exist , 
please check.");

Review comment:
       done

##########
File path: 
handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/strategy/DefaultStrategyFactory.java
##########
@@ -14,27 +14,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.servicecomb.qps.strategy;
 
-import org.apache.commons.lang3.StringUtils;
-
-public enum StrategyType {
-  TokenBucket,
-  LeakyBucket,
-  FixedWindow,
-  SlidingWindow;
-
-
-  public static StrategyType parseStrategyType(String type) {
-    if (StringUtils.isEmpty(type)) {
-      return StrategyType.FixedWindow;
-    }
+public class DefaultStrategyFactory implements IStrategyFactory {
 
-    try {
-      return StrategyType.valueOf(type.toUpperCase());
-    } catch (IllegalArgumentException e) {
-      return StrategyType.FixedWindow;
+  public AbstractQpsStrategy getStrategy(String strategyName) {

Review comment:
       done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to