lockRow(); $now = abj_clock()->now(); $claimValue = ABJ_404_Solution_ExclusiveOptionRow::uniqueClaimValue( (string)($now + self::TTL_SECONDS) ); $claim = array('optionName' => self::OPTION_NAME, 'value' => $claimValue); if ($lockRow->claim($claim)) { return $claimValue; } $existing = $lockRow->valueOf(self::OPTION_NAME); $expiryPart = explode(':', $existing, 2)[0]; $expiry = ABJ_404_Solution_ExactInteger::read($expiryPart, 0); $existingIsStale = $existing === '' || $expiry === null || $expiry <= $now; if (!$existingIsStale) { return null; } if ($existing !== '' && !$lockRow->releaseIfValueIs(array( 'optionName' => self::OPTION_NAME, 'value' => $existing, ))) { return null; } return $lockRow->claim($claim) ? $claimValue : null; } /** Release only the exact claim this instance acquired. */ public function release(string $claimValue): void { $this->lockRow()->releaseIfValueIs(array( 'optionName' => self::OPTION_NAME, 'value' => $claimValue, )); } private function lockRow(): ABJ_404_Solution_ExclusiveOptionRow { return new ABJ_404_Solution_ExclusiveOptionRow(); } }