55 lines
1.1 KiB
Java
55 lines
1.1 KiB
Java
|
|
package com.tuoheng.machine.command;
|
|||
|
|
|
|||
|
|
import com.tuoheng.machine.instruction.Instruction;
|
|||
|
|
import lombok.Data;
|
|||
|
|
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.List;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 事务(由多个指令组成)
|
|||
|
|
*/
|
|||
|
|
@Data
|
|||
|
|
public class Transaction {
|
|||
|
|
/**
|
|||
|
|
* 事务名称
|
|||
|
|
*/
|
|||
|
|
private String name;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 命令类型
|
|||
|
|
*/
|
|||
|
|
private CommandType commandType;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 指令列表(按顺序执行)
|
|||
|
|
*/
|
|||
|
|
private List<Instruction> instructions = new ArrayList<>();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 事务超时时间(毫秒)
|
|||
|
|
*/
|
|||
|
|
private long timeoutMs = 120000; // 默认2分钟
|
|||
|
|
|
|||
|
|
public Transaction(String name, CommandType commandType) {
|
|||
|
|
this.name = name;
|
|||
|
|
this.commandType = commandType;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 添加指令
|
|||
|
|
*/
|
|||
|
|
public Transaction addInstruction(Instruction instruction) {
|
|||
|
|
this.instructions.add(instruction);
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 设置超时时间
|
|||
|
|
*/
|
|||
|
|
public Transaction setTimeout(long timeoutMs) {
|
|||
|
|
this.timeoutMs = timeoutMs;
|
|||
|
|
return this;
|
|||
|
|
}
|
|||
|
|
}
|