|
| 1 | +/* |
| 2 | + * Copyright 1999-2020 Alibaba Group Holding Ltd. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.alibaba.csp.sentinel.adapter.okhttp.config; |
| 17 | + |
| 18 | +import com.alibaba.csp.sentinel.adapter.okhttp.extractor.DefaultOkHttpResourceExtractor; |
| 19 | +import com.alibaba.csp.sentinel.adapter.okhttp.extractor.OkHttpResourceExtractor; |
| 20 | +import com.alibaba.csp.sentinel.adapter.okhttp.fallback.DefaultOkHttpFallback; |
| 21 | +import com.alibaba.csp.sentinel.adapter.okhttp.fallback.OkHttpFallback; |
| 22 | +import com.alibaba.csp.sentinel.util.AssertUtil; |
| 23 | + |
| 24 | +/** |
| 25 | + * @author zhaoyuguang |
| 26 | + */ |
| 27 | +public final class SentinelOkHttpConfig { |
| 28 | + |
| 29 | + private static volatile String prefix = "okhttp:"; |
| 30 | + private static volatile OkHttpResourceExtractor extractor = new DefaultOkHttpResourceExtractor(); |
| 31 | + private static volatile OkHttpFallback fallback = new DefaultOkHttpFallback(); |
| 32 | + |
| 33 | + public static String getPrefix() { |
| 34 | + return prefix; |
| 35 | + } |
| 36 | + |
| 37 | + public static void setPrefix(String prefix) { |
| 38 | + AssertUtil.notNull(prefix, "prefix cannot be null"); |
| 39 | + SentinelOkHttpConfig.prefix = prefix; |
| 40 | + } |
| 41 | + |
| 42 | + public static OkHttpResourceExtractor getExtractor() { |
| 43 | + return extractor; |
| 44 | + } |
| 45 | + |
| 46 | + public static void setExtractor(OkHttpResourceExtractor extractor) { |
| 47 | + AssertUtil.notNull(extractor, "extractor cannot be null"); |
| 48 | + SentinelOkHttpConfig.extractor = extractor; |
| 49 | + } |
| 50 | + |
| 51 | + public static OkHttpFallback getFallback() { |
| 52 | + return fallback; |
| 53 | + } |
| 54 | + |
| 55 | + public static void setFallback(OkHttpFallback fallback) { |
| 56 | + AssertUtil.notNull(fallback, "fallback cannot be null"); |
| 57 | + SentinelOkHttpConfig.fallback = fallback; |
| 58 | + } |
| 59 | +} |
0 commit comments