/**
  * Feed frame from the server
  *
  * @return An array of commands to be executed by the caller.
  */
 public function receiveFrame(Frame $frame)
 {
     if ('ERROR' === $frame->command) {
         throw new ServerErrorException($frame);
     }
     if ($this->state->isConnecting()) {
         if ('CONNECTED' !== $frame->command) {
             throw new InvalidFrameException(sprintf("Received frame with command '%s', expected 'CONNECTED'."));
         }
         $this->state->doneConnecting($frame->getHeader('session'), $frame->getHeader('server'));
         return new ConnectionEstablishedCommand();
     }
     if ($this->state->isDisconnecting()) {
         if ('RECEIPT' === $frame->command && $this->state->isDisconnectionReceipt($frame->getHeader('receipt-id'))) {
             $this->state->doneDisconnecting();
             return new CloseCommand();
         }
     }
     return new NullCommand();
 }
예제 #2
0
 public function handleLog(PredisClient $redis, Logger $logger, Frame $frame, AckResolver $resolver)
 {
     $logger->addInfo(sprintf('Processing job %s', $frame->getHeader('delivery_tag')));
     $error = false;
     try {
         $job = Factory::fromJson($frame->body);
         if (!$job instanceof JobInterface) {
             $error = true;
         }
     } catch (RuntimeException $e) {
         $error = true;
     }
     if (!$error) {
         $promise = $this->saveJob($redis, $job);
     } else {
         $promise = $this->saveGarbage($redis, $frame->body);
     }
     $promise->then(function () use($resolver) {
         $resolver->ack();
     });
     return $promise;
 }
예제 #3
0
 public function notifySubscribers(Frame $frame)
 {
     $subscriptionId = $frame->getHeader('subscription');
     if (!isset($this->subscriptions[$subscriptionId])) {
         return;
     }
     $callback = $this->subscriptions[$subscriptionId];
     if ('auto' !== $this->acknowledgements[$subscriptionId]) {
         $resolver = new AckResolver($this, $subscriptionId, $frame->getHeader('message-id'));
         $parameters = array($frame, $resolver);
     } else {
         $parameters = array($frame);
     }
     call_user_func_array($callback, $parameters);
 }
예제 #4
0
 public function __construct(Frame $frame)
 {
     parent::__construct(sprintf('%s (%s)', $frame->getHeader('message'), trim($frame->body)));
     $this->frame = $frame;
 }