| Constructor and Description |
|---|
ContextUtil() |
| Modifier and Type | Method and Description |
|---|---|
static int |
contextSize()
Get current size of context entrance node map.
|
static Context |
enter(String name)
Enter the invocation context, which marks as the entrance of an invocation chain.
|
static Context |
enter(String name,
String origin)
Enter the invocation context, which marks as the entrance of an invocation chain.
|
static void |
exit()
Exit context of current thread, that is removing
Context in the
ThreadLocal. |
static Context |
getContext()
Get
Context of current thread. |
static boolean |
isDefaultContext(Context context)
Check if provided context is a default auto-created context.
|
static void |
runOnContext(Context context,
Runnable f)
Execute the code within provided context.
|
protected static Context |
trueEnter(String name,
String origin) |
public static Context enter(String name, String origin)
Enter the invocation context, which marks as the entrance of an invocation chain.
The context is wrapped with ThreadLocal, meaning that each thread has it's own Context.
New context will be created if current thread doesn't have one.
A context will be bound with an EntranceNode, which represents the entrance statistic node
of the invocation chain. New EntranceNode will be created if
current context does't have one. Note that same context name will share
same EntranceNode globally.
The origin node will be created in ClusterBuilderSlot.
Note that each distinct origin of different resources will lead to creating different new
Node, meaning that total amount of created origin statistic nodes will be:
distinct resource name amount * distinct origin count.
So when there are too many origins, memory footprint should be carefully considered.
Same resource in different context will count separately, see NodeSelectorSlot.
name - the context nameorigin - the origin of this invocation, usually the origin could be the Service
Consumer's app name. The origin is useful when we want to control different
invoker/consumer separately.public static Context enter(String name)
Enter the invocation context, which marks as the entrance of an invocation chain.
The context is wrapped with ThreadLocal, meaning that each thread has it's own Context.
New context will be created if current thread doesn't have one.
A context will be bound with an EntranceNode, which represents the entrance statistic node
of the invocation chain. New EntranceNode will be created if
current context does't have one. Note that same context name will share
same EntranceNode globally.
Same resource in different context will count separately, see NodeSelectorSlot.
name - the context namepublic static void exit()
Context in the
ThreadLocal.public static int contextSize()
public static boolean isDefaultContext(Context context)
context - context to checkpublic static Context getContext()
Context of current thread.Copyright © 2021 Alibaba Group. All rights reserved.