private function _ensureGoalStateRetrieved()
    {
        if (is_null($this->_currentGoalState) || !$this->_keepOpen) {
            $inputStream = $this->_inputChannel->getInputStream($this->_endpoint);
            $this->_goalStateDeserializer->initialize($inputStream);
        }

        $goalState = $this->_goalStateDeserializer->deserialize();
        if (is_null($goalState)) {
            return;
        }

        $this->_currentGoalState = $goalState;

        if (!is_null($goalState->getEnvironmentPath())) {
            $this->_currentEnvironmentData = null;
        }

        $this->_currentStateClient->setEndpoint(
            $this->_currentGoalState->getCurrentStateEndpoint()
        );

        if (!$this->_keepOpen) {
            $this->_inputChannel->closeInputStream();
        }
    }