Restructure Lock to follow new paradigm
This commit is contained in:
parent
ab83d0dd27
commit
ff1a812e1a
|
@ -19,7 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\Lock;
|
namespace Friendica\Core\Lock\Enum;
|
||||||
|
|
||||||
use Friendica\Core\Cache\Enum\Type as CacheType;
|
use Friendica\Core\Cache\Enum\Type as CacheType;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Factory;
|
namespace Friendica\Core\Lock\Factory;
|
||||||
|
|
||||||
use Friendica\Core\Cache\Factory\CacheFactory;
|
use Friendica\Core\Cache\Factory\CacheFactory;
|
||||||
use Friendica\Core\Cache\IMemoryCache;
|
use Friendica\Core\Cache\IMemoryCache;
|
||||||
|
@ -83,18 +83,18 @@ class LockFactory
|
||||||
case Type::APCU:
|
case Type::APCU:
|
||||||
$cache = $this->cacheFactory->create($lock_type);
|
$cache = $this->cacheFactory->create($lock_type);
|
||||||
if ($cache instanceof IMemoryCache) {
|
if ($cache instanceof IMemoryCache) {
|
||||||
return new Lock\CacheLock($cache);
|
return new Lock\Type\CacheLock($cache);
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception(sprintf('Incompatible cache driver \'%s\' for lock used', $lock_type));
|
throw new \Exception(sprintf('Incompatible cache driver \'%s\' for lock used', $lock_type));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'database':
|
case 'database':
|
||||||
return new Lock\DatabaseLock($this->dba);
|
return new Lock\Type\DatabaseLock($this->dba);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'semaphore':
|
case 'semaphore':
|
||||||
return new Lock\SemaphoreLock();
|
return new Lock\Type\SemaphoreLock();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -121,7 +121,7 @@ class LockFactory
|
||||||
// 1. Try to use Semaphores for - local - locking
|
// 1. Try to use Semaphores for - local - locking
|
||||||
if (function_exists('sem_get')) {
|
if (function_exists('sem_get')) {
|
||||||
try {
|
try {
|
||||||
return new Lock\SemaphoreLock();
|
return new Lock\Type\SemaphoreLock();
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$this->logger->warning('Using Semaphore driver for locking failed.', ['exception' => $exception]);
|
$this->logger->warning('Using Semaphore driver for locking failed.', ['exception' => $exception]);
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ class LockFactory
|
||||||
try {
|
try {
|
||||||
$cache = $this->cacheFactory->create($cache_type);
|
$cache = $this->cacheFactory->create($cache_type);
|
||||||
if ($cache instanceof IMemoryCache) {
|
if ($cache instanceof IMemoryCache) {
|
||||||
return new Lock\CacheLock($cache);
|
return new Lock\Type\CacheLock($cache);
|
||||||
}
|
}
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$this->logger->warning('Using Cache driver for locking failed.', ['exception' => $exception]);
|
$this->logger->warning('Using Cache driver for locking failed.', ['exception' => $exception]);
|
||||||
|
@ -141,6 +141,6 @@ class LockFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Use Database Locking as a Fallback
|
// 3. Use Database Locking as a Fallback
|
||||||
return new Lock\DatabaseLock($this->dba);
|
return new Lock\Type\DatabaseLock($this->dba);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,7 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core\Lock\Type;
|
||||||
|
|
||||||
use Friendica\Core\Lock\ILock;
|
use Friendica\Core\Lock\ILock;
|
||||||
|
|
|
@ -19,9 +19,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\Lock;
|
namespace Friendica\Core\Lock\Type;
|
||||||
|
|
||||||
use Friendica\Core\BaseLock;
|
|
||||||
use Friendica\Core\Cache\Enum\Duration;
|
use Friendica\Core\Cache\Enum\Duration;
|
||||||
use Friendica\Core\Cache\IMemoryCache;
|
use Friendica\Core\Cache\IMemoryCache;
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\Lock;
|
namespace Friendica\Core\Lock\Type;
|
||||||
|
|
||||||
use Friendica\Core\BaseLock;
|
|
||||||
use Friendica\Core\Cache\Enum\Duration;
|
use Friendica\Core\Cache\Enum\Duration;
|
||||||
|
use Friendica\Core\Lock\Enum\Type;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
|
|
@ -19,10 +19,11 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Core\Lock;
|
namespace Friendica\Core\Lock\Type;
|
||||||
|
|
||||||
use Friendica\Core\BaseLock;
|
|
||||||
use Friendica\Core\Cache\Enum\Duration;
|
use Friendica\Core\Cache\Enum\Duration;
|
||||||
|
use Friendica\Core\Lock\Enum\Type;
|
||||||
|
use function get_temppath;
|
||||||
|
|
||||||
class SemaphoreLock extends BaseLock
|
class SemaphoreLock extends BaseLock
|
||||||
{
|
{
|
|
@ -39,7 +39,7 @@ use Friendica\Core\Cache;
|
||||||
use Friendica\Core\Config;
|
use Friendica\Core\Config;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Lock\ILock;
|
use Friendica\Core\Lock;
|
||||||
use Friendica\Core\Process;
|
use Friendica\Core\Process;
|
||||||
use Friendica\Core\Session\ISession;
|
use Friendica\Core\Session\ISession;
|
||||||
use Friendica\Core\StorageManager;
|
use Friendica\Core\StorageManager;
|
||||||
|
@ -101,7 +101,7 @@ return [
|
||||||
['create', [], Dice::CHAIN_CALL],
|
['create', [], Dice::CHAIN_CALL],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
\Friendica\Core\PConfig\IPConfig::class => [
|
PConfig\IPConfig::class => [
|
||||||
'instanceOf' => PConfig\Factory\PConfigFactory::class,
|
'instanceOf' => PConfig\Factory\PConfigFactory::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['create', [], Dice::CHAIN_CALL],
|
['create', [], Dice::CHAIN_CALL],
|
||||||
|
@ -170,8 +170,8 @@ return [
|
||||||
['create', [], Dice::CHAIN_CALL],
|
['create', [], Dice::CHAIN_CALL],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
ILock::class => [
|
Lock\ILock::class => [
|
||||||
'instanceOf' => Factory\LockFactory::class,
|
'instanceOf' => Lock\Factory\LockFactory::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['create', [], Dice::CHAIN_CALL],
|
['create', [], Dice::CHAIN_CALL],
|
||||||
],
|
],
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
namespace Friendica\Test\src\Core\Lock;
|
namespace Friendica\Test\src\Core\Lock;
|
||||||
|
|
||||||
use Friendica\Core\Cache\Type\APCuCache;
|
use Friendica\Core\Cache\Type\APCuCache;
|
||||||
use Friendica\Core\Lock\CacheLock;
|
use Friendica\Core\Lock\Type\CacheLock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group APCU
|
* @group APCU
|
||||||
|
@ -40,6 +40,6 @@ class APCuCacheLockTest extends LockTest
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
return new CacheLock(new APCuCache('localhost'));
|
return new \Friendica\Core\Lock\Type\CacheLock(new APCuCache('localhost'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,13 @@
|
||||||
namespace Friendica\Test\src\Core\Lock;
|
namespace Friendica\Test\src\Core\Lock;
|
||||||
|
|
||||||
use Friendica\Core\Cache\Type\ArrayCache;
|
use Friendica\Core\Cache\Type\ArrayCache;
|
||||||
use Friendica\Core\Lock\CacheLock;
|
use Friendica\Core\Lock\Type\CacheLock;
|
||||||
|
|
||||||
class ArrayCacheLockTest extends LockTest
|
class ArrayCacheLockTest extends LockTest
|
||||||
{
|
{
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
return new CacheLock(new ArrayCache('localhost'));
|
return new \Friendica\Core\Lock\Type\CacheLock(new ArrayCache('localhost'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Test\src\Core\Lock;
|
namespace Friendica\Test\src\Core\Lock;
|
||||||
|
|
||||||
use Friendica\Core\Lock\DatabaseLock;
|
use Friendica\Core\Lock\Type\DatabaseLock;
|
||||||
use Friendica\Core\Config\Factory\ConfigFactory;
|
use Friendica\Core\Config\Factory\ConfigFactory;
|
||||||
use Friendica\Test\DatabaseTestTrait;
|
use Friendica\Test\DatabaseTestTrait;
|
||||||
use Friendica\Test\Util\Database\StaticDatabase;
|
use Friendica\Test\Util\Database\StaticDatabase;
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Test\src\Core\Lock;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\Core\Cache\Type\MemcacheCache;
|
use Friendica\Core\Cache\Type\MemcacheCache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\Lock\CacheLock;
|
use Friendica\Core\Lock\Type\CacheLock;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,7 @@ class MemcacheCacheLockTest extends LockTest
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$cache = new MemcacheCache($host, $configMock);
|
$cache = new MemcacheCache($host, $configMock);
|
||||||
$lock = new CacheLock($cache);
|
$lock = new \Friendica\Core\Lock\Type\CacheLock($cache);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
static::markTestSkipped('Memcache is not available');
|
static::markTestSkipped('Memcache is not available');
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Test\src\Core\Lock;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\Core\Cache\Type\MemcachedCache;
|
use Friendica\Core\Cache\Type\MemcachedCache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\Lock\CacheLock;
|
use Friendica\Core\Lock\Type\CacheLock;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Test\src\Core\Lock;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\Core\Cache\Type\RedisCache;
|
use Friendica\Core\Cache\Type\RedisCache;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\Lock\CacheLock;
|
use Friendica\Core\Lock\Type\CacheLock;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +62,7 @@ class RedisCacheLockTest extends LockTest
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$cache = new RedisCache($host, $configMock);
|
$cache = new RedisCache($host, $configMock);
|
||||||
$lock = new CacheLock($cache);
|
$lock = new \Friendica\Core\Lock\Type\CacheLock($cache);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
static::markTestSkipped('Redis is not available. Error: ' . $e->getMessage());
|
static::markTestSkipped('Redis is not available. Error: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ use Dice\Dice;
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Config\IConfig;
|
use Friendica\Core\Config\IConfig;
|
||||||
use Friendica\Core\Config\Type\JitConfig;
|
use Friendica\Core\Config\Type\JitConfig;
|
||||||
use Friendica\Core\Lock\SemaphoreLock;
|
use Friendica\Core\Lock\Type\SemaphoreLock;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Mockery\MockInterface;
|
use Mockery\MockInterface;
|
||||||
|
@ -56,7 +56,7 @@ class SemaphoreLockTest extends LockTest
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
return new SemaphoreLock();
|
return new \Friendica\Core\Lock\Type\SemaphoreLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue