[BUGFIX] Multiple fixes for Locking API and TSFE locking
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Locking / LockingStrategyInterface.php
1 <?php
2 namespace TYPO3\CMS\Core\Locking;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Locking\Exception\LockAcquireException;
18 use TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException;
19 use TYPO3\CMS\Core\Locking\Exception\LockCreateException;
20
21 /**
22 * Interface for locking methods
23 *
24 * @author Markus Klein <klein.t3@reelworx.at>
25 */
26 interface LockingStrategyInterface {
27
28 /**
29 * Exclusive locks can be acquired
30 */
31 const LOCK_CAPABILITY_EXCLUSIVE = 1;
32
33 /**
34 * Shared locks can be acquired
35 */
36 const LOCK_CAPABILITY_SHARED = 2;
37
38 /**
39 * Do not block when acquiring the lock
40 */
41 const LOCK_CAPABILITY_NOBLOCK = 4;
42
43 /**
44 * @return int LOCK_CAPABILITY_* elements combined with bit-wise OR
45 */
46 static public function getCapabilities();
47
48 /**
49 * @return int Returns a priority for the method. 0 to 100, 100 is highest
50 */
51 static public function getPriority();
52
53 /**
54 * @param string $subject ID to identify this lock in the system
55 * @throws LockCreateException if the lock could not be created
56 */
57 public function __construct($subject);
58
59 /**
60 * Try to acquire a lock
61 *
62 * @param int $mode LOCK_CAPABILITY_EXCLUSIVE or LOCK_CAPABILITY_SHARED
63 * @return bool Returns TRUE if the lock was acquired successfully
64 * @throws LockAcquireException if the lock could not be acquired
65 * @throws LockAcquireWouldBlockException if the acquire would have blocked and NOBLOCK was set
66 */
67 public function acquire($mode = self::LOCK_CAPABILITY_EXCLUSIVE);
68
69 /**
70 * Release the lock
71 *
72 * @return bool Returns TRUE on success or FALSE on failure
73 */
74 public function release();
75
76 /**
77 * Destroys the resource associated with the lock
78 *
79 * @return void
80 */
81 public function destroy();
82
83 /**
84 * Get status of this lock
85 *
86 * @return bool Returns TRUE if lock is acquired by this locker, FALSE otherwise
87 */
88 public function isAcquired();
89
90 }