Search in sources :

Example 1 with IStrategyFactory

use of org.apache.servicecomb.qps.strategy.IStrategyFactory in project java-chassis by ServiceComb.

the class QpsControllerManager method chooseStrategy.

private AbstractQpsStrategy chooseStrategy(String configKey, Long limit, Long 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.createStrategy(strategyName);
        if (strategy != null) {
            break;
        }
    }
    if (strategy == null) {
        throw new ServiceCombException("the qps strategy name " + strategyName + " is not exist , please check.");
    }
    strategy.setKey(configKey);
    strategy.setQpsLimit(limit);
    strategy.setBucketLimit(bucket);
    return strategy;
}
Also used : AbstractQpsStrategy(org.apache.servicecomb.qps.strategy.AbstractQpsStrategy) IStrategyFactory(org.apache.servicecomb.qps.strategy.IStrategyFactory) ServiceCombException(org.apache.servicecomb.foundation.common.exceptions.ServiceCombException)

Aggregations

ServiceCombException (org.apache.servicecomb.foundation.common.exceptions.ServiceCombException)1 AbstractQpsStrategy (org.apache.servicecomb.qps.strategy.AbstractQpsStrategy)1 IStrategyFactory (org.apache.servicecomb.qps.strategy.IStrategyFactory)1