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.
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.
lock($key)
Aquires a lock, returns true if successful.
unlock($key)
Releases the lock. Returns true if successful.
try_lock($key)
Tests to see if the lock is available, returns true if the lock is available.
SEE ALSO
AUTHOR
Kevin L. Esteb, <kevin@kesteb.us>
COPYRIGHT AND LICENSE
Copyright (c) 2012-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.