提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.env.core.context; |
H |
2 |
|
|
3 |
import cn.hutool.core.collection.CollUtil; |
|
4 |
import com.alibaba.ttl.TransmittableThreadLocal; |
|
5 |
|
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
/** |
|
10 |
* 开发环境上下文 |
|
11 |
* |
|
12 |
* @author iailab |
|
13 |
*/ |
|
14 |
public class EnvContextHolder { |
|
15 |
|
|
16 |
/** |
|
17 |
* 标签的上下文 |
|
18 |
* |
|
19 |
* 使用 {@link List} 的原因,可能存在多层设置或者清理 |
|
20 |
*/ |
|
21 |
private static final ThreadLocal<List<String>> TAG_CONTEXT = TransmittableThreadLocal.withInitial(ArrayList::new); |
|
22 |
|
|
23 |
public static void setTag(String tag) { |
|
24 |
TAG_CONTEXT.get().add(tag); |
|
25 |
} |
|
26 |
|
|
27 |
public static String getTag() { |
|
28 |
return CollUtil.getLast(TAG_CONTEXT.get()); |
|
29 |
} |
|
30 |
|
|
31 |
public static void removeTag() { |
|
32 |
List<String> tags = TAG_CONTEXT.get(); |
|
33 |
if (CollUtil.isEmpty(tags)) { |
|
34 |
return; |
|
35 |
} |
|
36 |
tags.remove(tags.size() - 1); |
|
37 |
} |
|
38 |
|
|
39 |
} |