コード例 #1
0
 public function __construct($reply_code, $reply_text, $method_sig)
 {
     parent::__construct($reply_text, $reply_code);
     $this->amqp_reply_code = $reply_code;
     // redundant, but kept for BC
     $this->amqp_reply_text = $reply_text;
     // redundant, but kept for BC
     $this->amqp_method_sig = $method_sig;
     $ms = MiscHelper::methodSig($method_sig);
     $mn = isset(AbstractChannel::$GLOBAL_METHOD_NAMES[$ms]) ? AbstractChannel::$GLOBAL_METHOD_NAMES[$ms] : ($mn = "");
     $this->args = array($reply_code, $reply_text, $method_sig, $mn);
 }
コード例 #2
0
 /**
  * @param string $reply_code
  * @param int $reply_text
  * @param array $method_sig
  */
 public function __construct($reply_code, $reply_text, $method_sig)
 {
     parent::__construct($reply_text, $reply_code);
     $this->amqp_reply_code = $reply_code;
     // redundant, but kept for BC
     $this->amqp_reply_text = $reply_text;
     // redundant, but kept for BC
     $this->amqp_method_sig = $method_sig;
     $ms = MiscHelper::methodSig($method_sig);
     $protocolClass = AbstractChannel::$PROTOCOL_CONSTANTS_CLASS;
     $mn = isset($protocolClass::$GLOBAL_METHOD_NAMES[$ms]) ? $protocolClass::$GLOBAL_METHOD_NAMES[$ms] : ($mn = '');
     $this->args = array($reply_code, $reply_text, $method_sig, $mn);
 }
コード例 #3
0
 /**
  * returns a new AMQPWriter or mutates the provided $pkt
  */
 protected function prepare_channel_method_frame($channel, $method_sig, $args = "", $pkt = null)
 {
     if ($args instanceof AMQPWriter) {
         $args = $args->getvalue();
     }
     if (empty($pkt)) {
         $pkt = new AMQPWriter();
     }
     $pkt->write_octet(1);
     $pkt->write_short($channel);
     $pkt->write_long(mb_strlen($args, 'ASCII') + 4);
     // 4 = length of class_id and method_id
     // in payload
     $pkt->write_short($method_sig[0]);
     // class_id
     $pkt->write_short($method_sig[1]);
     // method_id
     $pkt->write($args);
     $pkt->write_octet(0xce);
     if ($this->debug) {
         $PROTOCOL_CONSTANTS_CLASS = self::$PROTOCOL_CONSTANTS_CLASS;
         MiscHelper::debug_msg("< " . MiscHelper::methodSig($method_sig) . ": " . $PROTOCOL_CONSTANTS_CLASS::$GLOBAL_METHOD_NAMES[MiscHelper::methodSig($method_sig)]);
     }
     return $pkt;
 }
コード例 #4
0
 /**
  * Wait for some expected AMQP methods and dispatch to them.
  * Unexpected methods are queued up for later calls to this PHP
  * method.
  *
  * @param array $allowed_methods
  * @param bool $non_blocking
  * @param int $timeout
  * @return mixed
  */
 public function wait($allowed_methods = null, $non_blocking = false, $timeout = 0)
 {
     $PROTOCOL_CONSTANTS_CLASS = self::$PROTOCOL_CONSTANTS_CLASS;
     if ($allowed_methods && $this->debug) {
         MiscHelper::debug_msg("waiting for " . implode(", ", $allowed_methods));
     } elseif ($this->debug) {
         MiscHelper::debug_msg("waiting for any method");
     }
     //Process deferred methods
     foreach ($this->method_queue as $qk => $queued_method) {
         if ($this->debug) {
             MiscHelper::debug_msg("checking queue method " . $qk);
         }
         $method_sig = $queued_method[0];
         if ($allowed_methods == null || in_array($method_sig, $allowed_methods)) {
             unset($this->method_queue[$qk]);
             if ($this->debug) {
                 MiscHelper::debug_msg("Executing queued method: {$method_sig}: " . $PROTOCOL_CONSTANTS_CLASS::$GLOBAL_METHOD_NAMES[MiscHelper::methodSig($method_sig)]);
             }
             return $this->dispatch($queued_method[0], $queued_method[1], $queued_method[2]);
         }
     }
     // No deferred methods?  wait for new ones
     while (true) {
         $frm = $this->next_frame($timeout);
         $frame_type = $frm[0];
         $payload = $frm[1];
         if ($frame_type != 1) {
             throw new AMQPRuntimeException("Expecting AMQP method, received frame type: {$frame_type} (" . $PROTOCOL_CONSTANTS_CLASS::$FRAME_TYPES[$frame_type] . ")");
         }
         if (mb_strlen($payload, 'ASCII') < 4) {
             throw new AMQPOutOfBoundsException("Method frame too short");
         }
         $method_sig_array = unpack("n2", mb_substr($payload, 0, 4, 'ASCII'));
         $method_sig = "" . $method_sig_array[1] . "," . $method_sig_array[2];
         $args = mb_substr($payload, 4, mb_strlen($payload, 'ASCII') - 4, 'ASCII');
         if ($this->debug) {
             MiscHelper::debug_msg("> {$method_sig}: " . $PROTOCOL_CONSTANTS_CLASS::$GLOBAL_METHOD_NAMES[MiscHelper::methodSig($method_sig)]);
         }
         if (in_array($method_sig, $PROTOCOL_CONSTANTS_CLASS::$CONTENT_METHODS)) {
             $content = $this->wait_content();
         } else {
             $content = null;
         }
         if ($allowed_methods == null || in_array($method_sig, $allowed_methods) || in_array($method_sig, $PROTOCOL_CONSTANTS_CLASS::$CLOSE_METHODS)) {
             return $this->dispatch($method_sig, $args, $content);
         }
         // Wasn't what we were looking for? save it for later
         if ($this->debug) {
             MiscHelper::debug_msg("Queueing for later: {$method_sig}: " . $PROTOCOL_CONSTANTS_CLASS::$GLOBAL_METHOD_NAMES[MiscHelper::methodSig($method_sig)]);
         }
         $this->method_queue[] = array($method_sig, $args, $content);
         if ($non_blocking) {
             break;
         }
     }
 }
コード例 #5
0
 protected function send_channel_method_frame($channel, $method_sig, $args = "")
 {
     if ($args instanceof AMQPWriter) {
         $args = $args->getvalue();
     }
     $pkt = new AMQPWriter();
     $pkt->write_octet(1);
     $pkt->write_short($channel);
     $pkt->write_long(strlen($args) + 4);
     // 4 = length of class_id and method_id
     // in payload
     $pkt->write_short($method_sig[0]);
     // class_id
     $pkt->write_short($method_sig[1]);
     // method_id
     $pkt->write($args);
     $pkt->write_octet(0xce);
     $pkt = $pkt->getvalue();
     $this->write($pkt);
     if ($this->debug) {
         MiscHelper::debug_msg("< " . MiscHelper::methodSig($method_sig) . ": " . AbstractChannel::$GLOBAL_METHOD_NAMES[MiscHelper::methodSig($method_sig)]);
     }
 }