예제 #1
0
 /**
  * Decide if we should switch to a better node
  *
  * @throws ConnectionException
  */
 private function switchNodeIfNeeded()
 {
     $sortedNodes = $this->priorityStrategy->sort($this->nodes, $this->nodeId);
     // Try to connect by priority, continue on error, return on success
     foreach ($sortedNodes as $nodeCandidate) {
         // If the first recommended node is our current node and it has
         // a working connection, return early.
         // If its connection is not working, let's try and reconnect further
         // below, or find the first best connected node.
         if ($nodeCandidate->getId() === $this->nodeId && $nodeCandidate->isConnected()) {
             return;
         }
         try {
             if ($nodeCandidate->isConnected()) {
                 // Say a new HELLO to the node, the cluster might have changed
                 $nodeCandidate->sayHello();
             } else {
                 $nodeCandidate->connect();
             }
         } catch (ConnectionException $e) {
             continue;
         }
         $this->switchToNode($nodeCandidate);
         return;
     }
     throw new ConnectionException('Could not switch to any node');
 }
예제 #2
0
 /**
  * Decide if we should switch to a better node
  *
  * @throws ConnectionException
  */
 private function switchNodeIfNeeded()
 {
     $sortedNodes = $this->priorityStrategy->sort($this->nodes, $this->nodeId);
     // Try to connect by priority, continue on error, return on success
     foreach ($sortedNodes as $nodeCandidate) {
         if ($nodeCandidate->getId() === $this->nodeId) {
             return;
         }
         try {
             if ($nodeCandidate->getConnection()->isConnected()) {
                 // Say a new HELLO to the node, the cluster might have changed
                 $nodeCandidate->sayHello();
             } else {
                 $nodeCandidate->connect();
             }
         } catch (ConnectionException $e) {
             continue;
         }
         $this->switchToNode($nodeCandidate);
         return;
     }
     throw new ConnectionException('Could not switch to any node');
 }