2424import java .util .Map ;
2525import java .util .Set ;
2626
27+ import com .cloud .utils .db .DB ;
28+ import com .cloud .utils .db .Transaction ;
29+
2730/**
2831 * StateMachine is a partial implementation of a finite state machine.
2932 * Specifically, it implements the Moore machine.
@@ -94,6 +97,7 @@ public List<S> getFromStates(S s, E e) {
9497 return entry .prevStates .get (e );
9598 }
9699
100+ @ DB
97101 public boolean transitTO (V vo , E e ) {
98102 S currentState = vo .getState ();
99103 S nextState = getNextState (currentState , e );
@@ -102,13 +106,23 @@ public boolean transitTO(V vo, E e) {
102106 if (nextState == null ) {
103107 transitionStatus = false ;
104108 }
109+
110+ Transaction txn = Transaction .currentTxn ();
111+ txn .start ();
105112
106- transitionStatus = _instanceDao . updateState ( currentState , e , nextState , vo );
113+ try {
107114
108- for (StateListener <S ,E , V > listener : _listeners ) {
109- listener .processStateTransitionEvent (currentState , e , nextState , vo , transitionStatus );
110- }
115+ transitionStatus = _instanceDao .updateState (currentState , e , nextState , vo );
116+
117+ for (StateListener <S ,E , V > listener : _listeners ) {
118+ listener .processStateTransitionEvent (currentState , e , nextState , vo , transitionStatus );
119+ }
120+ txn .commit ();
111121
122+ } catch (Exception ex ) {
123+ txn .rollback ();
124+ }
125+
112126 return transitionStatus ;
113127 }
114128
0 commit comments