/**
  * @param AbstractConnection $connection
  *
  * @return bool
  */
 private function readyToRevive(AbstractConnection $connection)
 {
     $timeout = min($this->pingTimeout * pow(2, $connection->getPingFailures()), $this->maxPingTimeout);
     if ($connection->getLastPing() + $timeout < time()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * @param array                    $hostDetails
  * @param array                    $connectionParams Array of connection parameters
  * @param \Psr\Log\LoggerInterface $log              logger object
  * @param \Psr\Log\LoggerInterface $trace            logger object (for curl traces)
  *
  * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
  * @return \Elasticsearch\Connections\GuzzleConnection
  */
 public function __construct($hostDetails, $connectionParams, LoggerInterface $log, LoggerInterface $trace)
 {
     if (isset($connectionParams['guzzleClient']) !== true) {
         $log->critical('guzzleClient must be set in connectionParams');
         throw new InvalidArgumentException('guzzleClient must be set in connectionParams');
     }
     if (isset($hostDetails['port']) !== true) {
         $hostDetails['port'] = 9200;
     }
     $this->guzzle = $connectionParams['guzzleClient'];
     if (isset($connectionParams['connectionParams'])) {
         $this->connectionOpts = $connectionParams['connectionParams'];
     }
     return parent::__construct($hostDetails, $connectionParams, $log, $trace);
 }
 /**
  * Constructor
  *
  * @param string                   $host             Host string
  * @param int                      $port             Host port
  * @param array                    $connectionParams Array of connection parameters
  * @param \Psr\Log\LoggerInterface $log              logger object
  * @param \Psr\Log\LoggerInterface $trace            logger object (for curl traces)
  *
  * @throws \Elasticsearch\Common\Exceptions\RuntimeException
  * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
  * @return CurlMultiConnection
  */
 public function __construct($host, $port, $connectionParams, LoggerInterface $log, LoggerInterface $trace)
 {
     if (extension_loaded('curl') !== true) {
         $log->critical('Curl library/extension is required for CurlMultiConnection.');
         throw new RuntimeException('Curl library/extension is required for CurlMultiConnection.');
     }
     if (isset($connectionParams['curlMultiHandle']) !== true) {
         $log->critical('curlMultiHandle must be set in connectionParams');
         throw new InvalidArgumentException('curlMultiHandle must be set in connectionParams');
     }
     if (isset($port) !== true) {
         $port = 9200;
     }
     $connectionParams = $this->transformAuth($connectionParams);
     $this->curlOpts = $this->generateCurlOpts($connectionParams);
     $this->multiHandle = $connectionParams['curlMultiHandle'];
     return parent::__construct($host, $port, $connectionParams, $log, $trace);
 }
 /**
  * @param AbstractConnection $connection
  * @return bool
  */
 private function sniffConnection(AbstractConnection $connection)
 {
     try {
         $response = $connection->sniff();
     } catch (OperationTimeoutException $exception) {
         return false;
     }
     $nodes = $this->parseClusterState($connection->getTransportSchema(), $response);
     if (count($nodes) === 0) {
         return false;
     }
     $this->connections = array();
     foreach ($nodes as $node) {
         $this->connections[] = $this->connectionFactory->create($node['host'], $node['port']);
     }
     $this->nextSniff = time() + $this->sniffingInterval;
     return true;
 }
 /**
  * @param AbstractConnection $connection
  * @return bool
  */
 private function sniffConnection(AbstractConnection $connection)
 {
     try {
         $response = $connection->sniff();
     } catch (OperationTimeoutException $exception) {
         return false;
     }
     // TODO wire in the serializer?
     $nodeInfo = json_decode($response['text'], true);
     $nodes = $this->parseClusterState($connection->getTransportSchema(), $nodeInfo);
     if (count($nodes) === 0) {
         return false;
     }
     $this->connections = array();
     foreach ($nodes as $node) {
         $nodeDetails = array('host' => $node['host'], 'port' => $node['port']);
         $this->connections[] = $this->connectionFactory->create($nodeDetails);
     }
     $this->nextSniff = time() + $this->sniffingInterval;
     return true;
 }
 /**
  * @param array                    $hostDetails
  * @param array                    $connectionParams Array of connection parameters
  * @param \Psr\Log\LoggerInterface $log              logger object
  * @param \Psr\Log\LoggerInterface $trace            logger object (for curl traces)
  *
  * @throws \Elasticsearch\Common\Exceptions\InvalidArgumentException
  * @return \Elasticsearch\Connections\GuzzleConnection
  */
 public function __construct($hostDetails, $connectionParams, LoggerInterface $log, LoggerInterface $trace)
 {
     if (isset($hostDetails['port']) !== true) {
         $hostDetails['port'] = 9200;
     }
     if (isset($hostDetails['scheme']) !== true) {
         $hostDetails['scheme'] = 'http';
     }
     $handler = null;
     if (isset($connectionParams)) {
         if (isset($connectionParams['ringphp_handler'])) {
             $handler = $connectionParams['ringphp_handler'];
             unset($connectionParams['ringphp_handler']);
         }
         $this->connectionOpts = $connectionParams;
     }
     if ($handler) {
         $this->guzzle = new \GuzzleHttp\Client(['handler' => $handler, 'defaults' => ['future' => true]]);
     } else {
         $this->guzzle = new \GuzzleHttp\Client(['defaults' => ['future' => true]]);
     }
     return parent::__construct($hostDetails, $connectionParams, $log, $trace);
 }