java.lang.Object
cn.wjybxx.btree.Task<T>
cn.wjybxx.btree.BranchTask<T>
cn.wjybxx.btree.branch.SingleRunningChildBranch<T>
cn.wjybxx.btree.branch.Switch<T>
- 所有已实现的接口:
ICancelTokenListener
- 直接已知子类:
FixedSwitch
Switch-选择一个分支运行,直到其结束
Switch的基础实现通过逐个检测child的前置条件实现选择,在分支较多的情况下可能开销较大,
在多数情况下,我们可能只是根据配置选择一个分支,可选择SwitchHandler实现。
Q:为什么Switch要支持内联? A:Switch有一个重要的用途:决策树。在做出决策以后,中间层的节点就没有价值了,而保留它们会导致较大的运行时开销。
- 作者:
- wjybxx date - 2023/11/26
-
字段概要
从类继承的字段 cn.wjybxx.btree.branch.SingleRunningChildBranch
inlineHelper, runningChild, runningIndex从类继承的字段 cn.wjybxx.btree.BranchTask
children -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidexecute()Task的心跳方法,在Task进入完成状态之前会反复执行。SwitchHandler<? super T> protected voidonChildCompleted(Task<T> child) 子类的实现模板:protected voidonChildRunning(Task<T> child, boolean starting) 子类如果支持内联,则重写该方法voidsetHandler(SwitchHandler<? super T> handler) 从类继承的方法 cn.wjybxx.btree.branch.SingleRunningChildBranch
beforeEnter, exit, getCompletedCount, getInlineHelper, getRunningChild, getRunningIndex, getSucceededCount, illegalStateMsg, isAllChildCompleted, nextChild, onEventImpl, resetForRestart, stopRunningChildren从类继承的方法 cn.wjybxx.btree.BranchTask
addChildImpl, getChild, getChildCount, getChildren, getFirstChild, getLastChild, indexChild, isFirstChild, isLastChild, removeChildImpl, setChildImpl, setChildren, shuffleChild, visitChildren从类继承的方法 cn.wjybxx.btree.Task
addChild, canHandleEvent, checkCancel, enter, exportControlFlowOptions, getBlackboard, getCancelToken, getControl, getControlData, getControlFlowOptions, getEnterFrame, getEntity, getExitFrame, getFlags, getGuard, getNormalizedStatus, getPrevStatus, getReentryId, getRunFrames, getSharedProps, getStatus, getTaskEntry, isActiveInHierarchy, isActiveSelf, isAutoListenCancel, isAutoResetChildren, isBlackboardPerChild, isBreakInline, isCancelled, isCancelTokenPerChild, isCheckingGuard, isCompleted, isExited, isFailed, isFailedOrCancelled, isInlinable, isInvertedGuard, isManualCheckCancel, isRunning, isSlowStart, isStillborn, isSucceeded, onActiveInHierarchyChanged, onCancelRequested, onEvent, refreshActiveInHierarchy, registerCancelListener, removeAllChild, removeChild, removeChild, resetChildrenForRestart, resetForRestart, setActive, setAutoListenCancel, setAutoResetChildren, setBlackboard, setBlackboardPerChild, setBreakInline, setCancelled, setCancelToken, setCancelTokenPerChild, setChild, setChildCancelToken, setCompleted, setControl, setControlData, setEnterFrame, setExitFrame, setFailed, setFlags, setGuard, setGuardFailed, setInvertedGuard, setManualCheckCancel, setPrevStatus, setSharedProps, setSlowStart, setSuccess, stop, stop, stop, template_checkGuard, template_execute, template_executeInlined, template_startChild, template_startHook, unsetChildCancelToken, unsetControl
-
构造器详细资料
-
Switch
public Switch()
-
-
方法详细资料
-
execute
protected void execute()从类复制的说明:TaskTask的心跳方法,在Task进入完成状态之前会反复执行。 1.运行中可通过Task.setSuccess()、Task.setFailed(int)、Task.setCancelled()将自己更新为完成状态。 2.如果不想和Task.enter(int)同步执行,可通过Task.setSlowStart(boolean)实现。 3.不建议直接调用该方法,而是通过模板方法Task.template_execute(boolean)运行。- 覆盖:
execute在类中SingleRunningChildBranch<T>
-
onChildRunning
从类复制的说明:SingleRunningChildBranch子类如果支持内联,则重写该方法- 覆盖:
onChildRunning在类中SingleRunningChildBranch<T>- 参数:
starting- 是否是启动时调用,即首次调用
-
onChildCompleted
从类复制的说明:SingleRunningChildBranch子类的实现模板:
ps: 推荐子类重复编码避免调用superprotected void onChildCompleted(Task child) { runningChild = null; inlinedHolder.stopInline(); // 尝试计算结果(记得处理取消) ... // 如果未得出结果 if (!isExecuting()) { template_execute(); } }- 覆盖:
onChildCompleted在类中SingleRunningChildBranch<T>
-
getHandler
-
setHandler
-