我們可以看到flowable里面有很多命令模式,那么我們如何定義自己的命令呢?
學無止境,每天在睡覺前都問一下自己今天的時間有沒有揮霍。
1. 實現Command<Void>接口 泛型里面是我們的返回值的類型,這里用Void是無返回值的
重寫execute方法
2.使用ManagementService來執行命令
3.實例
public class NotifyTaskCompleteCmd implements Command<Void> { private String taskId; private TaskService taskService; public NotifyTaskCompleteCmd(TaskService taskService, String taskId) { this.taskService = taskService; this.taskId = taskId; } @Override public Void execute(CommandContext commandContext) { TaskEntity task = CommandContextUtil.getTaskService().getTask(taskId); if (task != null) { taskService.complete(taskId); } return null; } }
執行
managementService.executeCommand(new NotifyTaskCompleteCmd(taskService, taskVo.getTaskId()));