2018-06-26 20:31:04 +00:00
|
|
|
<?php
|
2020-02-09 14:45:36 +00:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @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/>.
|
|
|
|
*
|
|
|
|
*/
|
2018-06-26 20:31:04 +00:00
|
|
|
|
2018-06-28 20:57:17 +00:00
|
|
|
namespace Friendica\Core\Lock;
|
2019-08-03 18:48:56 +00:00
|
|
|
|
2020-01-18 19:15:46 +00:00
|
|
|
use Friendica\Core\Cache\Duration;
|
2018-06-26 20:31:04 +00:00
|
|
|
|
|
|
|
/**
|
2019-08-04 08:26:53 +00:00
|
|
|
* Lock Interface
|
2018-06-26 20:31:04 +00:00
|
|
|
*/
|
2019-08-04 08:26:53 +00:00
|
|
|
interface ILock
|
2018-06-26 20:31:04 +00:00
|
|
|
{
|
2018-07-04 21:37:22 +00:00
|
|
|
/**
|
2018-07-05 05:59:56 +00:00
|
|
|
* Checks, if a key is currently locked to a or my process
|
2018-07-04 21:37:22 +00:00
|
|
|
*
|
2019-08-03 18:48:56 +00:00
|
|
|
* @param string $key The name of the lock
|
|
|
|
*
|
2018-07-04 21:37:22 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isLocked($key);
|
|
|
|
|
2018-06-26 20:31:04 +00:00
|
|
|
/**
|
|
|
|
*
|
2018-07-05 05:59:56 +00:00
|
|
|
* Acquires a lock for a given name
|
2018-06-26 20:31:04 +00:00
|
|
|
*
|
2019-08-03 18:48:56 +00:00
|
|
|
* @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
|
2018-06-26 20:31:04 +00:00
|
|
|
*
|
|
|
|
* @return boolean Was the lock successful?
|
|
|
|
*/
|
2020-01-18 19:15:46 +00:00
|
|
|
public function acquire($key, $timeout = 120, $ttl = Duration::FIVE_MINUTES);
|
2018-06-26 20:31:04 +00:00
|
|
|
|
|
|
|
/**
|
2018-07-05 05:59:56 +00:00
|
|
|
* Releases a lock if it was set by us
|
2018-06-26 20:31:04 +00:00
|
|
|
*
|
2019-02-24 11:24:09 +00:00
|
|
|
* @param string $key The Name of the lock
|
|
|
|
* @param bool $override Overrides the lock to get released
|
2018-06-26 20:31:04 +00:00
|
|
|
*
|
2019-03-04 20:28:36 +00:00
|
|
|
* @return boolean Was the unlock successful?
|
2018-06-26 20:31:04 +00:00
|
|
|
*/
|
2020-01-06 23:24:10 +00:00
|
|
|
public function release($key, $override = false);
|
2018-06-26 20:31:04 +00:00
|
|
|
|
|
|
|
/**
|
2018-07-05 05:59:56 +00:00
|
|
|
* Releases all lock that were set by us
|
2018-06-26 20:31:04 +00:00
|
|
|
*
|
2019-08-13 19:20:41 +00:00
|
|
|
* @param bool $override Override to release all locks
|
|
|
|
*
|
2019-03-04 20:28:36 +00:00
|
|
|
* @return boolean Was the unlock of all locks successful?
|
2018-06-26 20:31:04 +00:00
|
|
|
*/
|
2019-08-13 19:20:41 +00:00
|
|
|
public function releaseAll($override = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of the current lock
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getName();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists all locks
|
|
|
|
*
|
|
|
|
* @param string prefix optional a prefix to search
|
|
|
|
*
|
|
|
|
* @return array Empty if it isn't supported by the cache driver
|
|
|
|
*/
|
|
|
|
public function getLocks(string $prefix = '');
|
2018-06-26 21:44:30 +00:00
|
|
|
}
|