The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

XAS::Lib::Lockmgr::Filsystem - Use the file system for locking.

SYNOPSIS

 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);

 }

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.

attempts

The number of attempts to aquire the lock. The default is 30.

timeout

The number of seconds to wait between lock attempts. The default is 30.

deadlock

The number of seconds before a deadlock is declated, defaults to 1800,

breaklock

Break the lock irregardless of how owns the lock, defaults to FALSE.

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.

exceptions

Returns the exceptions that you may not want to continue lock attemtps if triggered.

SEE ALSO

XAS::Lib::Lockmgr
XAS

AUTHOR

Kevin L. Esteb, <kevin@kesteb.us>

COPYRIGHT AND LICENSE

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.