/**
  * Ensures a connected connection adapter for a host.
  * Returns the connection adapter instance.
  *
  * @param Host $host
  *
  * @return ConnectionAdapterInterface
  *
  * @throws ConnectionException
  */
 public function ensureConnection(Host $host)
 {
     if ($host->hasConnection()) {
         $connection = $host->getConnection();
         if ($connection->isConnected() === false && $connection->connect() === false) {
             throw new ConnectionException(sprintf('Could not connect to "%s" through "%s".', $host->getHostname(), $host->getConnectionType()));
         }
         return $connection;
     }
     throw new ConnectionException(sprintf('No connection adapter of type "%s" found on host.', $host->getConnectionType()));
 }
 /**
  * {@inheritdoc}
  */
 public function getConnectionAdapter(Host $host)
 {
     if (isset($this->connectionAdapters[$host->getConnectionType()])) {
         $connectionIdentifier = spl_object_hash($host);
         if (isset($this->connections[$connectionIdentifier]) === false) {
             $connectionAdapterArguments = $host->getConnectionOptions();
             $connectionAdapterArguments['hostname'] = $host->getHostname();
             $this->connections[$connectionIdentifier] = ObjectFactory::getInstance()->newInstance($this->connectionAdapters[$host->getConnectionType()], $connectionAdapterArguments);
         }
         return $this->connections[$connectionIdentifier];
     }
 }