NAME
XAS::Lib::Lockmgr::Filsystem - Use the file system for locking.
SYNOPSIS
use XAS::Lib::Lockmgr;
my $key = '/var/lock/xas/alerts';
my $lockmgr = XAS::Lib::Lockmgr->new();
$lockmgr->add(
-key => $key,
-driver => 'Filesystem',
);
if ($lockmgr->try_lock($key)) {
$lockmgr->lock($key);
...
$lockmgr->unlock($key);
}
DESCRIPTION
This class uses the manipulation of directories within the file system as a mutex. This leverages the atomicity of creating directories and allows for discretionary locking of resources.
CONFIGURATION
This module uses the following fields in -args.
- limit
-
The number of attempts to aquire the lock. The default is 10.
- timeout
-
The number of seconds to wait between lock attempts. The default is 10.
METHODS
lock
Attempt to aquire a lock. This is done by creating a directory and writing a status file into that directory. Returns TRUE for success, FALSE otherwise.
unlock
Remove the lock. This is done by removing the status file and then the directory. Returns TRUE for success, FALSE otherwise.
try_lock
Check to see if a lock could be aquired. Returns FALSE if the directory exists, TRUE otherwise.
break_lock
Unconditionally remove the contains of the directory and than remove the directory.
whose_lock
Query the status file. This file provides the following information:
This information is implicit in the name of the file and the modification time stored within the filesystem.
SEE ALSO
AUTHOR
Kevin L. Esteb, <kevin@kesteb.us>
COPYRIGHT AND LICENSE
Copyright (c) 2015 Kevin L. Esteb
This is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license at http://www.perlfoundation.org/artistic_license_2_0.