userver
C++ Async Framework
Loading...
Searching...
No Matches
dist_lock_strategy.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/dist_lock/dist_lock_strategy.hpp
4
/// @brief @copybrief dist_lock::DistLockStrategyBase
5
6
#
include
<
chrono
>
7
#
include
<
exception
>
8
#
include
<
string
>
9
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
dist_lock
{
13
14
/// Indicates that lock cannot be acquired because it's busy.
15
class
LockIsAcquiredByAnotherHostException
:
public
std::exception {};
16
17
/// @ingroup userver_base_classes userver_concurrency
18
///
19
/// @brief Interface for distributed lock strategies
20
///
21
/// ## Example
22
///
23
/// @snippet core/src/dist_lock/dist_lock_test.cpp Sample distlock strategy
24
class
DistLockStrategyBase
{
25
public
:
26
virtual
~DistLockStrategyBase() =
default
;
27
28
/// Acquires the distributed lock.
29
///
30
/// @param lock_ttl The duration for which the lock must be held.
31
/// @param locker_id Globally unique ID of the locking entity.
32
/// @throws LockIsAcquiredByAnotherHostError when the lock is busy
33
/// @throws anything else when the locking fails, strategy is responsible for
34
/// cleanup, Release won't be invoked.
35
virtual
void
Acquire
(std::chrono::milliseconds lock_ttl,
const
std::string& locker_id) = 0;
36
37
/// Releases the lock.
38
///
39
/// @param locker_id Globally unique ID of the locking entity, must be the
40
/// same as in Acquire().
41
/// @note Exceptions are ignored.
42
virtual
void
Release
(
const
std::string& locker_id) = 0;
43
};
44
45
}
// namespace dist_lock
46
47
USERVER_NAMESPACE_END
userver
dist_lock
dist_lock_strategy.hpp
Generated on Fri Jan 31 2025 09:47:38 for userver by
Doxygen
1.10.0