Esempio n. 1
0
 /**
  * Create a new Call wrapper object.
  * @param Channel $channel The channel to communicate on
  * @param string $method The method to call on the remote server
  * @param callback $deserialize A callback function to deserialize
  * the response
  * @param (optional) long $timeout Timeout in microseconds
  */
 public function __construct(Channel $channel, $method, $deserialize, $timeout = false)
 {
     if ($timeout) {
         $now = Timeval::now();
         $delta = new Timeval($timeout);
         $deadline = $now->add($delta);
     } else {
         $deadline = Timeval::infFuture();
     }
     $this->call = new Call($channel, $method, $deadline);
     $this->deserialize = $deserialize;
     $this->metadata = null;
 }
Esempio n. 2
0
 /**
  * Create a new Call wrapper object.
  *
  * @param Channel  $channel     The channel to communicate on
  * @param string   $method      The method to call on the
  *                              remote server
  * @param callback $deserialize A callback function to deserialize
  *                              the response
  * @param array    $options     Call options (optional)
  */
 public function __construct(Channel $channel, $method, $deserialize, $options = [])
 {
     if (isset($options['timeout']) && is_numeric($timeout = $options['timeout'])) {
         $now = Timeval::now();
         $delta = new Timeval($timeout);
         $deadline = $now->add($delta);
     } else {
         $deadline = Timeval::infFuture();
     }
     $this->call = new Call($channel, $method, $deadline);
     $this->deserialize = $deserialize;
     $this->metadata = null;
     if (isset($options['call_credentials_callback']) && is_callable($call_credentials_callback = $options['call_credentials_callback'])) {
         $call_credentials = CallCredentials::createFromPlugin($call_credentials_callback);
         $this->call->setCredentials($call_credentials);
     }
 }
Esempio n. 3
0
 /**
  * @param $timeout in microseconds
  *
  * @return bool true if channel is ready
  * @throw Exception if channel is in FATAL_ERROR state
  */
 public function waitForReady($timeout)
 {
     $new_state = $this->getConnectivityState(true);
     if ($this->_checkConnectivityState($new_state)) {
         return true;
     }
     $now = Timeval::now();
     $delta = new Timeval($timeout);
     $deadline = $now->add($delta);
     while ($this->channel->watchConnectivityState($new_state, $deadline)) {
         // state has changed before deadline
         $new_state = $this->getConnectivityState();
         if ($this->_checkConnectivityState($new_state)) {
             return true;
         }
     }
     // deadline has passed
     $new_state = $this->getConnectivityState();
     return $this->_checkConnectivityState($new_state);
 }
Esempio n. 4
0
 /**
  * Wait for the server to send the status, and return it.
  * @return object The status object, with integer $code, string $details,
  *     and array $metadata members
  */
 public function getStatus()
 {
     $status_event = $this->completion_queue->pluck(FINISHED, Timeval::inf_future());
     return $status_event->data;
 }
Esempio n. 5
0
 /**
  * Create a new Call wrapper object.
  * @param Channel $channel The channel to communicate on
  * @param string $method The method to call on the remote server
  */
 public function __construct(Channel $channel, $method, $deserialize)
 {
     $this->call = new Call($channel, $method, Timeval::inf_future());
     $this->deserialize = $deserialize;
     $this->metadata = null;
 }