Exemple #1
0
 /**
  * @param ZMQSocket $socket
  *
  * @return SocketWrapper
  */
 protected function wrapSocket(ZMQSocket $socket)
 {
     $wrapped = new SocketWrapper($socket, $this->loop);
     if ($this->isReadableSocketType($socket->getSocketType())) {
         $wrapped->attachReadListener();
     }
     return $wrapped;
 }
Exemple #2
0
 /**
  * @test
  */
 public function closeShouldStopListening()
 {
     $loop = $this->getMock('React\\EventLoop\\LoopInterface');
     $loop->expects($this->once())->method('removeStream')->with(14);
     $socket = $this->getMockBuilder('ZMQSocket')->disableOriginalConstructor()->getMock();
     $socket->expects($this->any())->method('getSockOpt')->with(ZMQ::SOCKOPT_FD)->will($this->returnValue(14));
     $wrapped = new SocketWrapper($socket, $loop);
     $wrapped->close();
 }
Exemple #3
0
 /**
  * @param SocketWrapper $stream
  * @param string $msgType
  * @param array $content
  * @param array $parentHeader
  * @param array $metadata
  */
 public function send(SocketWrapper $stream, $msgType, array $content = [], array $parentHeader = [], array $metadata = [])
 {
     $header = $this->createHeader($msgType);
     $msgDef = [json_encode(empty($header) ? new \stdClass() : $header), json_encode(empty($parentHeader) ? new \stdClass() : $parentHeader), json_encode(empty($metadata) ? new \stdClass() : $metadata), json_encode(empty($content) ? new \stdClass() : $content)];
     $finalMsg = array_merge(['<IDS|MSG>', $this->sign($msgDef)], $msgDef);
     if (null !== $this->logger) {
         $this->logger->debug('Sent message', ['processId' => posix_getpid(), 'message' => $finalMsg]);
     }
     $stream->send($finalMsg);
 }
Exemple #4
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')));
 }
Exemple #5
0
 /**
  * @param Context $context
  * @param BitcoinNode $node
  * @param ScriptThreadControl $threadControl
  */
 public function __construct(Context $context, BitcoinNode $node, ScriptThreadControl $threadControl)
 {
     $cmdControl = $context->getSocket(\ZMQ::SOCKET_REP);
     $cmdControl->bind('tcp://127.0.0.1:5560');
     $cmdControl->on('message', function ($e) use($threadControl, $node) {
         $result = ['error' => 'Unrecognized command'];
         if ($e === 'shutdown') {
             $threadControl->shutdown();
             $result = $this->onShutdown($threadControl);
         } elseif ($e === 'info') {
             $result = $this->onInfo($node);
         }
         $this->socket->send(json_encode($result, JSON_PRETTY_PRINT));
         if ($e === 'shutdown') {
             $node->stop();
         }
     });
     $this->socket = $cmdControl;
 }
 /**
  * @param array $result
  * @return bool
  */
 private function respond(array $result)
 {
     $this->socket->send(json_encode($result, JSON_PRETTY_PRINT));
     return true;
 }
 /**
  * @return $this
  */
 public function shutdown()
 {
     $this->socket->sendmulti(array('control', 'shutdown'));
     return $this;
 }
Exemple #8
0
 /**
  * @param string $subject
  * @param array $params
  */
 public function log($subject, array $params = [])
 {
     $this->socket->send(json_encode(['event' => $subject, 'params' => $params]));
 }
Exemple #9
0
 /**
  * @return null
  */
 protected function initSockets()
 {
     $this->replyToReplyStack = $this->context->getSocket(\ZMQ::SOCKET_REP);
     $this->replyToReplyStack->bind($this->pulsarSocketsParams->getReplyToReplyStackSocketAddress());
     $this->publisher = $this->context->getSocket(\ZMQ::SOCKET_PUB);
     $this->publisher->bind($this->pulsarSocketsParams->getPublishSocketAddress());
     $this->pullActionInfo = $this->context->getSocket(\ZMQ::SOCKET_PULL);
     $this->pullActionInfo->bind($this->pulsarSocketsParams->getPullSocketAddress());
     return null;
 }