getType() public method

Return protocol type.
public getType ( ) : string
return string
示例#1
0
 /**
  * @param string $name
  * @param ProtocolInterface $message
  * @param int $flags
  * @return bool
  */
 protected function handleSendAsync($name, $message, $flags = Channel::MODE_DEFAULT)
 {
     if ($message->getType() === '') {
         $message->setType(Channel::TYPE_SND);
     }
     if ($message->getDestination() === '') {
         $message->setDestination($name);
     }
     return $this->getOutput()->handle($name, $message, $flags);
 }
示例#2
0
 /**
  * @param ChannelCompositeInterface $composite
  * @param ProtocolInterface $protocol
  */
 private function executeProtocol(ChannelCompositeInterface $composite, ProtocolInterface $protocol)
 {
     $params = json_decode($protocol->getMessage(), true);
     $command = array_shift($params);
     $params['origin'] = $protocol->getOrigin();
     $promise = $this->executeCommand($command, $params);
     if ($protocol->getType() === Channel::TYPE_REQ) {
         $promise->then(function ($response) use($composite, $protocol, $command) {
             return (new Response($composite, $protocol, $response))->call();
         }, function ($reason) use($composite, $protocol) {
             return (new Response($composite, $protocol, $reason))->call();
         }, function ($reason) use($composite, $protocol) {
             return (new Response($composite, $protocol, $reason))->call();
         });
     }
 }
示例#3
0
 /**
  * @param RuntimeContainerInterface $runtime
  * @param ChannelCompositeInterface $composite
  * @param ProtocolInterface $protocol
  */
 private function executeProtocol(RuntimeContainerInterface $runtime, ChannelCompositeInterface $composite, ProtocolInterface $protocol)
 {
     /**
      * If the json_decode fails, it means the received message is leftover of request response,
      * hence it should be dropped.
      */
     try {
         $params = json_decode($protocol->getMessage(), true);
         $command = array_shift($params);
         $params['origin'] = $protocol->getOrigin();
         if (!$runtime->isFailed() || isset($params['hash']) && $runtime->getHash() === $params['hash']) {
             $promise = $this->executeCommand($command, $params);
         } else {
             $promise = Promise::doReject(new RejectionException('Container is currently in failed state and cannot execute any tasks.'));
         }
         if ($protocol->getType() === Channel::TYPE_REQ) {
             $promise->then(function ($response) use($composite, $protocol, $command) {
                 return (new Response($composite, $protocol, $response))->call();
             }, function ($reason) use($composite, $protocol) {
                 return (new Response($composite, $protocol, $reason))->call();
             }, function ($reason) use($composite, $protocol) {
                 return (new Response($composite, $protocol, $reason))->call();
             });
         }
     } catch (Error $ex) {
         return;
     } catch (Exception $ex) {
         return;
     }
 }
示例#4
0
 /**
  * @param ProtocolInterface
  * @return bool
  */
 protected function handleReceiveRequest(ProtocolInterface $protocol)
 {
     if ($protocol->getType() === Channel::TYPE_REQ && $protocol->getDestination() === $this->name) {
         $pid = $protocol->getPid();
         $timestamp = $protocol->getTimestamp();
         $now = $this->getTime();
         if ($timestamp <= $now || $this->existsResponse($pid)) {
             return true;
         }
         $timestamp -= 5000.0;
         $this->addResponse($pid, $this->createResponse($pid, $protocol->getOrigin(), $timestamp, $timestamp - $now));
     }
     return false;
 }