示例#1
0
文件: Request.php 项目: khelle/surume
 /**
  * @param ChannelBaseInterface $channel
  * @param string $name
  * @param string|ChannelProtocolInterface $message
  * @param mixed[] $params
  */
 public function __construct($channel, $name, $message, $params = [])
 {
     $this->channel = $channel;
     $this->name = $name;
     $this->message = $message instanceof ChannelProtocolInterface ? $message : $this->channel->createProtocol($message);
     $this->params = ['timeout' => isset($params['timeout']) ? $params['timeout'] : 3.0, 'retriesLimit' => isset($params['retriesLimit']) ? $params['retriesLimit'] : 6, 'retriesInterval' => isset($params['retriesInterval']) ? $params['retriesInterval'] : 2.0];
     $this->counter = 1;
     $this->message->setTimestamp(TimeSupport::now() + ($this->params['retriesInterval'] + $this->params['timeout']) * 1000.0 * $this->params['retriesLimit'], true);
 }
示例#2
0
 /**
  *
  */
 protected function expireResponses()
 {
     $now = TimeSupport::now();
     $expiredReps = [];
     foreach ($this->handledReps as $pid => $response) {
         if ($now >= $response->timeout) {
             $expiredReps[] = $pid;
         }
     }
     foreach ($expiredReps as $pid) {
         unset($this->handledReps[$pid]);
     }
 }
示例#3
0
 /**
  *
  */
 protected function expireRequests()
 {
     $now = TimeSupport::now();
     $expiredReqs = [];
     foreach ($this->reqs as $pid => $request) {
         if ($now >= $request->timeout()) {
             $expiredReqs[] = $request;
         }
     }
     foreach ($expiredReqs as $request) {
         unset($this->reqs[$request->pid()]);
     }
     foreach ($expiredReqs as $request) {
         $request->cancel(new LazyException(new TimeoutException("Request has expired.")));
     }
 }
示例#4
0
 /**
  * @return float
  */
 protected function now()
 {
     return TimeSupport::now();
 }