org.springframework.statemachine.config.StateMachineBuilder Java Examples

The following examples show how to use org.springframework.statemachine.config.StateMachineBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StateMachineBuilderIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenUseStateMachineBuilder_thenBuildSuccessAndMachineWorks() throws Exception {
    StateMachineBuilder.Builder<String, String> builder = StateMachineBuilder.builder();
    builder.configureStates().withStates()
            .initial("SI")
            .state("S1")
            .end("SF");

    builder.configureTransitions()
            .withExternal()
            .source("SI").target("S1").event("E1")
            .and().withExternal()
            .source("S1").target("SF").event("E2");

    StateMachine machine = builder.build();

    machine.start();

    machine.sendEvent("E1");
    assertEquals("S1", machine.getState().getId());

    machine.sendEvent("E2");
    assertEquals("SF", machine.getState().getId());
}
 
Example #2
Source File: MachineFactory.java    From agile-service-old with Apache License 2.0 5 votes vote down vote up
private StateMachine<String, String> buildInstance(Long organizationId, String serviceCode, Long stateMachineId) {
    StateMachineBuilder.Builder<String, String> builder = instanceCache.getBuilder(stateMachineId);
    if (builder == null) {
        builder = getBuilder(organizationId, serviceCode, stateMachineId);
        logger.info("build StateMachineBuilder successful,stateMachineId:{}", stateMachineId);
        instanceCache.putBuilder(stateMachineId, builder);
    }
    StateMachine<String, String> smInstance = builder.build();
    smInstance.start();
    return smInstance;
}
 
Example #3
Source File: InstanceCache.java    From agile-service-old with Apache License 2.0 4 votes vote down vote up
/**
 * 缓存状态机构建器
 */
public void putBuilder(Long stateMachineId, StateMachineBuilder.Builder<String, String> builder) {
    builderMap.put(stateMachineId, builder);
}
 
Example #4
Source File: InstanceCache.java    From agile-service-old with Apache License 2.0 4 votes vote down vote up
/**
 * 获取状态机构建器
 */
public StateMachineBuilder.Builder<String, String> getBuilder(Long stateMachineId) {
    return builderMap.get(stateMachineId);
}