@ Override public synchronized void run ( ) { LOGGER . info ( "run " + currentState . getClass ( ) . getSimpleName ( ) + "..." ) ; if ( currentState == null ) { throw new IllegalStateException ( "No initial state defined." ) ; } while ( currentState != null ) { LOGGER . debug ( "execute " + currentState ) ; final Class < ? extends State > nextStateClass ; try { nextStateClass = currentState . call ( ) ; } catch ( CouldNotPerformException ex ) { ExceptionPrinter . printHistory ( "Something went wrong during state execution!" , ex , LOGGER ) ; if ( Thread . currentThread ( ) . isInterrupted ( ) ) { return ; } continue ; } catch ( Throwable t ) { ExceptionPrinter . printHistory ( "State failed: " , t , LOGGER ) ; change . firePropertyChange ( STATE_ERROR , currentState . getClass ( ) , t . getMessage ( ) ) ; return ; } change . firePropertyChange ( STATE_CHANGE , currentState . getClass ( ) , nextStateClass ) ; if ( nextStateClass != null ) { LOGGER . info ( "StateChange: " + currentState . getClass ( ) . getSimpleName ( ) + " -> " + nextStateClass . getSimpleName ( ) ) ; try { currentState = getState ( nextStateClass ) ; } catch ( NotAvailableException ex ) { ExceptionPrinter . printHistory ( "State change failed!" , ex , LOGGER ) ; } } } LOGGER . info ( "finished execution." ) ; }
Method starts the state machine . Because this class is implementing the runnable interface its not recommended to call this method manually . Start the state machine via the global executor service .