示例#1
0
 /**
  * Iterate through available read services and select the first with a ping
  * that satisfies configured timeout restrictions (or the default)
  *
  * @return Apache_Solr_Service
  *
  * @throws Apache_Solr_NoServiceAvailableException If there are no read services that meet requirements
  */
 protected function _selectReadService($forceSelect = false)
 {
     if (!$this->_currentReadService || !isset($this->_readableServices[$this->_currentReadService]) || $forceSelect) {
         if ($this->_currentReadService && isset($this->_readableServices[$this->_currentReadService]) && $forceSelect) {
             // we probably had a communication error, ping the current read service, remove it if it times out
             if ($this->_readableServices[$this->_currentReadService]->ping($this->_readPingTimeout) === false) {
                 $this->removeReadService($this->_currentReadService);
             }
         }
         if (count($this->_readableServices)) {
             // select one of the read services at random
             $ids = array_keys($this->_readableServices);
             $id = $ids[rand(0, count($ids) - 1)];
             $service = $this->_readableServices[$id];
             if (is_array($service)) {
                 //convert the array definition to a client object
                 $service = new Apache_Solr_Service($service['host'], $service['port'], $service['path']);
                 $this->_readableServices[$id] = $service;
             }
             $service->setCreateDocuments($this->_createDocuments);
             $this->_currentReadService = $id;
         } else {
             throw new Apache_Solr_NoServiceAvailableException('No read services were available');
         }
     }
     return $this->_readableServices[$this->_currentReadService];
 }