]> git.mxchange.org Git - friendica.git/blob - src/Core/Lock/Capability/ICanLock.php
Use the post language for the language detection / config for quality
[friendica.git] / src / Core / Lock / Capability / ICanLock.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Core\Lock\Capability;
23
24 use Friendica\Core\Cache\Enum\Duration;
25 use Friendica\Core\Lock\Exception\LockPersistenceException;
26
27 /**
28  * Lock Interface
29  */
30 interface ICanLock
31 {
32         /**
33          * Checks, if a key is currently locked to a or my process
34          *
35          * @param string $key The name of the lock
36          */
37         public function isLocked(string $key): bool;
38
39         /**
40          *
41          * Acquires a lock for a given name
42          *
43          * @param string  $key     The Name of the lock
44          * @param integer $timeout Seconds until we give up
45          * @param integer $ttl     Seconds The lock lifespan, must be one of the Cache constants
46          *
47          * @throws LockPersistenceException In case the underlying persistence throws errors
48          */
49         public function acquire(string $key, int $timeout = 120, int $ttl = Duration::FIVE_MINUTES): bool;
50
51         /**
52          * Releases a lock if it was set by us
53          *
54          * @param string $key      The Name of the lock
55          * @param bool   $override Overrides the lock to get released
56          *
57          * @return bool Was the unlock successful?
58          *
59          * @throws LockPersistenceException In case the underlying persistence throws errors
60          */
61         public function release(string $key, bool $override = false): bool;
62
63         /**
64          * Releases all lock that were set by us
65          *
66          * @param bool $override Override to release all locks
67          *
68          * @return bool Was the unlock of all locks successful?
69          *
70          * @throws LockPersistenceException In case the underlying persistence throws errors
71          */
72         public function releaseAll(bool $override = false): bool;
73
74         /**
75          * Returns the name of the current lock
76          */
77         public function getName(): string;
78
79         /**
80          * Lists all locks
81          *
82          * @param string prefix optional a prefix to search
83          *
84          * @return string[] Empty if it isn't supported by the cache driver
85          *
86          * @throws LockPersistenceException In case the underlying persistence throws errors
87          */
88         public function getLocks(string $prefix = ''): array;
89 }