public function connect()
{
// If the manager was already connected, connect to a node from the last
// HELLO response. This information is newer than the credentials
// supplied by the user at the beginning.
if ($this->wasAlreadyConnected()) {
try {
$this->switchNodeIfNeeded();
} catch (ConnectionException $e) {
// Ignore the error, we'll try reconnecting with credentials below
}
}
// Use the user-supplied credentials in case this is the initial
// connection.
// If the reconnection attempt above didn't work, fall back
// to the user-supplied credentials, too.
if (!$this->isConnected()) {
$currentNode = $this->findAvailableConnection();
$this->switchToNode($currentNode);
}
return $this->getCurrentNode();
}