thingsboard-client-demo/src/main/java/com/tuoheng/machine/instruction/Instruction.java

53 lines
1.3 KiB
Java
Raw Normal View History

2025-12-17 10:23:45 +08:00
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) {
// 默认空实现
}
}