protected function _getDownloadListFromWorker() { $zmsg = new Zmsg($this->_socketToWorker); $zmsg->recv(); $this->_downloadList = unserialize($zmsg->body()); $this->log('received downloadlist from worker, nr of elements: %d', count($this->_downloadList)); }
/** * Submit the $jobs to the server to be processed * * @param ZMASocket $req * * @param array $jobs */ protected function submitJobs(ZMQSocket $req, array $jobs) { foreach ($jobs as $job) { $this->log(__CLASS__, "Sending job to server"); $zmsg = new Zmsg($req); $zmsg->body_set(serialize($job))->send(); } }
public function getInstance(\ZMQ\Zmsg $zmsg) { $message = unserialize($zmsg->body()); $class = get_class($message); $handlerClass = str_replace('Message', 'MessageHandler', $class); if (!isset($this->_messageHandlerCache[$handlerClass])) { if (false === class_exists($handlerClass)) { throw new \UnexpectedValueException(sprintf('invalid handlerClass %s', $handlerClass)); } $handler = new $handlerClass($this->_config, $this->_queueManager); $this->_messageHandlerCache[$handlerClass] = $handler; } $this->_messageHandlerCache[$handlerClass]->setMessage($zmsg, $message); return $this->_messageHandlerCache[$handlerClass]; }
protected function _run() { $this->_forkDownloader(); $bindTo = sprintf('ipc:///tmp/downloader-%d.ipc', $this->_data['download_bundle_id']); $socketToDownloader = $this->_context->getSocket(\ZMQ::SOCKET_PAIR); $socketToDownloader->bind($bindTo); $this->_process->log('bind socket to %s', $bindTo); $zmsg = new Zmsg($socketToDownloader); $zmsg->body_set(serialize($this->_data['download_list'])); $zmsg->send(); $zmsg->recv(); $this->_process->log('received message from downloader'); /** @var $msg \SAP\Daemon\Message\Download\CheckResult */ $msg = unserialize($zmsg->body()); if (!$msg->hasNotReachableDownloads()) { $this->_setResult(array('success' => true, 'message' => 'downloads started successfully')); } else { $this->_setResult(array('success' => false, 'message' => 'reachability check of downloads failed', 'not-reachable-downloads' => $msg->getNotReachableDownloadsWithReason())); } unset($socketToDownloader); }
/** * @param string $targetAddress * @param mixed $data */ public function sendMessageTo($targetAddress, $data) { $zmsg = new Zmsg($this->_socket); $zmsg->body_set(serialize($data)); $zmsg->wrap($targetAddress); $zmsg->send(); }
/** * Run a self test of the Zmsg class. * * @return boolean * @todo See if assert returns */ public static function test() { $result = true; $context = new ZMQContext(); $output = new ZMQSocket($context, ZMQ::SOCKET_XREQ); $output->bind("inproc://zmsg_selftest"); $input = new ZMQSocket($context, ZMQ::SOCKET_XREP); $input->connect("inproc://zmsg_selftest"); // Test send and receive of single-part message $zmsgo = new Zmsg($output); $zmsgo->body_set("Hello"); $result &= assert($zmsgo->body() == "Hello"); $zmsgo->send(); $zmsgi = new Zmsg($input); $zmsgi->recv(); $result &= assert($zmsgi->parts() == 2); $result &= assert($zmsgi->body() == "Hello"); echo $zmsgi; // Test send and receive of multi-part message $zmsgo = new Zmsg($output); $zmsgo->body_set("Hello"); $zmsgo->wrap("address1", ""); $zmsgo->wrap("address2"); $result &= assert($zmsgo->parts() == 4); echo $zmsgo; $zmsgo->send(); $zmsgi = new Zmsg($input); $zmsgi->recv(); $result &= assert($zmsgi->parts() == 5); $zmsgi->unwrap(); $result &= assert($zmsgi->unwrap() == "address2"); $zmsgi->body_fmt("%s%s", 'W', "orld"); $result &= assert($zmsgi->body() == "World"); // Pull off address 1, check that empty part was dropped $zmsgi->unwrap(); $result &= assert($zmsgi->parts() == 1); // Check that message body was correctly modified $part = $zmsgi->pop(); $result &= assert($part == "World"); $result &= assert($zmsgi->parts() == 0); echo $result ? "OK" : "FAIL", PHP_EOL; return $result; }
public function curlProgress($fullSize, $alreadyDownloaded) { if ($fullSize > 0) { $this->log('progress: %d%%', $alreadyDownloaded / $fullSize * 100); } else { $this->log('fullsize is %d', $fullSize); } $message = new \Daemon\Message\Task\Add(array('task' => new \SAP\Daemon\Task\Download\UpdateStatus(array('download_id' => $this->_currentDownloadId, 'already_downloaded' => $alreadyDownloaded, 'full_size' => $fullSize)))); $zmsg = new \ZMQ\Zmsg($this->_socketToQueueManager); $zmsg->body_set(serialize($message)); $zmsg->send(); }
protected function _responseToQueueManager(Zmsg $zmsg, Message\AbstractMessage $msg) { $zmsg->body_set(serialize($msg))->send(); }