java.lang.Object
cn.wjybxx.concurrent.Context<T>
- 所有已实现的接口:
IContext
默认上下文实现
黑板类型
默认实现假设了父上下文和当前上下文的黑板类型一致,这个假设并不总是成立,但一般情况下是如此; 如果该实现不满足需求,用户可实现自己的上下文类型。- 作者:
- wjybxx date - 2023/11/18
-
字段概要
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明任务运行时依赖的黑板(主要上下文) 1.每个任务可有独立的黑板(数据); 2.一般而言,黑板需要实现递归向上查找。任务绑定的取消令牌(取消上下文) 1.每个任务可有独立的取消信号 -- 私有属性。childWith(Object state, ICancelToken cancelToken, T blackboard, Object sharedProps) childWithBlackboard(T blackboard) childWithBlackboard(T blackboard, Object sharedProps) childWithState(Object state) childWithState(Object state, ICancelToken cancelToken) newContext(Context<T> parent, Object state, ICancelToken cancelToken, T blackboard, Object sharedProps) 用于子类重写static <U> Context<U> ofBlackboard(U blackboard) static <U> Context<U> ofBlackboard(U blackboard, Object sharedProps) static <U> Context<U> ofCancelToken(ICancelToken cancelToken) static <U> Context<U> static <U> Context<U> ofState(Object state, ICancelToken cancelToken) static <U> Context<U> ofState(Object state, ICancelToken cancelToken, U blackboard, Object sharedProps) parent()父上下文 由于我们没有提供默认的黑板实现,因此需要支持用户迭代上下文。root()根上下文 1.根上下文中可能保存着一些有用的行为。共享属性(配置上下文) 1.用于支持【数据和行为分离】的Task体系。state()任务绑定的状态 1.任务之间通常不共享 -- 私有属性。with(Object state, ICancelToken cancelToken, T blackboard, Object sharedProps) withBlackboard(T blackboard) withBlackboard(T blackboard, Object sharedProps) withState(Object state, ICancelToken cancelToken)
-
构造器详细资料
-
Context
-
Context
-
Context
public Context(Context<T> parent, Object state, ICancelToken cancelToken, T blackboard, Object sharedProps) 一般不建议直接调用该方法,而是通过withBlackboard(Object)等创建子上下文,否则无法处理上下文继承问题。- 参数:
parent- 父节点state- 任务绑定的状态cancelToken- 取消令牌blackboard- 黑板sharedProps- 共享属性
-
-
方法详细资料
-
root
根上下文 1.根上下文中可能保存着一些有用的行为。 2.记录更上下文可以避免深度的递归查找。 3.没有父节点的Context的根为自己。默认的实现不缓存(root)上下文,如果用户需要频繁访问root上下文,可实现自己的上下文类型, 将root缓存在每一级的context上,以减少查找开销。
-
parent
父上下文 由于我们没有提供默认的黑板实现,因此需要支持用户迭代上下文。 -
state
从接口复制的说明:IContext任务绑定的状态 1.任务之间通常不共享 -- 私有属性。 2.运行时可能为null。 -
cancelToken
从接口复制的说明:IContext任务绑定的取消令牌(取消上下文) 1.每个任务可有独立的取消信号 -- 私有属性。 2.运行时不为null - 可返回ICancelToken.NONE。- 指定者:
cancelToken在接口中IContext
-
blackboard
从接口复制的说明:IContext任务运行时依赖的黑板(主要上下文) 1.每个任务可有独立的黑板(数据); 2.一般而言,黑板需要实现递归向上查找。这里未直接实现为类似Map的读写接口,是故意的。 因为提供类似Map的读写接口,会导致创建Context的开销变大,而在许多情况下是不必要的。 将黑板设定为Object类型,既可以增加灵活性,也可以减少一般情况下的开销。
- 指定者:
blackboard在接口中IContext
-
ofBlackboard
-
ofBlackboard
-
ofState
-
ofState
-
ofState
public static <U> Context<U> ofState(Object state, ICancelToken cancelToken, U blackboard, Object sharedProps) -
ofCancelToken
-
newContext
protected Context<T> newContext(Context<T> parent, Object state, ICancelToken cancelToken, T blackboard, Object sharedProps) 用于子类重写- 参数:
parent- 父节点state- 任务绑定的状态cancelToken- 取消令牌blackboard- 黑板sharedProps- 共享属性
-
childWithState
-
childWithState
-
childWithBlackboard
-
childWithBlackboard
-
childWith
-
withState
-
withState
-
withBlackboard
-
withBlackboard
-
with
-