public class ActionContext extends Object implements Map<String,Object>
变量上下文是执行动作时的变量空间,起到函数调用时栈的作用,是一个Stack和Map的综合体。
变量上下文通过栈的深度来表示全局变量和局部变量,深度越浅则越靠近全局变量,范围0是全局变量。
变量上下文是线程绑定的,除了创建时的变量时公用的,其他变量是线程各自的。
如果一个变量上下文的构造参数是另一个变量上下文,那么会先把用于构造的变量上下文的 所有变量绑定压入栈中,因此两个变量上下文将使用相同的全局变量,但使用各自的最新的 局部变量。由于原先的变量上下文的变量绑定被新的变量上下文所引用,因此当原先的动作 上下文把一个变量绑定移除栈的时候,新的变量上下文还保持这个变量绑定的引用,因此需要注意一下内存的问题。
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
BREAK
打断状态,一般返回到上一个循环处
|
static int |
CANCEL
取消的状态,取消当前的动作执行
|
static int |
CONTINUE
继续从循环处执行
|
static int |
EXCEPTION
抛出异常的状态,一般到异常处理处结束
|
static String |
RESULT_FAILURE |
static String |
RESULT_SUCCESS |
static int |
RETURN
返回值的状态,返回到动作被初始调用的地方
|
static int |
RUNNING
正常的运行状态
|
static String |
RUNTYPE_DEFAULT |
static String |
RUNTYPE_RANDOM |
static String |
RUNTYPE_RANDOM_ONE |
static String |
RUNTYPE_RANDOM_RANDOM |
static String |
RUNTYPE_RANDOM_RATE |
static String |
RUNTYPE_RANDOM_SUCCESS |
static String |
RUNTYPE_SUCCESS |
| 构造器和说明 |
|---|
ActionContext()
默认构造函数,并创建一个所有线程都共用的全局变量栈。
|
ActionContext(ActionContext actionContext)
通过给定的变量绑定创建变量上下文,其中传入的变量上下文的栈全部放入不可push和pop的栈中,
并压入一个新的所有线程都共用的全局变量栈,传入的变量上下文比新的全局变量更加全局。
|
ActionContext(Bindings bindings)
创建一个变量上下文,使用指定的全局变量Bindings。
|
ActionContext(boolean managedByPool) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<String,Object>> |
entrySet() |
Bindings |
g()
获取全局变量的缩写。
|
Object |
get(Object key) |
Object |
get(Object key,
String scopeThingPath) |
Action |
getAction() |
List<Action> |
getActions()
返回动作调用列表,最开始的是堆栈的底部,最后的是堆栈的顶部。
|
Bindings |
getGlobalScope()
获取全局变量。
|
Bindings |
getLocalScope()
获取当前本地变量.
|
Bindings |
getScope()
获取当前的局部变量范围。
|
Bindings |
getScope(int index)
返回指定范围的变量绑定。
|
Bindings |
getScope(String actionThingPath)
根据动作事物的路径来获得变量范围。
|
List<Bindings> |
getScopes()
返回变量绑定的列表。
|
int |
getScopesSize()
返回变脸范围的迭代大小。
|
int |
getScopesSizeAll()
返回所有包括线程之前创建的变量范围大小。
|
String |
getStackTrace()
获取当前堆栈信息。
|
int |
getStatus()
返回动作执行的状态。
|
List<Thing> |
getThings()
返回调用动作的事物列表,最开始的是堆栈的底部,最后的堆栈的顶部的事物。
|
Object |
getThrowedObject() |
boolean |
isDisableGlobalContext()
返回是否禁止了全局变量上下文。
|
boolean |
isEmpty() |
Set<String> |
keySet() |
Bindings |
l()
获取局部变量的缩写。
|
Bindings |
peek()
返回最顶层的变量绑定。
|
Bindings |
pop()
弹出最顶层的变量绑定。
|
void |
popAction() |
void |
printStackTrace()
打印堆栈信息到控制台。
|
Bindings |
push() |
Bindings |
push(Bindings bindings)
压入一个变量绑定到堆栈中,当传入的变量绑定为null时自动创建一个新的。
|
void |
pushAction(Action action) |
Bindings |
pushPoolBindings() |
Object |
put(String key,
Object value)
设置变量上下文中一个变量的值,设置值的方法是从栈的顶端的Bindings向栈底端的Bindings找,如果Bindings包含
相应的键那么调用Bindings的put方法,如果所有的Bingings都不包含给定的键值,没有那么设置到顶端的Bindings中。
|
Object |
put(String key,
Object value,
String scopeThingPath)
根据指定的事物从堆栈中寻找变量范围,并设置变量范围的值。
|
void |
putAll(Map<? extends String,? extends Object> m) |
Object |
putTo(String key,
String scopeThingPath)
把某个值放到指定的变量范围中。
|
Object |
remove(Object key) |
void |
setStatus(int status)
设置动作的执行状态。
|
void |
setThrowedObject(Object obj) |
int |
size() |
String |
toString() |
Collection<Object> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllpublic static final int RUNNING
public static final int RETURN
public static final int CANCEL
public static final int BREAK
public static final int CONTINUE
public static final int EXCEPTION
public ActionContext()
public ActionContext(boolean managedByPool)
public ActionContext(ActionContext actionContext)
actionContext - 变量上下文public ActionContext(Bindings bindings)
bindings - 变量范围public void pushAction(Action action)
public void popAction()
public Action getAction()
public int getStatus()
public boolean isDisableGlobalContext()
public void setStatus(int status)
status - 执行状态public Bindings push()
public Bindings push(Bindings bindings)
bindings - 变量绑定public Bindings pushPoolBindings()
public Bindings peek()
public Bindings pop()
public Bindings getScope()
public Bindings getLocalScope()
public Bindings getGlobalScope()
public Bindings g()
public Bindings l()
public String getStackTrace()
public void printStackTrace()
public Bindings getScope(int index)
index - 变量范围public Bindings getScope(String actionThingPath)
actionThingPath - 动作路径public int getScopesSize()
public int getScopesSizeAll()
public boolean containsKey(Object key)
containsKey 在接口中 Map<String,Object>public boolean containsValue(Object value)
containsValue 在接口中 Map<String,Object>public Object put(String key, Object value)
public Object put(String key, Object value, String scopeThingPath)
key - 变量的keyvalue - 变量的值scopeThingPath - 变量范围路径public Object putTo(String key, String scopeThingPath)
key - 变量keyscopeThingPath - 路径public void setThrowedObject(Object obj)
public Object getThrowedObject()
Copyright © 2016 xworker.org. All rights reserved.