/**
  * Sets internal values for aggregations when the next cycle is calculated.
  */
 public function tick()
 {
     $this->metrics->set('objects', $this->getAddedObjectCount());
     $this->metrics->set('evictions', $this->getEvictedObjectCount());
     $this->metrics->set('memory', $this->getMemoryUsageMb());
     $this->metrics->set('memory_peak', $this->getMemoryPeakUsageMb());
     if (!$this->countAbsolute) {
         $this->evictedObjectCount = 0;
         $this->addedObjectCount = 0;
     } else {
         $this->setLastEvictionCount($this->getEvictedObjectCount());
         $this->setLastObjectCount($this->getAddedObjectCount());
     }
 }
 /**
  * Registers the gearman queues where the worker has to listen on.
  * The given callback has to transform the workload into a RequestMessage object.
  *
  * @param string $callbackName
  * @param callable $workloadToMessageCallback The return value of
  */
 public function listenOn($callbackName, callable $workloadToMessageCallback)
 {
     $this->addCallback($callbackName, function ($job) use($workloadToMessageCallback) {
         $message = call_user_func($workloadToMessageCallback, $job->workload());
         if ($message instanceof RequestMessageInterface) {
             if ($this->verbose) {
                 $this->logger->debug("Sending message to queue: " . (string) $message);
             }
             $this->metrics->increment('message');
             $this->client->message($message);
         } else {
             throw new \Exception("Invalid return type.");
         }
     });
 }