1 | <?php |
||
19 | class MutexAdapter |
||
20 | { |
||
21 | /** |
||
22 | * @var MutexInterface |
||
23 | */ |
||
24 | protected $mutex; |
||
25 | |||
26 | /** |
||
27 | * @var integer |
||
28 | */ |
||
29 | protected $attemptTotal; |
||
30 | |||
31 | /** |
||
32 | * @var integer |
||
33 | */ |
||
34 | protected $wait; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $prefix; |
||
40 | |||
41 | /** |
||
42 | * |
||
43 | * @param MutexInterface $mutex |
||
44 | * @param integer $attemptTotal |
||
45 | * @param integer $wait |
||
46 | * @param string $prefix |
||
47 | */ |
||
48 | public function __construct(MutexInterface $mutex, $attemptTotal = 10, $wait = 1, $prefix = 'worker_mutex') |
||
55 | |||
56 | /** |
||
57 | * Acquires access to Semaphore. |
||
58 | * |
||
59 | * @param string $key |
||
60 | * @param integer $ttl |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | public function acquire($key, $ttl = 60) |
||
81 | |||
82 | /** |
||
83 | * Releases access to Semaphore. |
||
84 | * |
||
85 | * @param string $key |
||
86 | */ |
||
87 | public function release($key) |
||
95 | |||
96 | /** |
||
97 | * Generates a key with prefix. |
||
98 | * |
||
99 | * @param string $key |
||
100 | * |
||
101 | * @return string |
||
102 | */ |
||
103 | protected function generateKey($key) |
||
107 | } |
||
108 |