Java Code Examples for com.alibaba.csp.sentinel.config.SentinelConfig#getConfig()

The following examples show how to use com.alibaba.csp.sentinel.config.SentinelConfig#getConfig() . 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: WebServletConfig.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Get the HTTP status when using the default block page.</p>
 * <p>You can set the status code with the {@code -Dcsp.sentinel.web.servlet.block.status}
 * property. When the property is empty or invalid, Sentinel will use 429 (Too Many Requests)
 * as the default status code.</p>
 *
 * @return the HTTP status of the default block page
 * @since 1.7.0
 */
public static int getBlockPageHttpStatus() {
    String value = SentinelConfig.getConfig(BLOCK_PAGE_HTTP_STATUS_CONF_KEY);
    if (StringUtil.isEmpty(value)) {
        return HTTP_STATUS_TOO_MANY_REQUESTS;
    }
    try {
        int s = Integer.parseInt(value);
        if (s <= 0) {
            throw new IllegalArgumentException("Invalid status code: " + s);
        }
        return s;
    } catch (Exception e) {
        RecordLog.warn("[WebServletConfig] Invalid block HTTP status (" + value + "), using default 429");
        setBlockPageHttpStatus(HTTP_STATUS_TOO_MANY_REQUESTS);
    }
    return HTTP_STATUS_TOO_MANY_REQUESTS;
}
 
Example 2
Source File: TransportConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
/**
 * Get heartbeat interval in milliseconds.
 *
 * @return heartbeat interval in milliseconds if exists, or null if not configured or invalid config
 */
public static Long getHeartbeatIntervalMs() {
    String interval = SentinelConfig.getConfig(HEARTBEAT_INTERVAL_MS);
    try {
        return interval == null ? null : Long.parseLong(interval);
    } catch (Exception ex) {
        RecordLog.warn("[TransportConfig] Failed to parse heartbeat interval: " + interval);
        return null;
    }
}
 
Example 3
Source File: TransportConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
/**
 * Get Server port of this HTTP server.
 *
 * @return the port, maybe null if not configured.
 */
public static String getPort() {
    if (runtimePort > 0) {
        return String.valueOf(runtimePort);
    }
    return SentinelConfig.getConfig(SERVER_PORT);
}
 
Example 4
Source File: TransportConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
/**
 * Get heartbeat client local ip.
 * If the client ip not configured,it will be the address of local host
 *
 * @return the local ip.
 */
public static String getHeartbeatClientIp() {
    String ip = SentinelConfig.getConfig(HEARTBEAT_CLIENT_IP);
    if (StringUtil.isBlank(ip)) {
        ip = HostNameUtil.getIp();
    }
    return ip;
}
 
Example 5
Source File: ClusterClientStartUpConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
/**
 * Get the max bytes params can be serialized
 *
 * @return the max bytes, may be null
 */
public static Integer getMaxParamByteSize() {
    String maxParamByteSize = SentinelConfig.getConfig(MAX_PARAM_BYTE_SIZE);
    try {
        return maxParamByteSize == null ? null : Integer.valueOf(maxParamByteSize);
    } catch (Exception ex) {
        RecordLog.warn("[ClusterClientStartUpConfig] Failed to parse maxParamByteSize: " + maxParamByteSize);
        return null;
    }
}
 
Example 6
Source File: TransportConfig.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
/**
 * Get Server port of this HTTP server.
 *
 * @return the port, maybe null if not configured.
 */
public static String getPort() {
    if (runtimePort > 0) {
        return String.valueOf(runtimePort);
    }
    return SentinelConfig.getConfig(SERVER_PORT);
}
 
Example 7
Source File: TransportConfig.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
/**
 * Get heartbeat client local ip.
 * If the client ip not configured,it will be the address of local host
 *
 * @return the local ip.
 */
public static String getHeartbeatClientIp() {
    String ip = SentinelConfig.getConfig(HEARTBEAT_CLIENT_IP);
    if (StringUtil.isBlank(ip)) {
        ip = HostNameUtil.getIp();
    }
    return ip;
}
 
Example 8
Source File: TransportConfig.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
/**
 * Get the heartbeat api path. If the machine registry path of the dashboard
 * is modified, then the API path should also be consistent with the API path of the dashboard.
 *
 * @return the heartbeat api path
 * @since 1.7.1
 */
public static String getHeartbeatApiPath() {
    String apiPath = SentinelConfig.getConfig(HEARTBEAT_API_PATH);
    if (StringUtil.isBlank(apiPath)) {
        return HEARTBEAT_DEFAULT_PATH;
    }
    if (!apiPath.startsWith("/")) {
        apiPath = "/" + apiPath;
    }
    return apiPath;
}
 
Example 9
Source File: ClusterClientStartUpConfig.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
/**
 * Get the max bytes params can be serialized
 *
 * @return the max bytes, may be null
 */
public static Integer getMaxParamByteSize() {
    String maxParamByteSize = SentinelConfig.getConfig(MAX_PARAM_BYTE_SIZE);
    try {
        return maxParamByteSize == null ? null : Integer.valueOf(maxParamByteSize);
    } catch (Exception ex) {
        RecordLog.warn("[ClusterClientStartUpConfig] Failed to parse maxParamByteSize: " + maxParamByteSize);
        return null;
    }
}
 
Example 10
Source File: EtcdConfig.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static String getCharset() {
    String etcdCharset = SentinelConfig.getConfig(CHARSET);
    if (StringUtil.isNotBlank(etcdCharset)) {
        return etcdCharset;
    }
    return SentinelConfig.charset();
}
 
Example 11
Source File: DubboConfig.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static String getDubboConsumerPrefix() {
    if (isUsePrefix()) {
        String config = SentinelConfig.getConfig(DUBBO_CONSUMER_PREFIX);
        return StringUtil.isNotBlank(config) ? config : DEFAULT_DUBBO_CONSUMER_PREFIX;
    }
    return null;
}
 
Example 12
Source File: DubboConfig.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static Boolean getDubboBizExceptionTraceEnabled() {
    String traceBizExceptionEnabled = SentinelConfig.getConfig(TRACE_BIZ_EXCEPTION_ENABLED);
    if (StringUtil.isNotBlank(traceBizExceptionEnabled)) {
        return TRUE_STR.equalsIgnoreCase(traceBizExceptionEnabled);
    }
    return true;
}
 
Example 13
Source File: EtcdConfig.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static String getEndPoints() {
    return SentinelConfig.getConfig(END_POINTS);
}
 
Example 14
Source File: EtcdConfig.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static String getAuthority() {
    return SentinelConfig.getConfig(AUTHORITY);
}
 
Example 15
Source File: ServiceLoaderUtil.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static boolean shouldUseContextClassloader() {
    String classloaderConf = SentinelConfig.getConfig(SentinelConfig.SPI_CLASSLOADER);
    return CLASSLOADER_CONTEXT.equalsIgnoreCase(classloaderConf);
}
 
Example 16
Source File: EtcdConfig.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static String getPassword() {
    return SentinelConfig.getConfig(PASSWORD);
}
 
Example 17
Source File: EtcdConfig.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static String getUser() {
    return SentinelConfig.getConfig(USER);
}
 
Example 18
Source File: WebServletConfig.java    From Sentinel with Apache License 2.0 2 votes vote down vote up
/**
 * Get redirecting page when Sentinel blocking for {@link CommonFilter} or
 * {@link CommonTotalFilter} occurs.
 *
 * @return the block page URL, maybe null if not configured.
 */
public static String getBlockPage() {
    return SentinelConfig.getConfig(BLOCK_PAGE_URL_CONF_KEY);
}
 
Example 19
Source File: WebServletConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 2 votes vote down vote up
/**
 * Get redirecting page when Sentinel blocking for {@link CommonFilter} or
 * {@link CommonTotalFilter} occurs.
 *
 * @return the block page URL, maybe null if not configured.
 */
public static String getBlockPage() {
    return SentinelConfig.getConfig(BLOCK_PAGE);
}
 
Example 20
Source File: TransportConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 2 votes vote down vote up
/**
 * Get ip:port of Sentinel Dashboard.
 *
 * @return console server ip:port, maybe null if not configured
 */
public static String getConsoleServer() {
    return SentinelConfig.getConfig(CONSOLE_SERVER);
}