XAS::Lib::Lockmgr::Filsystem - Use the file system for locking.
use XAS::Lib::Lockmgr; my $key = '/var/lock/wpm/alerts'; my $lockmgr = XAS::Lib::Lockmgr->new(); $lockmgr->add( -key => $key, -driver => 'Filesystem', -args => { timeout => 10, attempts => 10, breaklock => 1, deadlock => 900, } ); if ($lockmgr->try_lock($key)) { $lockmgr->lock($key); ... $lockmgr->unlock($key); }
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.
This module uses the following fields in -args.
The number of attempts to aquire the lock. The default is 30.
The number of seconds to wait between lock attempts. The default is 30.
The number of seconds before a deadlock is declated, defaults to 1800,
Break the lock irregardless of how owns the lock, defaults to FALSE.
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.
Remove the lock. This is done by removing the status file and then the directory. Returns TRUE for success, FALSE otherwise.
Check to see if a lock could be aquired. Returns FALSE if the directory exists, TRUE otherwise.
Returns the exceptions that you may not want to continue lock attemtps if triggered.
Kevin L. Esteb, <kevin@kesteb.us>
Copyright (c) 2012-2016 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.
To install XAS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XAS
CPAN shell
perl -MCPAN -e shell install XAS
For more information on module installation, please visit the detailed CPAN module installation guide.