2025-12-17 10:23:45 +08:00
|
|
|
|
package com.tuoheng.machine.instruction;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-12-18 10:31:20 +08:00
|
|
|
|
* 抽象指令基类,提供默认实现和下游节点管理
|
2025-12-17 10:23:45 +08:00
|
|
|
|
*/
|
|
|
|
|
|
public abstract class AbstractInstruction implements Instruction {
|
|
|
|
|
|
|
2025-12-18 10:31:20 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 成功后执行的下一个指令
|
|
|
|
|
|
*/
|
|
|
|
|
|
private Instruction onSuccessInstruction;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 失败后执行的下一个指令
|
|
|
|
|
|
*/
|
|
|
|
|
|
private Instruction onFailureInstruction;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 无论成功失败都执行的下一个指令
|
|
|
|
|
|
*/
|
|
|
|
|
|
private Instruction alwaysNextInstruction;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Instruction getOnSuccessInstruction() {
|
|
|
|
|
|
return onSuccessInstruction;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Instruction getOnFailureInstruction() {
|
|
|
|
|
|
return onFailureInstruction;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Instruction getAlwaysNextInstruction() {
|
|
|
|
|
|
return alwaysNextInstruction;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设置成功后执行的指令(支持链式调用)
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T extends AbstractInstruction> T onSuccess(Instruction instruction) {
|
|
|
|
|
|
this.onSuccessInstruction = instruction;
|
|
|
|
|
|
return (T) this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设置失败后执行的指令(支持链式调用)
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T extends AbstractInstruction> T onFailure(Instruction instruction) {
|
|
|
|
|
|
this.onFailureInstruction = instruction;
|
|
|
|
|
|
return (T) this;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设置无论成功失败都执行的指令(支持链式调用)
|
|
|
|
|
|
*/
|
|
|
|
|
|
public <T extends AbstractInstruction> T then(Instruction instruction) {
|
|
|
|
|
|
this.alwaysNextInstruction = instruction;
|
|
|
|
|
|
return (T) this;
|
|
|
|
|
|
}
|
2025-12-17 10:23:45 +08:00
|
|
|
|
}
|