1Lucy::Store::Lock(3)  User Contributed Perl Documentation Lucy::Store::Lock(3)
2
3
4

NAME

6       Lucy::Store::Lock - Abstract class representing an interprocess mutex
7       lock.
8

SYNOPSIS

10           my $lock = $lock_factory->make_lock(
11               name    => 'write',
12               timeout => 5000,
13           );
14           $lock->obtain or die "can't get lock for " . $lock->get_name;
15           do_stuff();
16           $lock->release;
17

DESCRIPTION

19       The Lock class produces an interprocess mutex lock.  The default
20       subclass uses dot-lock files, but alternative implementations are
21       possible.
22
23       Each lock must have a name which is unique per resource to be locked.
24       Each lock also has a XhostX id which should be unique per machine; it
25       is used to help clear away stale locks.
26

CONSTRUCTORS

28   new
29           my $lock = Lucy::Store::Lock->new(
30               name     => 'commit',     # required
31               folder   => $folder,      # required
32               host     => $hostname,    # required
33               timeout  => 5000,         # default: 0
34               interval => 1000,         # default: 100
35           );
36
37       Abstract constructor.
38
39folder - A Folder.
40
41name - String identifying the resource to be locked, which must
42           consist solely of characters matching [-_.A-Za-z0-9].
43
44host - A unique per-machine identifier.
45
46timeout - Time in milliseconds to keep retrying before abandoning
47           the attempt to obtain() a lock.
48
49interval - Time in milliseconds between retries.
50

ABSTRACT METHODS

52   shared
53           my $bool = $lock->shared();
54
55       Returns true if the Lock is shared, false if the Lock is exclusive.
56
57   request
58           my $bool = $lock->request();
59
60       Make one attempt to acquire the lock.
61
62       The semantics of request() differ depending on whether shared() returns
63       true.  If the Lock is shared(), then request() should not fail if
64       another lock is held against the resource identified by "name" (though
65       it might fail for other reasons).  If it is not shared() X i.e. itXs an
66       exclusive (write) lock X then other locks should cause request() to
67       fail.
68
69       Returns: true on success, false on failure (sets the global error
70       object returned by Clownfish->error).
71
72   release
73           $lock->release();
74
75       Release the lock.
76
77   is_locked
78           my $bool = $lock->is_locked();
79
80       Indicate whether the resource identified by this lockXs name is
81       currently locked.
82
83       Returns: true if the resource is locked, false otherwise.
84
85   clear_stale
86           $lock->clear_stale();
87
88       Release all locks that meet the following three conditions: the lock
89       name matches, the host id matches, and the process id that the lock was
90       created under no longer identifies an active process.
91

METHODS

93   obtain
94           my $bool = $lock->obtain();
95
96       Call request() once per "interval" until request() returns success or
97       the "timeout" has been reached.
98
99       Returns: true on success, false on failure (sets the global error
100       object returned by Clownfish->error).
101

INHERITANCE

103       Lucy::Store::Lock isa Clownfish::Obj.
104
105
106
107perl v5.36.0                      2022-07-22              Lucy::Store::Lock(3)
Impressum