Lucy::...actory(3pm)
π Lucy::Store::LockFactory β Create Locks π
okay bestie, pull up a chair, because we're talking about locks. not the hair kind (though periodt, protect your curls). this is the interprocess mutex kind, and it lives in the Lucy::Store::LockFactory page of the User Contributed Perl Documentation. it's giving gatekeeper energy, but in a helpful way π«Ά
β¨ SYNOPSIS β¨
use Sys::Hostname qw( hostname );
my $hostname = hostname() or die "Can't get unique hostname";
my $folder = Lucy::Store::FSFolder->new(
path => '/path/to/index',
);
my $lock_factory = Lucy::Store::LockFactory->new(
folder => $folder,
host => $hostname,
);
my $write_lock = $lock_factory->make_lock(
name => 'write',
timeout => 5000,
interval => 100,
);
like, look at that. she's set up, she's got her hostname, she's ready to lock things down. main character setup fr fr π
πΈ DESCRIPTION πΈ
LockFactory is what you call when you need to spin off interprocess mutex locks β the ones various index reading and writing components are lowkey obsessed with using.
the default implementation? it uses lockfiles. simple, iconic, does the job. but bestie, the plot twist is that LockFactory subclasses implemented with alternatives like flock() are totally possible. so if you wanna switch up the vibe, the door is open πͺβ¨
π CONSTRUCTORS π
π new
my $lock_factory = Lucy::Store::LockFactory->new(
folder => $folder, # required
host => $hostname, # required
);
create a new LockFactory. brand new baby, fresh out the box π¦
folderβ aFolder. required, no cap, don't forget her.hostβ an identifier which should be unique per-machine. yes, unique. that part matters, bestie π
β METHODS β
π make_lock
my $lock = $lock_factory->make_lock(
name => $name, # required
timeout => $timeout, # default: 0
interval => $interval, # default: 100
);
return a Lock object, which β once obtain() returns successfully β maintains an exclusive lock on a resource. exclusive. she's not sharing, she's not passing notes, she's locked in. periodt π₯
nameβ a file-system-friendly id which identifies the resource to be locked.timeoutβ time in milliseconds to keep retrying before abandoning the attempt toobtain()a lock.intervalβ time in milliseconds between retries.
π¦ make_shared_lock
my $lock = $lock_factory->make_shared_lock(
name => $name, # required
timeout => $timeout, # default: 0
interval => $interval, # default: 100
);
return a Lock object for which shared() returns true, and which maintains a non-exclusive lock on a resource once obtain() returns success. so like, the chill version of the last one. she shares. she's generous. we love her π
nameβ a file-system-friendly id which identifies the resource to be locked.timeoutβ time in milliseconds to keep retrying before abandoning the attempt toobtain()a lock.intervalβ time in milliseconds between retries.
ngl bestie,timeoutdefaults to0andintervaldefaults to100on both of these. remember that or you'll be sitting there like π wondering why nothing's retrying.
π INHERITANCE π
Lucy::Store::LockFactory isa Clownfish::Obj. family tree checked, ancestry confirmed, she comes from good stock π
and that's the whole page, no notes, ate and left no crumbs β¨
this was brought to you by the Lucy::...actory(3pm) page in the User Contributed Perl Documentation β perl v5.42.0, dated 2025-07-25. go forth and lock responsibly, bestie π
π
π¦ where this page comes from
- fedora 43: perl-Lucy 0.6.2-26.fc43 Β· Apache-2.0 AND MIT AND Unicode-DFS-2015
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms