2018-06-26 16:31:04 -04:00
|
|
|
<?php
|
|
|
|
|
2018-06-28 16:57:17 -04:00
|
|
|
namespace Friendica\Core\Lock;
|
2018-07-07 13:46:16 -04:00
|
|
|
use Friendica\Core\Cache;
|
2018-06-26 16:31:04 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lock Driver Interface
|
|
|
|
*
|
|
|
|
* @author Philipp Holzer <admin@philipp.info>
|
|
|
|
*/
|
|
|
|
interface ILockDriver
|
|
|
|
{
|
2018-07-04 17:37:22 -04:00
|
|
|
/**
|
2018-07-05 01:59:56 -04:00
|
|
|
* Checks, if a key is currently locked to a or my process
|
2018-07-04 17:37:22 -04:00
|
|
|
*
|
|
|
|
* @param string $key The name of the lock
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isLocked($key);
|
|
|
|
|
2018-06-26 16:31:04 -04:00
|
|
|
/**
|
|
|
|
*
|
2018-07-05 01:59:56 -04:00
|
|
|
* Acquires a lock for a given name
|
2018-06-26 16:31:04 -04:00
|
|
|
*
|
|
|
|
* @param string $key The Name of the lock
|
|
|
|
* @param integer $timeout Seconds until we give up
|
2018-07-07 13:46:16 -04:00
|
|
|
* @param integer $ttl Seconds The lock lifespan, must be one of the Cache constants
|
2018-06-26 16:31:04 -04:00
|
|
|
*
|
|
|
|
* @return boolean Was the lock successful?
|
|
|
|
*/
|
2018-07-07 13:46:16 -04:00
|
|
|
public function acquireLock($key, $timeout = 120, $ttl = Cache::FIVE_MINUTES);
|
2018-06-26 16:31:04 -04:00
|
|
|
|
|
|
|
/**
|
2018-07-05 01:59:56 -04:00
|
|
|
* Releases a lock if it was set by us
|
2018-06-26 16:31:04 -04:00
|
|
|
*
|
2019-02-24 06:24:09 -05:00
|
|
|
* @param string $key The Name of the lock
|
|
|
|
* @param bool $override Overrides the lock to get released
|
2018-06-26 16:31:04 -04:00
|
|
|
*
|
2019-03-04 15:28:36 -05:00
|
|
|
* @return boolean Was the unlock successful?
|
2018-06-26 16:31:04 -04:00
|
|
|
*/
|
2019-02-24 06:24:09 -05:00
|
|
|
public function releaseLock($key, $override = false);
|
2018-06-26 16:31:04 -04:00
|
|
|
|
|
|
|
/**
|
2018-07-05 01:59:56 -04:00
|
|
|
* Releases all lock that were set by us
|
2018-06-26 16:31:04 -04:00
|
|
|
*
|
2019-03-04 15:28:36 -05:00
|
|
|
* @return boolean Was the unlock of all locks successful?
|
2018-06-26 16:31:04 -04:00
|
|
|
*/
|
|
|
|
public function releaseAll();
|
2018-06-26 17:44:30 -04:00
|
|
|
}
|