private boolean setState ( State newState ) { switch ( newState ) { case DEPLOYED : return changeState ( State . DEPLOYING , State . DEPLOYED ) ; case DEPLOYING : //can move from either UNDEPLOYED or FAILED into DEPLOYING state return ( changeState ( State . UNDEPLOYED , State . DEPLOYING ) || changeState ( State . FAILED , State . DEPLOYING ) ) ; case UNDEPLOYING : return changeState ( State . DEPLOYED , State . UNDEPLOYING ) ; case UNDEPLOYED : return changeState ( State . UNDEPLOYING , State . UNDEPLOYED ) ; case FAILED : return changeState ( State . DEPLOYING , State . FAILED ) ; default : return false ; } }
state should only transition while the terminated lock is held .