Lucy::...actory(3pm)

πŸ“¦
version 0.6.2 Β· 2 versions
, in fedora 43

πŸ’– 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 β€” a Folder. 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 to obtain() 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 to obtain() a lock.
  • interval β€” time in milliseconds between retries.
ngl bestie, timeout defaults to 0 and interval defaults to 100 on 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