Java Code Examples for org.springframework.statemachine.listener.StateMachineListenerAdapter

The following examples show how to use org.springframework.statemachine.listener.StateMachineListenerAdapter. 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
Source Project: cloudbreak   Source File: AbstractFlowConfigurationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected MachineConfiguration<State, Event> getStateMachineConfiguration() {
    StateMachineConfigurationBuilder<State, Event> configurationBuilder =
            new StateMachineConfigurationBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    StateMachineStateBuilder<State, Event> stateBuilder =
            new StateMachineStateBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    StateMachineTransitionBuilder<State, Event> transitionBuilder =
            new StateMachineTransitionBuilder<>(ObjectPostProcessor.QUIESCENT_POSTPROCESSOR, true);
    StateMachineListener<State, Event> listener =
            new StateMachineListenerAdapter<State, Event>() {
                @Override
                public void eventNotAccepted(Message<Event> event) {
                    throw new NotAcceptedException();
                }
            };
    return new MachineConfiguration<>(configurationBuilder, stateBuilder, transitionBuilder, listener,
            new SyncTaskExecutor());
}
 
Example 4
@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());
        }
    };
}