类 ContextUtil
Context in current thread.
Each SphU#entry() or SphO#entry() should be in a Context.
If we don't invoke ContextUtil#enter() explicitly, DEFAULT context will be used.
- 作者:
- jialiang.linjl, leyou(lihao), Eric Zhao
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static intGet current size of context entrance node map.static ContextEnter the invocation context, which marks as the entrance of an invocation chain.static ContextEnter the invocation context, which marks as the entrance of an invocation chain.static voidexit()Exit context of current thread, that is removingContextin the ThreadLocal.static ContextGetContextof current thread.static booleanisDefaultContext(Context context) Check if provided context is a default auto-created context.static voidrunOnContext(Context context, Runnable f) Execute the code within provided context.protected static Context
-
构造器详细资料
-
ContextUtil
public ContextUtil()
-
-
方法详细资料
-
enter
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 ownContext. 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. NewEntranceNodewill be created if current context does't have one. Note that same context name will share sameEntranceNodeglobally.The origin node will be created in
ClusterBuilderSlot. Note that each distinctoriginof different resources will lead to creating different newNode, 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.- 返回:
- The invocation context of the current thread
-
trueEnter
-
enter
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 ownContext. 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. NewEntranceNodewill be created if current context does't have one. Note that same context name will share sameEntranceNodeglobally.Same resource in different context will count separately, see
NodeSelectorSlot.- 参数:
name- the context name- 返回:
- The invocation context of the current thread
-
exit
public static void exit()Exit context of current thread, that is removingContextin the ThreadLocal. -
contextSize
public static int contextSize()Get current size of context entrance node map.- 返回:
- current size of context entrance node map
- 从以下版本开始:
- 0.2.0
-
isDefaultContext
Check if provided context is a default auto-created context.- 参数:
context- context to check- 返回:
- true if it is a default context, otherwise false
- 从以下版本开始:
- 0.2.0
-
getContext
GetContextof current thread.- 返回:
- context of current thread. Null value will be return if current thread does't have context.
-
runOnContext
Execute the code within provided context. This is mainly designed for context switching (e.g. in asynchronous invocation).- 参数:
context- the contextf- lambda to run within the context- 从以下版本开始:
- 0.2.0
-