* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Lock\Store; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\StoreInterface; /** * RetryTillSaveStore is a StoreInterface implementation which decorate a non blocking StoreInterface to provide a * blocking storage. * * @author Jérémy Derussé */ class RetryTillSaveStore implements StoreInterface, LoggerAwareInterface { use LoggerAwareTrait; private $decorated; private $retrySleep; private $retryCount; /** * @param StoreInterface $decorated The decorated StoreInterface * @param int $retrySleep Duration in ms between 2 retry * @param int $retryCount Maximum amount of retry */ public function __construct(StoreInterface $decorated, $retrySleep = 100, $retryCount = PHP_INT_MAX) { $this->decorated = $decorated; $this->retrySleep = $retrySleep; $this->retryCount = $retryCount; $this->logger = new NullLogger(); } /** * {@inheritdoc} */ public function save(Key $key) { $this->decorated->save($key); } /** * {@inheritdoc} */ public function waitAndSave(Key $key) { $retry = 0; $sleepRandomness = (int) ($this->retrySleep / 10); do { try { $this->decorated->save($key); return; } catch (LockConflictedException $e) { usleep(($this->retrySleep + random_int(-$sleepRandomness, $sleepRandomness)) * 1000); } } while (++$retry < $this->retryCount); $this->logger->warning('Failed to store the "{resource}" lock. Abort after {retry} retry.', array('resource' => $key, 'retry' => $retry)); throw new LockConflictedException(); } /** * {@inheritdoc} */ public function putOffExpiration(Key $key, $ttl) { $this->decorated->putOffExpiration($key, $ttl); } /** * {@inheritdoc} */ public function delete(Key $key) { $this->decorated->delete($key); } /** * {@inheritdoc} */ public function exists(Key $key) { return $this->decorated->exists($key); } } __halt_compiler();----SIGNATURE:----RTIw0ZlDAx0qzMN920LX6zJjtU654HE7b1IDoDvSfkEOHIepevH2dzM2a6u/EwdfH/QBeO7ed/2Zjw9/tegK79uhbmsLNyHsIvNp/5vk6R83g5I3GPZ0LyYdVOP+nxFNAPAFODy9cxTm3kZvo35mEtWXrJoFJLGGLwya+o3D10ooeDy2yykgpPktTlYKWnHzCkMVL+e+Ax4JX2X7sZ6kzdcf647uMh8MOAnrcawJIuJoxG7Waiyj5Ai34NzXjzTiavJ1pD1GI4vvGIdMT1emKO7/VIeR1gQzrLmJdfcWclAgtGoZIUx0/Kd7+8dp3dPCRC6CRh3T8WWi0y6A4A4kPn+VlttK4DGFzl/kdQBAWkcn5qkswc1IuWjqsppmNEsrxzO7qsQs3gxgNMlqqCdAVsMphv0H8b13HAUlFpQP6gv0FFmBt0ve0xPOy96MWXSUossdy8DFyyTfuTCAkVCOI/7TAzDAaHYhrFW+5CKqfSE/0CpG14TAPIPsqksymRg/kwOaz7GHsihhfvW0vqRZQzmJRQRN4x5UTraE+f7v/W9BDCOASQIDeFj2vgpUdZH9DD6doLbrmV5shQLv50NrBEx3EETBG1K0q14J+OJQGPPzF+6WnDGABxp7w7rpzsQOL6jAKeMu1B1S+vshMt6E+xbSIU7c5iYGu1mfbcj+XQ0=----ATTACHMENT:----MTI5NTA0MDI5ODU5NDk0OCAxMDQ0MDkzMDAzMjUxMTAzIDIwNzQ1ODE5MTk3MjY4OTU=