Java Code Examples for org.springframework.statemachine.state.State

The following examples show how to use org.springframework.statemachine.state.State. These examples are extracted from open source projects. 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
@Override
public void configure(StateMachineConfigurationConfigurer<SkipperStates, SkipperEvents> config) throws Exception {
	config
		.withConfiguration()
			.taskExecutor(skipperStateMachineTaskExecutor)
			// this is to simply add logging for state enters
			.listener(new StateMachineListenerAdapter<SkipperStates, SkipperEvents>() {
				@Override
				public void stateEntered(State<SkipperStates, SkipperEvents> state) {
					log.info("Entering state {}", state);
				}
			})
			.transitionConflictPolicy(TransitionConflictPolicy.PARENT)
		.and()
		.withPersistence()
			.runtimePersister(stateMachineRuntimePersister);
}
 
Example 2
Source Project: cloudbreak   Source File: AbstractFlowConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
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<>() {
                @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());
}
 
Example 3
@Bean
public StateMachineListener<States, Events> listener() {
    return new StateMachineListenerAdapter<States, Events>() {
        @Override
        public void stateChanged(State<States, Events> from, State<States, Events> to) {
            System.out.println("State change to " + to.getId());
        }
    };
}
 
Example 4
Source Project: cloudbreak   Source File: FlowStructuredEventHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void stateMachineStopped(StateMachine<S, E> stateMachine) {
    if (!stateMachine.isComplete()) {
        State<S, E> currentState = stateMachine.getState();
        Long currentTime = System.currentTimeMillis();
        String fromId = currentState != null ? currentState.getId().toString() : "unknown";
        FlowDetails flowDetails = new FlowDetails("", flowType, "", flowId, fromId, "unknown", "FLOW_CANCEL",
                lastStateChange == null ? 0L : currentTime - lastStateChange);
        StructuredEvent structuredEvent = structuredFlowEventFactory.createStucturedFlowEvent(stackId, flowDetails, true);
        structuredEventClient.sendStructuredEvent(structuredEvent);
        lastStateChange = currentTime;
    }
}
 
Example 5
Source Project: cloudbreak   Source File: FlowStructuredEventHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void stateChanged(State<S, E> from, State<S, E> to) {
}
 
Example 6
Source Project: tutorials   Source File: StateMachineListener.java    License: MIT License 4 votes vote down vote up
@Override
public void stateChanged(State from, State to) {
    LOGGER.info(() -> String.format("Transitioned from %s to %s%n", from == null ? "none" : from.getId(), to.getId()));
}
 
Example 7
Source Project: cloudbreak   Source File: FlowStructuredEventHandler.java    License: Apache License 2.0 2 votes vote down vote up
@Override
public void stateEntered(State<S, E> state) {

}
 
Example 8
Source Project: cloudbreak   Source File: FlowStructuredEventHandler.java    License: Apache License 2.0 2 votes vote down vote up
@Override
public void stateExited(State<S, E> state) {

}