2018-06-26 20:31:04 +00:00
|
|
|
<?php
|
|
|
|
|
2018-06-28 20:57:17 +00:00
|
|
|
namespace Friendica\Core\Lock;
|
2019-08-03 18:48:56 +00:00
|
|
|
|
2018-07-07 17:46:16 +00:00
|
|
|
use Friendica\Core\Cache;
|
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
|
|
|
*
|
|
|
|
* @author Philipp Holzer <admin@philipp.info>
|
|
|
|
*/
|
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?
|
|
|
|
*/
|
2019-08-04 13:58:53 +00:00
|
|
|
public function acquireLock($key, $timeout = 120, $ttl = Cache\Cache::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
|
|
|
*/
|
2019-02-24 11:24:09 +00:00
|
|
|
public function releaseLock($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
|
|
|
}
|