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