feat: 状态机切换状态时更灵活.

This commit is contained in:
2025-01-13 14:25:38 +08:00
parent 08cca7ae61
commit 7a8d5187b9
3 changed files with 191 additions and 87 deletions

View File

@@ -24,8 +24,8 @@ public class MachineTest {
.async()
.standard()
.executor(Executors.newFixedThreadPool(16))
.whenLeave(PrinterState.PRINTING, h -> {
System.out.println(Thread.currentThread().getName() + ": leave PRINTING");
.whenLeave(PrinterState.IDLE, h -> {
System.out.println(Thread.currentThread().getName() + ": leave IDLE");
})
.whenEntry(PrinterState.STOPPING, h -> {
System.out.println(Thread.currentThread().getName() + ": entry STOPPING, from " + h.getFrom());
@@ -35,14 +35,7 @@ public class MachineTest {
})
.build();
System.out.println(stateMachine.getClass());
stateMachine.switchTo(PrinterState.PRINTING);
stateMachine.switchNext();
stateMachine.switchNext();
System.out.println(stateMachine.current());
stateMachine.switchNext(false);
stateMachine.close();
}
}