change: 代码清理、注释修复.

This commit is contained in:
2025-03-27 08:56:25 +08:00
parent 494f093041
commit 974b0ffe6d
7 changed files with 16 additions and 23 deletions

View File

@@ -1,6 +1,8 @@
package com.serliunx.statemanagement.exception;
/**
* 状态机异常
*
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
* @version 1.0.0
* @since 2024/12/28

View File

@@ -13,6 +13,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
/**
* 状态机上下文集合, 用于构建参数封装
*
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
* @version 1.0.0
* @since 2025/2/2

View File

@@ -9,7 +9,6 @@ package com.serliunx.statemanagement.machine.handler;
* @version 1.0.0
* @since 2024/12/28
*/
@SuppressWarnings("all")
public final class StateHandlerProcessParams<S> {
/**
@@ -29,7 +28,6 @@ public final class StateHandlerProcessParams<S> {
* @param from 原状态
* @param to 目标状态
* @param attach 附加参数
* @param bidirectionalStateManager 状态机内置的状态管理器
*/
public StateHandlerProcessParams(S from, S to, Object attach) {
this.from = from;

View File

@@ -1,10 +0,0 @@
package com.serliunx.statemanagement.machine.handler;
/**
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
* @version 1.0.0
* @since 2024/12/28
*/
public class StateHandlerRegistry {
}

View File

@@ -11,7 +11,6 @@ import java.util.concurrent.Executor;
* @version 1.0.0
* @since 2024/12/28
*/
@SuppressWarnings("all")
public final class StateHandlerWrapper<S> {
/**

View File

@@ -33,6 +33,7 @@ public interface StateManager<S> {
/**
* 获取当前状态数量
*
* @return 数量
*/
int size();

View File

@@ -21,8 +21,11 @@ public class MachineTest {
@Test
public void testStandardStateMachine() throws Exception {
StateMachine<PrinterState> stateMachine = StateMachineBuilder.from(PrinterState.values())
.async(true)
.async(false)
.standard()
.exchange(PrinterState.IDLE, PrinterState.SCANNING, h -> {
System.out.println("hello~");
})
.whenLeave(PrinterState.IDLE, h -> {
System.out.println(Thread.currentThread().getName() + ": leave IDLE");
})
@@ -32,28 +35,26 @@ public class MachineTest {
.whenEntry(PrinterState.STOPPED, h -> {
System.out.println(Thread.currentThread().getName() + ": entry STOPPED, from " + h.getFrom());
})
.whenHappened(PrinterEvent.TURN_ON, m -> {
m.switchTo(PrinterState.SCANNING);
})
.whenHappened(PrinterEvent.TURN_OFF, m -> {
if (m.switchTo(PrinterState.STOPPING))
m.switchTo(PrinterState.STOPPED);
})
.build();
stateMachine.publish(PrinterEvent.TURN_ON);
stateMachine.switchTo(PrinterState.SCANNING);
}
@Test
public void testConcurrentStateMachine() throws Exception {
ConcurrentStateMachine<PrinterState> stateMachine = StateMachineBuilder.from(PrinterState.values())
.async()
.whenEntry(PrinterState.STOPPING, h -> {
System.out.println(1111);
})
.whenHappened(PrinterEvent.TURN_OFF, l -> {
if (l.switchTo(PrinterState.STOPPING))
l.switchTo(PrinterState.STOPPED);
})
.concurrent()
.build();
System.out.println(stateMachine.compareAndSet(PrinterState.IDLE, PrinterState.STOPPING, true));
stateMachine.publish(PrinterEvent.TURN_OFF);
stateMachine.close();
}