Search in sources :

Example 1 with StateMachineTransitionBuilder

use of org.springframework.statemachine.config.builders.StateMachineTransitionBuilder in project cloudbreak by hortonworks.

the class AbstractFlowConfiguration method getStateMachineConfiguration.

protected MachineConfiguration<S, E> getStateMachineConfiguration() {
    StateMachineConfigurationBuilder<S, E> configurationBuilder = new StateMachineConfigurationBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    StateMachineStateBuilder<S, E> stateBuilder = new StateMachineStateBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    StateMachineTransitionBuilder<S, E> transitionBuilder = new StateMachineTransitionBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    StateMachineListener<S, E> listener = new StateMachineListenerAdapter<S, E>() {

        @Override
        public void stateChanged(State<S, E> from, State<S, E> to) {
            LOGGER.debug("state changed from {} to {}", from, to);
        }

        @Override
        public void eventNotAccepted(Message<E> event) {
            LOGGER.error("{} not accepted event: {}", getClass().getSimpleName(), event);
        }
    };
    return new MachineConfiguration<>(configurationBuilder, stateBuilder, transitionBuilder, listener, new SyncTaskExecutor());
}
Also used : Message(org.springframework.messaging.Message) StateMachineStateBuilder(org.springframework.statemachine.config.builders.StateMachineStateBuilder) SyncTaskExecutor(org.springframework.core.task.SyncTaskExecutor) StateMachineConfigurationBuilder(org.springframework.statemachine.config.builders.StateMachineConfigurationBuilder) StateMachineTransitionBuilder(org.springframework.statemachine.config.builders.StateMachineTransitionBuilder) FlowState(com.sequenceiq.cloudbreak.core.flow2.FlowState) State(org.springframework.statemachine.state.State) StateMachineListenerAdapter(org.springframework.statemachine.listener.StateMachineListenerAdapter)

Example 2 with StateMachineTransitionBuilder

use of org.springframework.statemachine.config.builders.StateMachineTransitionBuilder in project cloudbreak by hortonworks.

the class AbstractActionTest method setup.

@Before
public void setup() throws Exception {
    underTest = spy(new TestAction());
    underTest.setFailureEvent(Event.FAILURE);
    MockitoAnnotations.initMocks(this);
    BDDMockito.given(flow.getFlowId()).willReturn(FLOW_ID);
    BDDMockito.given(runningFlows.get(anyString())).willReturn(flow);
    StateMachineConfigurationBuilder<State, Event> configurationBuilder = new StateMachineConfigurationBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    configurationBuilder.setTaskExecutor(new SyncTaskExecutor());
    StateMachineStateBuilder<State, Event> stateBuilder = new StateMachineStateBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    stateBuilder.withStates().initial(State.INIT).state(State.DOING, underTest, null);
    StateMachineTransitionBuilder<State, Event> transitionBuilder = new StateMachineTransitionBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    transitionBuilder.withExternal().source(State.INIT).target(State.DOING).event(Event.DOIT);
    stateMachine = new ObjectStateMachineFactory<>(configurationBuilder.build(), transitionBuilder.build(), stateBuilder.build()).getStateMachine();
    stateMachine.start();
}
Also used : SyncTaskExecutor(org.springframework.core.task.SyncTaskExecutor) StateMachineConfigurationBuilder(org.springframework.statemachine.config.builders.StateMachineConfigurationBuilder) StateMachineTransitionBuilder(org.springframework.statemachine.config.builders.StateMachineTransitionBuilder) StateMachineStateBuilder(org.springframework.statemachine.config.builders.StateMachineStateBuilder) ObjectStateMachineFactory(org.springframework.statemachine.config.ObjectStateMachineFactory) Before(org.junit.Before)

Aggregations

SyncTaskExecutor (org.springframework.core.task.SyncTaskExecutor)2 StateMachineConfigurationBuilder (org.springframework.statemachine.config.builders.StateMachineConfigurationBuilder)2 StateMachineStateBuilder (org.springframework.statemachine.config.builders.StateMachineStateBuilder)2 StateMachineTransitionBuilder (org.springframework.statemachine.config.builders.StateMachineTransitionBuilder)2 FlowState (com.sequenceiq.cloudbreak.core.flow2.FlowState)1 Before (org.junit.Before)1 Message (org.springframework.messaging.Message)1 ObjectStateMachineFactory (org.springframework.statemachine.config.ObjectStateMachineFactory)1 StateMachineListenerAdapter (org.springframework.statemachine.listener.StateMachineListenerAdapter)1 State (org.springframework.statemachine.state.State)1