Make RetryTillSaveStore implements the SharedLockStoreInterface

This commit is contained in:
Jérémy Derussé 2020-09-15 11:39:42 +02:00
parent f1f37a899c
commit a0321e66c9
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2

View File

@ -16,8 +16,10 @@ use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger; use Psr\Log\NullLogger;
use Symfony\Component\Lock\BlockingStoreInterface; use Symfony\Component\Lock\BlockingStoreInterface;
use Symfony\Component\Lock\Exception\LockConflictedException; use Symfony\Component\Lock\Exception\LockConflictedException;
use Symfony\Component\Lock\Exception\NotSupportedException;
use Symfony\Component\Lock\Key; use Symfony\Component\Lock\Key;
use Symfony\Component\Lock\PersistingStoreInterface; use Symfony\Component\Lock\PersistingStoreInterface;
use Symfony\Component\Lock\SharedLockStoreInterface;
/** /**
* RetryTillSaveStore is a PersistingStoreInterface implementation which decorate a non blocking PersistingStoreInterface to provide a * RetryTillSaveStore is a PersistingStoreInterface implementation which decorate a non blocking PersistingStoreInterface to provide a
@ -25,7 +27,7 @@ use Symfony\Component\Lock\PersistingStoreInterface;
* *
* @author Jérémy Derussé <jeremy@derusse.com> * @author Jérémy Derussé <jeremy@derusse.com>
*/ */
class RetryTillSaveStore implements BlockingStoreInterface, LoggerAwareInterface class RetryTillSaveStore implements BlockingStoreInterface, SharedLockStoreInterface, LoggerAwareInterface
{ {
use LoggerAwareTrait; use LoggerAwareTrait;
@ -76,6 +78,24 @@ class RetryTillSaveStore implements BlockingStoreInterface, LoggerAwareInterface
throw new LockConflictedException(); throw new LockConflictedException();
} }
public function saveRead(Key $key)
{
if (!$this->decorated instanceof SharedLockStoreInterface) {
throw new NotSupportedException(sprintf('The "%s" store must decorate a "%s" store.', get_debug_type($this), ShareLockStoreInterface::class));
}
$this->decorated->saveRead($key);
}
public function waitAndSaveRead(Key $key)
{
if (!$this->decorated instanceof SharedLockStoreInterface) {
throw new NotSupportedException(sprintf('The "%s" store must decorate a "%s" store.', get_debug_type($this), ShareLockStoreInterface::class));
}
$this->decorated->waitAndSaveRead($key);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */