public function testPrependRoutingInformationWithExistingRouting() { $msg = new Message(array('worker1', '', 'hello', 'world')); $msg->stripRoutingInformation(); $msg->prependRoutingInformation(array('dealer1')); $this->assertSame(array('dealer1', '', 'worker1'), $msg->getRoutingInformation()); }
public function testHasProtocolVersion() { $msg1 = new Message(array('1')); $this->assertTrue(MessageFactory::hasProtocolVersion($msg1->peek())); $msg2 = new Message(array(-1)); $this->assertFalse(MessageFactory::hasProtocolVersion($msg2->peek())); }
/** * Creates a FetchAction message from the Message. * * @param \AlphaRPC\Common\Socket\Message $msg * * @throws InvalidArgumentException * * @return self */ public static function fromMessage(Message $msg) { $count = $msg->shift(); if ($count != $msg->count()) { throw new InvalidArgumentException('The action count is not the same as the actual number of actions.'); } return new self($msg->toArray()); }
/** * Creates an instance based on the Message. * * @param Message $msg * * @return WorkerHandlerStatus */ public static function fromMessage(Message $msg) { $workerHandlerId = $msg->shift(); $requestId = $msg->shift(); if (!$requestId) { $requestId = null; } return new self($workerHandlerId, $requestId); }
/** * Create a new Message from this instance. * * @return Message */ public function toMessage() { $m = new Message(); /* @var $w Worker */ foreach ($this->workerStatus as $w) { $m->push($w['id']); $m->push(count($w['actionList'])); $m->append($w['actionList']); $m->push($w['current']); $m->push($w['ready']); $m->push($w['valid']); } return $m; }
/** * Create a new Message from this instance. * * @return Message */ public function toMessage() { $m = new Message(); foreach ($this->queueStatus as $action) { $m->push($action['action']); $m->push($action['queue']); $m->push($action['busy']); $m->push($action['available']); } return $m; }
/** * Creates a ActionResponse message from the Message. * * @param \AlphaRPC\Common\Socket\Message $msg * * @return StorageStatus */ public static function fromMessage(Message $msg) { return new self($msg->toArray()); }
/** * Creates a FetchAction message from the Message. * * @param \AlphaRPC\Common\Socket\Message $msg * * @return StorageStatus */ public static function fromMessage(Message $msg) { return new static($msg->shift(), $msg->shift()); }
/** * Create a new Message from this StorageStatus. * * @return Message */ public function toMessage() { $m = new Message(array($this->getRequestId(), $this->getActionName())); $m->append($this->getParameters()); return $m; }
/** * Create a new Message from this FetchActions. * * @return \AlphaRPC\Common\Socket\Message */ public function toMessage() { $msg = new Message(array($this->requestId, $this->action)); $msg->append($this->params); return $msg; }
/** * Send a Messsage. * * @param Message $msg * * @return Socket */ public function msend(Message $msg) { if (ZMQ::SOCKET_ROUTER === $this->getSocketType()) { $msg->prepend($msg->getRoutingInformation()); } if ($this->verbose) { $this->getLogger()->debug('SEND: ' . $this->id); $this->getLogger()->debug($msg); } $parts = $msg->toArray(); $iMax = count($parts) - 1; if ($iMax < 0) { throw new RuntimeException('No parts to send.'); } for ($i = 0; $i < $iMax; $i++) { $this->send($parts[$i], ZMQ::MODE_SNDMORE); } $this->send($parts[$iMax]); if ($this->verbose) { $this->getLogger()->debug('Message sent.'); } return $this; }
/** * @param Message $message * * @return boolean */ public static function isProtocolMessage(Message $message) { // Temporary check to maintain BC with legacy Messages. if (is_numeric($message->peek()) && $message->peek() < 100) { return true; } return false; }
/** * Creates an instance of this class based on the Message. * * @param Message $msg * * @return ExecuteResponse */ public static function fromMessage(Message $msg) { $request_id = $msg->shift(); $result = $msg->shift() ?: ''; return new self($request_id, $result); }