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