public function testParseAndGetData() { //$m = str_replace("\0","",'30:a:2:{s:1:"a";i:0;s:1:"b";i:0;}30:a:2:{s:1:"a";i:7;s:1:"b";i:8;}31:a:2:{s:1:"a";i:0;s:1:"b";i:10;}31:a:2:{s:1:"a";i:10;s:1:"b";i:4;}30:a:2:{s:1:"a";i:3;s:1:"b";i:2;}30:a:2:{s:1:"a";i:8;s:1:"b";i:2;}30:a:2:{s:1:"a";i:5;s:1:"b";i:8;}30:a:2:{s:1:"a";i:7;s:1:"b";i:3;}30:a:2:{s:1:"a";i:5;s:1:"b";i:9;}30:a:2:{s:1:"a";i:9;s:1:"b";i:6;}'); $m = 'key:type|30:a:2:{s:1:"a";i:0;s:1:"b";i:0;}30:a:2:{s:1:"a";i:7;s:1:"b";i:8;}31:a:2:{s:1:"a";i:0;s:1:"b";i:10;}31:a:2:{s:1:"a";i:10;s:1:"b";i:4;}30:a:2:{s:1:"a";i:3;s:1:"b";i:2;}30:a:2:{s:1:"a";i:8;s:1:"b";i:2;}30:a:2:{s:1:"a";i:5;s:1:"b";i:8;}30:a:2:{s:1:"a";i:7;s:1:"b";i:3;}30:a:2:{s:1:"a";i:5;s:1:"b";i:9;}30:a:2:{s:1:"a";i:9;s:1:"b";i:6;}'; $r = new ResponseMessage($m); $r->parse(); $this->assertEquals(10, count($r->getData())); }
/** * Consumes evicted objects from the outbound queue. */ public function consume() { $this->logger->info("Connecting to server outbound queue on '{$this->getZmq()}'."); $client = new Client($this->getZmq()); $client->connect(); $i = 0; while (true) { $i++; $rawMessage = $client->receive(); try { $msg = ResponseMessage::fromString($rawMessage); $rows = $msg->getData(); if ($this->isVerbose()) { $this->logger->debug("Received raw message: " . $rawMessage); } switch ($msg->getType()) { case 'aggregate': $result = $this->reducerAggregate($rows); break; case 'count': $result = $this->reducerCount($rows); break; default: $result = $rows; } if ($this->isVerbose()) { $this->logger->debug("Reduced result for key '{$msg->getKey()}' and type '{$msg->getType()}':" . var_export($result, true)); } } catch (\Exception $e) { $this->logger->error((string) $e); } if ($i % 1000 == 0) { $this->logger->info("Fetched {$i} messages."); } } }
/** * Registers the eviction of items from the queue. */ private function registerEvictionEvents() { $this->reactLoop->addPeriodicTimer(1 / $this->config->getEvictionTicksPerSec(), function () { if (($item = $this->getQueue()->evict(round(microtime(true) * 1000000))) !== null) { if ($this->isInLogLevel(Logger::DEBUG)) { $this->logger->debug("[Eviction] Timeout detected for '{$item->getKey()}' at " . round($item->getPriority() / 1000000, 3)); } $this->getZmqOutboundQueue()->send(ResponseMessage::fromQueueItemToString($item)); $this->runtimeStatistics->incrementEvictedObjectCount(); } }); }
/** * @param string $message * @param bool $doUnserialize * @return ResponseMessage * @throws \Exception */ public static function fromString($message, $doUnserialize = false) { $m = new ResponseMessage($message); $m->parse($doUnserialize); return $m; }