hekailiang / squirrel

squirrel-foundation is a State Machine library, which provided a lightweight, easy use, type safe and programmable state machine implementation for Java.
http://hekailiang.github.io/squirrel/
Other
2.19k stars 540 forks source link

Set id of state machine #124

Closed facelezzzz closed 3 years ago

facelezzzz commented 3 years ago

I want to order a special id for a state machine

In AbstractStateMachine.class

data.write().identifier(configuration.getIdProvider().get());

but there is no way set it manually.Id provider is only invoked by no-arg method

hekailiang commented 3 years ago

StateMachineConfiguration.getInstance().setIdProvider(...) you can refer to org.squirrelframework.foundation.fsm.UntypedStateMachineTest#testStateMachineConfiguration

facelezzzz commented 3 years ago

Thanks for your response

I know that there is StateMachineConfiguration.getInstance().setIdProvider(...),but i need a hook to set id manually rather than set id provider manually.

When a state machine created, I want: builder.newStateMachine(TaskFSMStates.CREATED).setId("32893719287");//of course setId is not present now

Shortly, I want to attach a business id to the state machine after creation.

azhuchkov commented 3 years ago

It's possible passing StateMachineConfiguration into builder.newStateMachine() method. Something like:

final StateMachineConfiguration configuration = StateMachineConfiguration.create();

configuration.setIdProvider(() -> "32893719287");

BUILDER.newStateMachine(State.INIT, configuration, new Object[0]);