/** * Load in previous master positions for the client */ protected function initPositions() { if ($this->initialized) { return; } $this->initialized = true; if ($this->wait) { // If there is an expectation to see master positions with a certain min // timestamp, then block until they appear, or until a timeout is reached. if ($this->waitForPosTime > 0.0) { $data = null; $loop = new WaitConditionLoop(function () use(&$data) { $data = $this->store->get($this->key); return self::minPosTime($data) >= $this->waitForPosTime ? WaitConditionLoop::CONDITION_REACHED : WaitConditionLoop::CONDITION_CONTINUE; }, $this->waitForPosTimeout); $result = $loop->invoke(); $waitedMs = $loop->getLastWaitTime() * 1000.0; if ($result == $loop::CONDITION_REACHED) { $msg = "expected and found pos time {$this->waitForPosTime} ({$waitedMs}ms)"; $this->logger->debug($msg); } else { $msg = "expected but missed pos time {$this->waitForPosTime} ({$waitedMs}ms)"; $this->logger->info($msg); } } else { $data = $this->store->get($this->key); } $this->startupPositions = $data ? $data['positions'] : []; $this->logger->info(__METHOD__ . ": key is {$this->key} (read)\n"); } else { $this->startupPositions = []; $this->logger->info(__METHOD__ . ": key is {$this->key} (unread)\n"); } }