Esempio n. 1
0
 public function testRoundtrip()
 {
     $pm = new ProtocolMessage();
     $pm->setActions(array('service1', 'service2'));
     $pm2 = ProtocolMessage::fromMessage($pm->toMessage());
     $this->assertEquals($pm, $pm2);
 }
 public function testTheMessageIsSerializableToItself()
 {
     $pm = new ProtocolMessage();
     $pm->setActions(array('service1', 'service2'));
     $pm2 = ProtocolMessage::fromMessage($pm->toMessage());
     $this->assertEquals($pm, $pm2);
 }
 /**
  * Handles a Message from the Service Handler.
  *
  * @param MessageInterface $msg
  */
 public function onServiceMessage(MessageInterface $msg)
 {
     $this->serviceStreamReady = true;
     $this->getLogger()->debug('Received Service Message of Type: ' . get_class($msg));
     if ($msg instanceof ActionListResponse) {
         $actions = $msg->getActions();
         $this->getLogger()->debug('The action list is: ' . implode(', ', $actions) . '.');
         $this->worker->setActions($actions);
         $reply = new Register();
         $reply->setActions($actions);
         $this->sendToWorkerHandler($reply);
         unset($reply);
         return;
     }
     if ($msg instanceof ExecuteJobResponse) {
         $requestId = $msg->getRequestId();
         $result = $msg->getResult();
         $this->getLogger()->debug('Result for: ' . $requestId . ': ' . $result);
         $this->worker->setResult($requestId, $result);
         return;
     }
     $this->getLogger()->error('Unknown service response: ' . get_class($msg) . '.');
 }
Esempio n. 4
0
 /**
  * Handles an init message from the worker.
  *
  * @param Worker   $worker
  * @param Register $msg
  *
  * @return void
  */
 protected function handleWorkerInit(Worker $worker, Register $msg)
 {
     $actionCount = intval(count($msg->getActions()));
     if ($actionCount <= 0) {
         $this->getLogger()->error('Invalid init, invalid action count.');
         return;
     }
     foreach ($msg->getActions() as $actionName) {
         $worker->addAction($actionName);
         $action = $this->getActionName($actionName);
         $action->addWorker($worker);
     }
     $this->getLogger()->info('New worker (' . $worker->getHexId() . ') with ' . $actionCount . ' actions.');
     $this->getLogger()->debug('Actions for worker ' . $worker->getHexId() . ': ' . implode(', ', $worker->getActionList()));
     $worker->setValid(true);
     $this->reply($worker, new HeartbeatResponseWorkerhandler());
     $this->getLogger()->debug('Worker ' . bin2hex($worker->getId()) . ' initialised.');
 }