Java Code Examples for com.alibaba.csp.sentinel.util.AssertUtil#notNull()

The following examples show how to use com.alibaba.csp.sentinel.util.AssertUtil#notNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileInJarReadableDataSource.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
public FileInJarReadableDataSource(String jarName, String fileInJarName, Converter<String, T> configParser,
                                   int bufSize, Charset charset) throws IOException {
    super(configParser);
    AssertUtil.assertNotBlank(jarName, "jarName cannot be blank");
    AssertUtil.assertNotBlank(fileInJarName, "fileInJarName cannot be blank");
    if (bufSize <= 0 || bufSize > MAX_SIZE) {
        throw new IllegalArgumentException("bufSize must between (0, " + MAX_SIZE + "], but " + bufSize + " get");
    }
    AssertUtil.notNull(charset, "charset can't be null");
    this.buf = new byte[bufSize];
    this.charset = charset;
    this.jarName = jarName;
    this.fileInJarName = fileInJarName;
    initializeJar();
    firstLoad();
}
 
Example 2
Source File: EurekaDataSource.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
public EurekaDataSource(String appId, String instanceId, List<String> serviceUrls, String ruleKey,
                        Converter<String, T> configParser, long refreshMs, int connectTimeoutMills,
                        int readTimeoutMills) {
    super(configParser, refreshMs);
    AssertUtil.notNull(appId, "appId can't be null");
    AssertUtil.notNull(instanceId, "instanceId can't be null");
    AssertUtil.assertNotEmpty(serviceUrls, "serviceUrls can't be empty");
    AssertUtil.notNull(ruleKey, "ruleKey can't be null");
    AssertUtil.assertState(connectTimeoutMills > 0, "connectTimeoutMills must be greater than 0");
    AssertUtil.assertState(readTimeoutMills > 0, "readTimeoutMills must be greater than 0");

    this.appId = appId;
    this.instanceId = instanceId;
    this.serviceUrls = ensureEndWithSlash(serviceUrls);
    AssertUtil.assertNotEmpty(this.serviceUrls, "No available service url");
    this.ruleKey = ruleKey;
    this.connectTimeoutMills = connectTimeoutMills;
    this.readTimeoutMills = readTimeoutMills;
}
 
Example 3
Source File: AuthorityRuleManager.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static void register2Property(SentinelProperty<List<AuthorityRule>> property) {
    AssertUtil.notNull(property, "property cannot be null");
    synchronized (LISTENER) {
        if (currentProperty != null) {
            currentProperty.removeListener(LISTENER);
        }
        property.addListener(LISTENER);
        currentProperty = property;
        RecordLog.info("[AuthorityRuleManager] Registering new property to authority rule manager");
    }
}
 
Example 4
Source File: RedisConnectionConfig.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
/**
 * Configures a client name.
 *
 * @param clientName the client name
 * @return the builder
 */
public RedisConnectionConfig.Builder withClientName(String clientName) {

    AssertUtil.notNull(clientName, "Client name must not be null");

    this.clientName = clientName;
    return this;
}
 
Example 5
Source File: GatewayRuleManager.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public static void register2Property(SentinelProperty<Set<GatewayFlowRule>> property) {
    AssertUtil.notNull(property, "property cannot be null");
    synchronized (LISTENER) {
        RecordLog.info("[GatewayRuleManager] Registering new property to gateway flow rule manager");
        currentProperty.removeListener(LISTENER);
        property.addListener(LISTENER);
        currentProperty = property;
    }
}
 
Example 6
Source File: NacosDataSource.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param properties properties for construct {@link ConfigService} using {@link NacosFactory#createConfigService(Properties)}
 * @param groupId    group ID, cannot be empty
 * @param dataId     data ID, cannot be empty
 * @param parser     customized data parser, cannot be empty
 */
public NacosDataSource(final Properties properties, final String groupId, final String dataId,
                       Converter<String, T> parser) {
    super(parser);
    if (StringUtil.isBlank(groupId) || StringUtil.isBlank(dataId)) {
        throw new IllegalArgumentException(String.format("Bad argument: groupId=[%s], dataId=[%s]",
            groupId, dataId));
    }
    AssertUtil.notNull(properties, "Nacos properties must not be null, you could put some keys from PropertyKeyConst");
    this.groupId = groupId;
    this.dataId = dataId;
    this.properties = properties;
    this.configListener = new Listener() {
        @Override
        public Executor getExecutor() {
            return pool;
        }

        @Override
        public void receiveConfigInfo(final String configInfo) {
            RecordLog.info(String.format("[NacosDataSource] New property value received for (properties: %s) (dataId: %s, groupId: %s): %s",
                properties, dataId, groupId, configInfo));
            T newValue = NacosDataSource.this.parser.convert(configInfo);
            // Update the new value to the property.
            getProperty().updateValue(newValue);
        }
    };
    initNacosListener();
    loadInitialConfig();
}
 
Example 7
Source File: RedisConnectionConfig.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the password. Use empty string to skip authentication.
 *
 * @param password the password, must not be {@literal null}.
 */
public void setPassword(String password) {

    AssertUtil.notNull(password, "Password must not be null");
    this.password = password.toCharArray();
}
 
Example 8
Source File: ParamFlowRuleUtil.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
/**
 * Build the rule map from raw list of parameter flow rules, grouping by provided group function.
 *
 * @param list          raw list of parameter flow rules
 * @param groupFunction grouping function of the map (by key)
 * @param filter        rule filter
 * @param shouldSort    whether the rules should be sorted
 * @param <K>           type of key
 * @return constructed new rule map; empty map if list is null or empty, or no wanted rules
 * @since 1.6.1
 */
public static <K> Map<K, List<ParamFlowRule>> buildParamRuleMap(List<ParamFlowRule> list,
                                                                Function<ParamFlowRule, K> groupFunction,
                                                                Predicate<ParamFlowRule> filter,
                                                                boolean shouldSort) {
    AssertUtil.notNull(groupFunction, "groupFunction should not be null");
    Map<K, List<ParamFlowRule>> newRuleMap = new ConcurrentHashMap<>();
    if (list == null || list.isEmpty()) {
        return newRuleMap;
    }
    Map<K, Set<ParamFlowRule>> tmpMap = new ConcurrentHashMap<>();

    for (ParamFlowRule rule : list) {
        if (!ParamFlowRuleUtil.isValidRule(rule)) {
            RecordLog.warn("[ParamFlowRuleManager] Ignoring invalid rule when loading new rules: " + rule);
            continue;
        }
        if (filter != null && !filter.test(rule)) {
            continue;
        }
        if (StringUtil.isBlank(rule.getLimitApp())) {
            rule.setLimitApp(RuleConstant.LIMIT_APP_DEFAULT);
        }

        ParamFlowRuleUtil.fillExceptionFlowItems(rule);

        K key = groupFunction.apply(rule);
        if (key == null) {
            continue;
        }
        Set<ParamFlowRule> flowRules = tmpMap.get(key);

        if (flowRules == null) {
            // Use hash set here to remove duplicate rules.
            flowRules = new HashSet<>();
            tmpMap.put(key, flowRules);
        }

        flowRules.add(rule);
    }
    for (Entry<K, Set<ParamFlowRule>> entries : tmpMap.entrySet()) {
        List<ParamFlowRule> rules = new ArrayList<>(entries.getValue());
        if (shouldSort) {
            // TODO: Sort the rules.
        }
        newRuleMap.put(entries.getKey(), rules);
    }

    return newRuleMap;
}
 
Example 9
Source File: GatewayApiDefinitionManager.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
static void addApiChangeListener(ApiDefinitionChangeObserver listener) {
    AssertUtil.notNull(listener, "listener cannot be null");
    API_CHANGE_OBSERVERS.put(listener.getClass().getCanonicalName(), listener);
}
 
Example 10
Source File: ParamFlowRuleEntity.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
public ParamFlowRuleEntity(ParamFlowRule rule) {
    AssertUtil.notNull(rule, "Authority rule should not be null");
    this.rule = rule;
}
 
Example 11
Source File: GatewayCallbackManager.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void setBlockHandler(BlockRequestHandler blockHandler) {
    AssertUtil.notNull(blockHandler, "blockHandler cannot be null");
    GatewayCallbackManager.blockHandler = blockHandler;
}
 
Example 12
Source File: ClusterParamMetricStatistics.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void putMetric(long id, ClusterParamMetric metric) {
    AssertUtil.notNull(metric, "metric cannot be null");
    METRIC_MAP.put(id, metric);
}
 
Example 13
Source File: SentinelConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
public static void setConfig(String key, String value) {
    AssertUtil.notNull(key, "key cannot be null");
    AssertUtil.notNull(value, "value cannot be null");
    props.put(key, value);
}
 
Example 14
Source File: SofaRpcFallbackRegistry.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void setProviderFallback(SofaRpcFallback providerFallback) {
    AssertUtil.notNull(providerFallback, "providerFallback cannot be null");
    SofaRpcFallbackRegistry.providerFallback = providerFallback;
}
 
Example 15
Source File: AuthorityRuleEntity.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public AuthorityRuleEntity(AuthorityRule authorityRule) {
    AssertUtil.notNull(authorityRule, "Authority rule should not be null");
    this.rule = authorityRule;
}
 
Example 16
Source File: ClusterMetricStatistics.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void putMetric(long id, ClusterMetric metric) {
    AssertUtil.notNull(metric, "Cluster metric cannot be null");
    METRIC_MAP.put(id, metric);
}
 
Example 17
Source File: SentinelConfig.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void setConfig(String key, String value) {
    AssertUtil.notNull(key, "key cannot be null");
    AssertUtil.notNull(value, "value cannot be null");
    props.put(key, value);
}
 
Example 18
Source File: DubboFallbackRegistry.java    From dubbo-sentinel-support with Apache License 2.0 4 votes vote down vote up
public static void setProviderFallback(DubboFallback providerFallback) {
    AssertUtil.notNull(providerFallback, "providerFallback cannot be null");
    DubboFallbackRegistry.providerFallback = providerFallback;
}
 
Example 19
Source File: ConfigSupplierRegistry.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static void setNamespaceSupplier(Supplier<String> namespaceSupplier) {
    AssertUtil.notNull(namespaceSupplier, "namespaceSupplier cannot be null");
    ConfigSupplierRegistry.namespaceSupplier = namespaceSupplier;
    RecordLog.info("[ConfigSupplierRegistry] New namespace supplier provided, current supplied: "
        + namespaceSupplier.get());
}
 
Example 20
Source File: FluxSentinelOperator.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
public FluxSentinelOperator(Flux<? extends T> source, EntryConfig entryConfig) {
    super(source);
    AssertUtil.notNull(entryConfig, "entryConfig cannot be null");
    this.entryConfig = entryConfig;
}