The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

XAS::Lib::Modules::Locking - A module to provide discretionary directory locking.

SYNOPSIS

 package My::App;

 use XAS::Class
    version   => '0.01',
    base      => 'XAS::Lib::App',
 ;

 sub main {

    if ($self->lockmgr->lock_directories('here', 'there')) {

        $self->lockmgr->unlock_directories('here', 'there);

    }

 }
 
 1;

DESCRIPTION

This module provides discretionary directory locking. This is used to coordinate access to shared resources. It is implemented as a singleton. This module will also auto-load if "lockmgr" is used as a method invocation.

METHODS

new($parameters)

This method initializes the module. It takes these parameters:

-lockfile

The optional name of the lock file. It defaults to "locked".

-max

The optional number of retries. This defaults to 20.

-delay

The number of seconds to delay before retrying to acquire the lock. This defaults to 1 second.

-hold

The amount of time to hold a lock. After this time the lock is considered "stale". This defaults to 900 seconds.

lock_directory($directory)

This method will lock a single directory. It takes these parameters:

$directory

The directory to use when locking.

unlock_directory($directory)

This method will unlock a single directory. It takes these parameters:

$directory

The directory to use when unlocking.

lock_directories($source, $destination)

This method will attempt to lock the source and destination directories. It takes these parameters:

$source

The source directory.

$destination

The destination directory.

unlock_directories($source, $destination)

This method will unlock the source and destination directories. It takes these parameters:

$source

The source directory.

$destination

The destination directory.

lock_file_name($directory)

This method returns the locks file name. It can be overridden if needed. The default name is 'locked'. It takes the following parameters:

$directory

The directory the lock file resides in.

SEE ALSO

XAS

AUTHOR

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

COPYRIGHT AND LICENSE

Copyright (C) 2014 Kevin L. Esteb

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

See http://dev.perl.org/licenses/ for more information.