Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Spring Framework - State Machine
    primarykey
    data
    text
    <p>I've been looking at refactoring some should be transactional code into modules where I can apply the state machine pattern on. Initially, I created the following classes:</p> <pre><code>public interface IExecutableState { public void execute(); } public class StateMachine { // final: private static final Logger LOGGER = Logger.getLogger(StateMachine.class); // instance private: private HashMap&lt;String, State&gt; validStates; private State currentState; // getters: public HashMap&lt;String, State&gt; getValidStates() { return this.validStates; } public State getCurrentState() { return this.currentState; } // setters: public void setValidStates(HashMap&lt;String, State&gt; validStates) { // assign the stateMachine attribute to each State from this setter, so that Spring doesn't enter an infinite loop while constructing a Prototype scoped StateMachine. for (State s : validStates.values()) { // validate that the State is defined with implements IExecutableState if (!(s instanceof IExecutableState)) { LOGGER.error("State: " + s.toString() + " does not implement IExecutableState."); throw new RuntimeException("State: " + s.toString() + " does not implement IExecutableState."); } LOGGER.trace("Setting stateMachine on State: " + s.toString() + " to: " + this.toString() + "."); s.setStateMachine(this); } LOGGER.trace("Setting validStates: " + validStates.toString() + "."); this.validStates = validStates; } public void setCurrentState(State currentState) { if (!(currentState instanceof IExecutableState)) { LOGGER.error("State: " + currentState.toString() + " does not implement IExecutableState."); throw new RuntimeException("State: " + currentState.toString() + " does not implement IExecutableState."); } LOGGER.trace("Setting currentState to: " + currentState.toString() + "."); this.currentState = currentState; } } public class State { private StateMachine stateMachine; public StateMachine getStateMachine() { return this.stateMachine; } public void setStateMacine(StateMachine stateMachine) { this.stateMachine = stateMachine; } } </code></pre> <p>All states would look like: <code>public class &lt;StateName&gt; extends State implements IExecutableState { ... }</code>.</p> <p>Then, with this model, I wanted to create a prototype scoped spring bean to instantiate the stateMachine, and assign it all of the states.</p> <p>However, after looking at some of the things available in Spring WebFlow, I started to see WebFlows, which emulate the State Machine behavior I seek, flawlessly. And, in a manner that allows for a visual representation of each state flow I create from XML.</p> <p>The only issue I'm finding, is the WebFlows are meant for Web Projects / Web Applications / Web Sites (whichever you want to classify them as). I am looking for something very similar to the <code>&lt;view-state&gt;</code> tags you get in spring webflow, but for an application that is running in a spring-core, spring-integration, or spring-batch project.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload