friendica/src/Core/Lock/Capability/ICanLock.php

90 lines
2.6 KiB
PHP
Raw Normal View History

<?php
2020-02-09 15:45:36 +01:00
/**
2021-03-29 08:40:20 +02:00
* @copyright Copyright (C) 2010-2021, the Friendica project
2020-02-09 15:45:36 +01:00
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
2021-10-26 21:44:29 +02:00
namespace Friendica\Core\Lock\Capability;
use Friendica\Core\Cache\Enum\Duration;
2021-10-26 21:44:29 +02:00
use Friendica\Core\Lock\Exception\LockPersistenceException;
/**
* Lock Interface
*/
2021-10-26 21:44:29 +02:00
interface ICanLock
{
/**
2018-07-05 07:59:56 +02:00
* Checks, if a key is currently locked to a or my process
*
* @param string $key The name of the lock
*/
2021-10-26 21:44:29 +02:00
public function isLocked(string $key): bool;
/**
*
2018-07-05 07:59:56 +02:00
* Acquires a lock for a given name
*
* @param string $key The Name of the lock
* @param integer $timeout Seconds until we give up
* @param integer $ttl Seconds The lock lifespan, must be one of the Cache constants
*
2021-10-26 21:44:29 +02:00
* @throws LockPersistenceException In case the underlying persistence throws errors
*/
2021-10-26 21:44:29 +02:00
public function acquire(string $key, int $timeout = 120, int $ttl = Duration::FIVE_MINUTES): bool;
/**
2018-07-05 07:59:56 +02:00
* Releases a lock if it was set by us
*
* @param string $key The Name of the lock
* @param bool $override Overrides the lock to get released
*
2021-10-26 21:44:29 +02:00
* @return bool Was the unlock successful?
*
* @throws LockPersistenceException In case the underlying persistence throws errors
*/
2021-10-26 21:44:29 +02:00
public function release(string $key, bool $override = false): bool;
/**
2018-07-05 07:59:56 +02:00
* Releases all lock that were set by us
*
2019-08-13 21:20:41 +02:00
* @param bool $override Override to release all locks
*
2021-10-26 21:44:29 +02:00
* @return bool Was the unlock of all locks successful?
*
* @throws LockPersistenceException In case the underlying persistence throws errors
*/
2021-10-26 21:44:29 +02:00
public function releaseAll(bool $override = false): bool;
2019-08-13 21:20:41 +02:00
/**
* Returns the name of the current lock
*/
2021-10-26 21:44:29 +02:00
public function getName(): string;
2019-08-13 21:20:41 +02:00
/**
* Lists all locks
*
* @param string prefix optional a prefix to search
*
2021-10-26 21:44:29 +02:00
* @return string[] Empty if it isn't supported by the cache driver
*
* @throws LockPersistenceException In case the underlying persistence throws errors
2019-08-13 21:20:41 +02:00
*/
2021-10-26 21:44:29 +02:00
public function getLocks(string $prefix = ''): array;
2018-06-26 23:44:30 +02:00
}