53 lines
1.3 KiB
Java
53 lines
1.3 KiB
Java
|
|
package com.tuoheng.machine.instruction;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 指令接口
|
|||
|
|
* 一个指令包含四个部分:
|
|||
|
|
* a. 判断是否可以执行该指令
|
|||
|
|
* b. 执行远程调用(如MQTT发送)
|
|||
|
|
* c. 等待方法回调,并判断该方法是否成功执行
|
|||
|
|
* d. 等待状态回调,并判断结果是否OK
|
|||
|
|
*/
|
|||
|
|
public interface Instruction {
|
|||
|
|
/**
|
|||
|
|
* 获取指令名称
|
|||
|
|
*/
|
|||
|
|
String getName();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* a. 判断是否可以执行该指令
|
|||
|
|
*/
|
|||
|
|
boolean canExecute(InstructionContext context);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* b. 执行远程调用(如MQTT发送)
|
|||
|
|
*/
|
|||
|
|
void executeRemoteCall(InstructionContext context) throws Exception;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* c. 获取方法回调配置(可选)
|
|||
|
|
* 返回null表示不需要方法回调
|
|||
|
|
*/
|
|||
|
|
CallbackConfig getMethodCallbackConfig(InstructionContext context);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* d. 获取状态回调配置(可选)
|
|||
|
|
* 返回null表示不需要状态回调
|
|||
|
|
*/
|
|||
|
|
CallbackConfig getStateCallbackConfig(InstructionContext context);
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取指令超时时间(毫秒)
|
|||
|
|
*/
|
|||
|
|
default long getTimeoutMs() {
|
|||
|
|
return 60000; // 默认60秒
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 指令执行完成回调(无论成功失败都会调用)
|
|||
|
|
*/
|
|||
|
|
default void onComplete(InstructionContext context, InstructionResult result) {
|
|||
|
|
// 默认空实现
|
|||
|
|
}
|
|||
|
|
}
|