Example #1
0
 /**
  * Perform a request to the Cluster
  *
  * @param string $method     HTTP method to use
  * @param string $uri        HTTP URI to send request to
  * @param null   $params     Optional query parameters
  * @param null   $body       Optional query body
  *
  * @throws Common\Exceptions\NoNodesAvailableException|\Exception
  * @internal param null $maxRetries Optional number of retries
  *
  * @return array
  */
 public function performRequest($method, $uri, $params = null, $body = null)
 {
     try {
         $connection = $this->getConnection();
     } catch (Exceptions\NoNodesAvailableException $exception) {
         $this->log->critical('No alive nodes found in cluster');
         throw $exception;
     }
     $response = array();
     $caughtException = null;
     $this->lastConnection = $connection;
     try {
         if (isset($body) === true) {
             $body = $this->serializer->serialize($body);
         }
         $response = $connection->performRequest($method, $uri, $params, $body);
         $connection->markAlive();
         $this->retryAttempts = 0;
         $data = $this->serializer->deserialize($response['text'], $response['info']);
         return array('status' => $response['status'], 'data' => $data, 'info' => $response['info']);
     } catch (Exceptions\Curl\OperationTimeoutException $exception) {
         $this->connectionPool->scheduleCheck();
         $caughtException = $exception;
     } catch (Exceptions\ClientErrorResponseException $exception) {
         throw $exception;
         //We need 4xx errors to go straight to the user, no retries
     } catch (Exceptions\ServerErrorResponseException $exception) {
         throw $exception;
         //We need 5xx errors to go straight to the user, no retries
     } catch (TransportException $exception) {
         $connection->markDead();
         $this->connectionPool->scheduleCheck();
         $caughtException = $exception;
     }
     $shouldRetry = $this->shouldRetry($method, $uri, $params, $body);
     if ($shouldRetry === true) {
         return $this->performRequest($method, $uri, $params, $body);
     }
     if ($caughtException !== null) {
         throw $caughtException;
     }
     return $response;
 }
Example #2
0
 /**
  * Perform a request to the Cluster
  *
  * @param string $method     HTTP method to use
  * @param string $uri        HTTP URI to send request to
  * @param null $params     Optional query parameters
  * @param null $body       Optional query body
  * @param array $options
  *
  * @throws Common\Exceptions\NoNodesAvailableException|\Exception
  * @return array
  */
 public function performRequest($method, $uri, $params = null, $body = null, $options = [])
 {
     try {
         $connection = $this->getConnection();
     } catch (Exceptions\NoNodesAvailableException $exception) {
         $this->log->critical('No alive nodes found in cluster');
         throw $exception;
     }
     $response = array();
     $caughtException = null;
     $this->lastConnection = $connection;
     $future = $connection->performRequest($method, $uri, $params, $body, $options, $this);
     $future->promise()->then(function ($response) {
         $this->retryAttempts = 0;
         // Note, this could be a 4xx or 5xx error
     }, function ($response) {
         //some kind of real faiure here, like a timeout
         $this->connectionPool->scheduleCheck();
         // log stuff
     });
     return $future;
 }
 /**
  * {@inheritdoc}
  */
 public function __construct($connections, SelectorInterface $selector, ConnectionFactory $factory, $connectionPoolParams)
 {
     parent::__construct($connections, $selector, $factory, $connectionPoolParams);
 }
 public function __construct($connections, SelectorInterface $selector, ConnectionFactory $factory, $connectionPoolParams)
 {
     parent::__construct($connections, $selector, $factory, $connectionPoolParams);
     $this->setConnectionPoolParams($connectionPoolParams);
     $this->nextSniff = time() + $this->sniffingInterval;
 }