Example #1
0
 /**
  * load next topic
  *
  * @access public
  * @return void
  */
 public function loadNextTopic()
 {
     if ($this->validCount >= $this->topicCount) {
         \Kafka\Protocol\Fetch\Helper\Helper::onStreamEof($this->currentStreamLockKey);
         return false;
     }
     if ($this->currentStreamCount >= $this->topicCounts[$this->currentStreamKey]) {
         \Kafka\Protocol\Fetch\Helper\Helper::onStreamEof($this->currentStreamLockKey);
         $this->currentStreamKey++;
     }
     $lockKeys = array_keys($this->streams);
     $streams = array_values($this->streams);
     if (!isset($streams[$this->currentStreamKey])) {
         return false;
     }
     $stream = $streams[$this->currentStreamKey];
     $this->currentStreamLockKey = $lockKeys[$this->currentStreamKey];
     try {
         $topicLen = $stream->read(2, true);
         $topicLen = Decoder::unpack(Decoder::BIT_B16, $topicLen);
         $topicLen = array_shift($topicLen);
         if ($topicLen <= 0) {
             return false;
         }
         // topic name
         $this->key = $stream->read($topicLen, true);
         $this->current = new Partition($this, $this->context);
     } catch (\Kafka\Exception $e) {
         return false;
     }
     $this->validCount++;
     $this->currentStreamCount++;
     return true;
 }