public function setState(State $state, $message = null)
{
if ($this->getState($state->getName()) === null) {
throw new Exception(sprintf("%s state '%s' not known to this machine", $this->toString(), $state->getName()), Exception::SM_UNKNOWN_STATE);
}
//get the state known to this machine so we are sure we have the correct reference
//even if the client provides another instance of State with the same name
$state = $this->getState($state->getName());
$this->getContext()->setState($state->getName(), $message);
$this->state = $state;
}