Refactor StateManagerImpl and TaskStateMachine for less code and better
readability.

The "big picture" for this change is that the closures inside
TaskStateMachine no longer drop items onto a work queue that feeds back into
StateManagerImpl.  Instead, it returns these actions in a TransitionResult.
I intend to improve this further in the future by exposing only a helper
function in TaskStateMachine, to guarantee the one-time-use semantic.

Reviewed at https://reviews.apache.org/r/16873/