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

NAME

XAS::Lib::Lockmgr - The base class for locking within XAS

SYNOPSIS

 my $lock = 'testing';
 my $lockmgr = XAS::Lib::Lockmgr->new();

 $lockmgr->add(-key => $lock);

 if ($lockmgr->try_lock($lock)) {

    if ($lockmgr->lock($lock)) {

        ....

        $lockmgr->unlock($lock);

    }

 }

DESCRIPTION

This module provides a general purpose locking mechanism to protect shared resources. It is rather interesting to ask a developer how they protect global shared data. They usually answer, "what do you mean by "global shared data" ?". Well, for those who understand the need, this module provides it for XAS.

METHODS

new

This method initializes the module. It takes the following parameters:

-deadlock

The number of minutes before a lock is considered deadlocked. At which point an attempt will be made to remove the lock. Defaults to 5.

-breaklock

After a deadlock has been detected, break the lock, irregardless of who owns the lock. Defaults to false. The default will also throw an exception instead of breaking the lock.

-attempts

The number of attempts to aquire the lock. Default to 30.

-timeout

The number of seconds to wait between each lock attempt. Defaults to 30.

add(...)

This method adds a key and defines the module that is used to manage that key. It takes the following named parameters:

-key

The name of the key. This parameter is required.

-driver

The module that will manage the lock. The default is 'Filesystem'. Which will load XAS::Lib::Lockmgr::Filesystem.

-args

An optional hash reference of arguments to pass to the driver.

remove($key)

This method will remove the key from management. This will call the destroy method of the managing module.

$key

The name of the managed key.

lock($key)

Aquires a lock, returns true if successful.

$key

The name of the managed key.

unlock($key)

Releases the lock. Returns true if successful.

$key

The name of the managed key.

try_lock($key)

Tests to see if the lock is available, returns true if the lock is available.

$key

The name of the managed key.

SEE ALSO

XAS::Lib::Lockmgr::Filesystem
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.