示例#1
0
 /**
  *
  */
 private function registerHandlers()
 {
     $this->hbSocket->on('error', new HbErrorHandler($this->logger->withName('HbErrorHandler')));
     $this->hbSocket->on('messages', new HbMessagesHandler($this->logger->withName('HbMessagesHandler')));
     $this->iopubSocket->on('messages', new IOPubMessagesHandler($this->logger->withName('IOPubMessagesHandler')));
     $this->shellSocket->on('messages', new ShellMessagesHandler($this->broker, $this->iopubSocket, $this->shellSocket, $this->logger->withName('ShellMessagesHandler')));
 }
示例#2
0
 /**
  * @param LoopInterface $loop
  */
 public function initZmq(LoopInterface $loop)
 {
     /** @var \ZMQContext $context */
     $context = new \React\ZMQ\Context($loop);
     $this->listener = $context->getSocket(\ZMQ::SOCKET_PUSH);
     $this->listener->connect('tcp://127.0.0.1:5559');
     $this->receiver = $context->getSocket(\ZMQ::SOCKET_PULL);
     $this->receiver->connect('tcp://127.0.0.1:5557');
     $this->receiver->on('message', function ($msg) {
         $message = json_decode($msg, true);
         if (is_array($message) && isset($message['outputs']) && is_array($message['outputs'])) {
             $cumulative = array();
             foreach ($message['outputs'] as $output) {
                 $script = pack("H*", $output['script']);
                 if (!isset($cumulative[$script])) {
                     $cumulative[$script] = $output['value'];
                 } else {
                     $cumulative[$script] += $output['value'];
                 }
             }
             $message['requirements'] = $cumulative;
             $this->contracts[$message['slug']] = $message;
             echo "New contract: " . $msg . "\n";
         }
     });
 }
示例#3
0
 /**
  * @return null
  */
 protected function declarePushMessaging()
 {
     $this->pullActionInfo->on(EventsConstants::MESSAGE, function ($pushDto) {
         $this->resolvePushMessage(unserialize($pushDto));
         $this->logger->debug("Receive push message {$pushDto}.");
     });
     $this->pullActionInfo->on(EventsConstants::ERROR, function ($error) {
         $this->logger->error(LoggingExceptions::getExceptionString($error));
     });
     return null;
 }
示例#4
0
 /**
  * Registers inbound data events.
  */
 private function registerInboundEvents()
 {
     // Handle requests from queue via SUBSCRIBER
     $this->zmqInboundQueue->on('message', function ($msg) {
         $this->runtimeStatistics->incrementAddedObjectCount();
         try {
             $message = RequestMessage::fromStringToArray($msg);
             $this->getQueue()->push($message['key'], $message['data'], round(microtime(true) * 1000000) + $message['timeout'], $message['type']);
             if ($this->isInLogLevel(Logger::DEBUG)) {
                 $this->logger->debug("[OnMessage] Data for key '{$message['key']}' [type '{$message['type']}', exp {$message['timeout']} ms]: " . str_replace("\n", "", var_export($message['data'], true)));
             }
         } catch (\Exception $e) {
             $this->logger->error($e);
         }
     });
 }
示例#5
0
 protected function declareReplyToPm()
 {
     $this->replyToPmSocket = $this->context->getSocket(\ZMQ::SOCKET_REP);
     $this->replyToPmSocket->bind($this->loadManagerDto->getPmLmSocketsParams()->getPmLmRequestAddress());
     $this->replyToPmSocket->on(EventsConstants::ERROR, function (\Exception $e) {
         $this->logger->error(LoggingExceptions::getExceptionString($e));
     });
     $this->replyToPmSocket->on(EventsConstants::MESSAGE, function ($receivedDtoContainer) {
         /**
          * @var DtoContainer $dtoContainer
          */
         $dtoContainer = unserialize($receivedDtoContainer);
         $this->processReceivedControlDto($dtoContainer->getDto());
         $this->receivePmInfo = true;
         $this->replyToPmSocket->send(serialize($this->dtoContainer));
     });
     return null;
 }
示例#6
0
 protected function declareLmRequester()
 {
     $this->lmRequesterSocket = $this->context->getSocket(\ZMQ::SOCKET_REQ);
     $this->lmRequesterSocket->connect($this->processManagerDto->getPmLmSocketsParams()->getPmLmRequestAddress());
     $this->lmRequesterSocket->on(EventsConstants::ERROR, function (\Exception $e) {
         $this->logger->error(LoggingExceptions::getExceptionString($e));
     });
     $this->lmRequesterSocket->on(EventsConstants::MESSAGE, function ($receivedDtoContainer) {
         $this->logger->alert("Received dto from LM." . $this->loggerPostfix);
         usleep($this->processManagerDto->getInterMessageInterval());
         /**
          * @var DtoContainer $dtoContainer
          */
         $dtoContainer = unserialize($receivedDtoContainer);
         $this->processReceivedControlDto($dtoContainer->getDto());
         if ($this->allowSending) {
             $this->lmRequesterSocket->send(serialize($this->dtoContainer));
             $this->logger->alert("Send a request " . $this->requestNumber . $this->loggerPostfix);
             $this->requestNumber++;
         }
     });
 }